diff options
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 67 |
2 files changed, 43 insertions, 32 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 8947ccf07..ad62571ef 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -128,6 +128,7 @@ pub struct ClientCapsConfig { | |||
128 | pub hover_actions: bool, | 128 | pub hover_actions: bool, |
129 | pub status_notification: bool, | 129 | pub status_notification: bool, |
130 | pub signature_help_label_offsets: bool, | 130 | pub signature_help_label_offsets: bool, |
131 | pub dynamic_watched_files: bool, | ||
131 | } | 132 | } |
132 | 133 | ||
133 | impl Config { | 134 | impl Config { |
@@ -290,6 +291,13 @@ impl Config { | |||
290 | } | 291 | } |
291 | 292 | ||
292 | pub fn update_caps(&mut self, caps: &ClientCapabilities) { | 293 | pub fn update_caps(&mut self, caps: &ClientCapabilities) { |
294 | if let Some(ws_caps) = caps.workspace.as_ref() { | ||
295 | if let Some(did_change_watched_files) = ws_caps.did_change_watched_files.as_ref() { | ||
296 | self.client_caps.dynamic_watched_files = | ||
297 | did_change_watched_files.dynamic_registration.unwrap_or(false); | ||
298 | } | ||
299 | } | ||
300 | |||
293 | if let Some(doc_caps) = caps.text_document.as_ref() { | 301 | if let Some(doc_caps) = caps.text_document.as_ref() { |
294 | if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) { | 302 | if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) { |
295 | self.client_caps.location_link = value; | 303 | 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 { | |||
106 | ); | 106 | ); |
107 | }; | 107 | }; |
108 | 108 | ||
109 | let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions { | 109 | if self.config.client_caps.dynamic_watched_files { |
110 | include_text: Some(false), | 110 | let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions { |
111 | text_document_registration_options: lsp_types::TextDocumentRegistrationOptions { | 111 | include_text: Some(false), |
112 | document_selector: Some(vec![ | 112 | text_document_registration_options: lsp_types::TextDocumentRegistrationOptions { |
113 | lsp_types::DocumentFilter { | 113 | document_selector: Some(vec![ |
114 | language: None, | 114 | lsp_types::DocumentFilter { |
115 | scheme: None, | 115 | language: None, |
116 | pattern: Some("**/*.rs".into()), | 116 | scheme: None, |
117 | }, | 117 | pattern: Some("**/*.rs".into()), |
118 | lsp_types::DocumentFilter { | 118 | }, |
119 | language: None, | 119 | lsp_types::DocumentFilter { |
120 | scheme: None, | 120 | language: None, |
121 | pattern: Some("**/Cargo.toml".into()), | 121 | scheme: None, |
122 | }, | 122 | pattern: Some("**/Cargo.toml".into()), |
123 | lsp_types::DocumentFilter { | 123 | }, |
124 | language: None, | 124 | lsp_types::DocumentFilter { |
125 | scheme: None, | 125 | language: None, |
126 | pattern: Some("**/Cargo.lock".into()), | 126 | scheme: None, |
127 | }, | 127 | pattern: Some("**/Cargo.lock".into()), |
128 | ]), | 128 | }, |
129 | }, | 129 | ]), |
130 | }; | 130 | }, |
131 | 131 | }; | |
132 | let registration = lsp_types::Registration { | 132 | |
133 | id: "textDocument/didSave".to_string(), | 133 | let registration = lsp_types::Registration { |
134 | method: "textDocument/didSave".to_string(), | 134 | id: "textDocument/didSave".to_string(), |
135 | register_options: Some(serde_json::to_value(save_registration_options).unwrap()), | 135 | method: "textDocument/didSave".to_string(), |
136 | }; | 136 | register_options: Some(serde_json::to_value(save_registration_options).unwrap()), |
137 | self.send_request::<lsp_types::request::RegisterCapability>( | 137 | }; |
138 | lsp_types::RegistrationParams { registrations: vec![registration] }, | 138 | |
139 | |_, _| (), | 139 | self.send_request::<lsp_types::request::RegisterCapability>( |
140 | ); | 140 | lsp_types::RegistrationParams { registrations: vec![registration] }, |
141 | |_, _| (), | ||
142 | ); | ||
143 | } | ||
141 | 144 | ||
142 | self.fetch_workspaces(); | 145 | self.fetch_workspaces(); |
143 | 146 | ||