-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1209e2
commit d91f05f
Showing
6 changed files
with
116 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use tower_lsp::lsp_types as lsp; | ||
use crate::Backend; | ||
|
||
|
||
pub async fn did_change_configuration(backend: &Backend, _: lsp::DidChangeConfigurationParams) { | ||
backend.clear_all_diagnostics().await.unwrap(); | ||
|
||
backend.fetch_config().await; | ||
backend.scan_content_repositories().await; | ||
backend.build_content_graph().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use tower_lsp::lsp_types::notification::Notification; | ||
use tower_lsp::lsp_types as lsp; | ||
use tower_lsp::jsonrpc::Result; | ||
use crate::Backend; | ||
|
||
|
||
pub async fn initialize(backend: &Backend, params: lsp::InitializeParams) -> Result<lsp::InitializeResult> { | ||
if let Some(workspace_folders) = params.workspace_folders { | ||
let mut workspace_roots = backend.workspace_roots.write().await; | ||
*workspace_roots = workspace_folders.into_iter() | ||
.map(|f| f.uri.to_file_path().unwrap()) | ||
.collect(); | ||
} | ||
|
||
Ok(lsp::InitializeResult { | ||
server_info: Some(lsp::ServerInfo { | ||
name: Backend::SERVER_NAME.into(), | ||
version: Some(env!("CARGO_PKG_VERSION").into()) | ||
}), | ||
capabilities: lsp::ServerCapabilities { | ||
text_document_sync: Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions { | ||
open_close: Some(true), | ||
change: Some(lsp::TextDocumentSyncKind::INCREMENTAL), | ||
will_save: Some(false), | ||
will_save_wait_until: Some(false), | ||
save: Some(lsp::TextDocumentSyncSaveOptions::SaveOptions(lsp::SaveOptions { | ||
include_text: Some(false) | ||
})) | ||
})), | ||
workspace: Some(lsp::WorkspaceServerCapabilities { | ||
workspace_folders: Some(lsp::WorkspaceFoldersServerCapabilities { | ||
supported: Some(true), | ||
change_notifications: Some(lsp::OneOf::Left(true)), | ||
}), | ||
//TODO file operations notifiction config to know if content graph changed in some way | ||
file_operations: None | ||
}), | ||
..lsp::ServerCapabilities::default() | ||
} | ||
}) | ||
} | ||
|
||
pub async fn initialized(backend: &Backend, _: lsp::InitializedParams) { | ||
backend.log_info("Server initialized!").await; | ||
|
||
backend.client.register_capability(vec![ | ||
lsp::Registration { | ||
id: lsp::notification::DidChangeConfiguration::METHOD.to_string(), | ||
method: lsp::notification::DidChangeConfiguration::METHOD.to_string(), | ||
register_options: None | ||
} | ||
]).await.unwrap(); | ||
|
||
backend.fetch_config().await; | ||
|
||
backend.scan_content_repositories().await; | ||
backend.scan_workspace_projects().await; | ||
backend.build_content_graph().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
pub mod document_ops; | ||
/// Modules providing implementations for [`Backend`]'s LanguageServer methods. | ||
/// Made for better code organization purposes. | ||
pub mod initialization; | ||
pub mod document_ops; | ||
pub mod configuration; | ||
pub mod workspace; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use tower_lsp::lsp_types as lsp; | ||
use crate::Backend; | ||
|
||
|
||
pub async fn did_change_workspace_folders(backend: &Backend, params: lsp::DidChangeWorkspaceFoldersParams) { | ||
let added: Vec<_> = params.event.added.into_iter() | ||
.map(|f| f.uri.to_file_path().unwrap()) | ||
.collect(); | ||
|
||
let removed: Vec<_> = params.event.removed.into_iter() | ||
.map(|f| f.uri.to_file_path().unwrap()) | ||
.collect(); | ||
|
||
{ | ||
let mut workspace_roots = backend.workspace_roots.write().await; | ||
workspace_roots.retain(|p| !removed.contains(p)); | ||
workspace_roots.extend(added); | ||
} | ||
|
||
backend.clear_all_diagnostics().await.unwrap(); | ||
|
||
backend.scan_workspace_projects().await; | ||
backend.build_content_graph().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters