From f195f876c38e5e013c095c494ec98be465c806db Mon Sep 17 00:00:00 2001 From: vsrs Date: Fri, 24 Jul 2020 10:41:50 +0300 Subject: Send dynamic didSave only if the client supports --- crates/rust-analyzer/src/config.rs | 7 ++++ crates/rust-analyzer/src/main_loop.rs | 67 ++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 32 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 8947ccf07..93605314a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -128,6 +128,7 @@ pub struct ClientCapsConfig { pub hover_actions: bool, pub status_notification: bool, pub signature_help_label_offsets: bool, + pub dynamic_watched_files: bool, } impl Config { @@ -290,6 +291,12 @@ impl Config { } pub fn update_caps(&mut self, caps: &ClientCapabilities) { + if let Some(ws_caps) = caps.workspace.as_ref() { + if let Some(did_change_watched_files) = ws_caps.did_change_watched_files.as_ref() { + self.client_caps.dynamic_watched_files = did_change_watched_files.dynamic_registration.unwrap_or(false); + } + } + if let Some(doc_caps) = caps.text_document.as_ref() { if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) { self.client_caps.location_link = value; diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index e95d4157c..b44fd9eb4 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -106,38 +106,41 @@ impl GlobalState { ); }; - let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions { - include_text: Some(false), - text_document_registration_options: lsp_types::TextDocumentRegistrationOptions { - document_selector: Some(vec![ - lsp_types::DocumentFilter { - language: None, - scheme: None, - pattern: Some("**/*.rs".into()), - }, - lsp_types::DocumentFilter { - language: None, - scheme: None, - pattern: Some("**/Cargo.toml".into()), - }, - lsp_types::DocumentFilter { - language: None, - scheme: None, - pattern: Some("**/Cargo.lock".into()), - }, - ]), - }, - }; - - let registration = lsp_types::Registration { - id: "textDocument/didSave".to_string(), - method: "textDocument/didSave".to_string(), - register_options: Some(serde_json::to_value(save_registration_options).unwrap()), - }; - self.send_request::( - lsp_types::RegistrationParams { registrations: vec![registration] }, - |_, _| (), - ); + if self.config.client_caps.dynamic_watched_files { + let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions { + include_text: Some(false), + text_document_registration_options: lsp_types::TextDocumentRegistrationOptions { + document_selector: Some(vec![ + lsp_types::DocumentFilter { + language: None, + scheme: None, + pattern: Some("**/*.rs".into()), + }, + lsp_types::DocumentFilter { + language: None, + scheme: None, + pattern: Some("**/Cargo.toml".into()), + }, + lsp_types::DocumentFilter { + language: None, + scheme: None, + pattern: Some("**/Cargo.lock".into()), + }, + ]), + }, + }; + + let registration = lsp_types::Registration { + id: "textDocument/didSave".to_string(), + method: "textDocument/didSave".to_string(), + register_options: Some(serde_json::to_value(save_registration_options).unwrap()), + }; + + self.send_request::( + lsp_types::RegistrationParams { registrations: vec![registration] }, + |_, _| (), + ); + } self.fetch_workspaces(); -- cgit v1.2.3