diff options
author | Aleksey Kladov <[email protected]> | 2021-01-10 19:38:35 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-01-10 19:38:35 +0000 |
commit | bb453edebe477ab754d6c78e11db1bf3af08833c (patch) | |
tree | 262275f1d401de42d0410d87feb8c789d9f0015c | |
parent | 035fed5f9f7c062da7d23190dab1a7021fd48a5d (diff) |
Honor client's dynamic registration caps
cc https://github.com/rust-analyzer/rust-analyzer/pull/5516#issuecomment-757520828
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 12 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 66 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 45 |
3 files changed, 71 insertions, 52 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 2d3e25cbf..27b92a5a9 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -334,6 +334,18 @@ impl Config { | |||
334 | } | 334 | } |
335 | } | 335 | } |
336 | 336 | ||
337 | pub fn did_save_text_document_dynamic_registration(&self) -> bool { | ||
338 | let caps = | ||
339 | try_or!(self.caps.text_document.as_ref()?.synchronization.clone()?, Default::default()); | ||
340 | caps.did_save == Some(true) && caps.dynamic_registration == Some(true) | ||
341 | } | ||
342 | pub fn did_change_watched_files_dynamic_registration(&self) -> bool { | ||
343 | try_or!( | ||
344 | self.caps.workspace.as_ref()?.did_change_watched_files.as_ref()?.dynamic_registration?, | ||
345 | false | ||
346 | ) | ||
347 | } | ||
348 | |||
337 | pub fn location_link(&self) -> bool { | 349 | pub fn location_link(&self) -> bool { |
338 | try_or!(self.caps.text_document.as_ref()?.definition?.link_support?, false) | 350 | try_or!(self.caps.text_document.as_ref()?.definition?.link_support?, false) |
339 | } | 351 | } |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 51fb2eb74..6d2475a59 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -108,38 +108,40 @@ impl GlobalState { | |||
108 | ); | 108 | ); |
109 | }; | 109 | }; |
110 | 110 | ||
111 | let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions { | 111 | if self.config.did_save_text_document_dynamic_registration() { |
112 | include_text: Some(false), | 112 | let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions { |
113 | text_document_registration_options: lsp_types::TextDocumentRegistrationOptions { | 113 | include_text: Some(false), |
114 | document_selector: Some(vec![ | 114 | text_document_registration_options: lsp_types::TextDocumentRegistrationOptions { |
115 | lsp_types::DocumentFilter { | 115 | document_selector: Some(vec![ |
116 | language: None, | 116 | lsp_types::DocumentFilter { |
117 | scheme: None, | 117 | language: None, |
118 | pattern: Some("**/*.rs".into()), | 118 | scheme: None, |
119 | }, | 119 | pattern: Some("**/*.rs".into()), |
120 | lsp_types::DocumentFilter { | 120 | }, |
121 | language: None, | 121 | lsp_types::DocumentFilter { |
122 | scheme: None, | 122 | language: None, |
123 | pattern: Some("**/Cargo.toml".into()), | 123 | scheme: None, |
124 | }, | 124 | pattern: Some("**/Cargo.toml".into()), |
125 | lsp_types::DocumentFilter { | 125 | }, |
126 | language: None, | 126 | lsp_types::DocumentFilter { |
127 | scheme: None, | 127 | language: None, |
128 | pattern: Some("**/Cargo.lock".into()), | 128 | scheme: None, |
129 | }, | 129 | pattern: Some("**/Cargo.lock".into()), |
130 | ]), | 130 | }, |
131 | }, | 131 | ]), |
132 | }; | 132 | }, |
133 | 133 | }; | |
134 | let registration = lsp_types::Registration { | 134 | |
135 | id: "textDocument/didSave".to_string(), | 135 | let registration = lsp_types::Registration { |
136 | method: "textDocument/didSave".to_string(), | 136 | id: "textDocument/didSave".to_string(), |
137 | register_options: Some(serde_json::to_value(save_registration_options).unwrap()), | 137 | method: "textDocument/didSave".to_string(), |
138 | }; | 138 | register_options: Some(serde_json::to_value(save_registration_options).unwrap()), |
139 | self.send_request::<lsp_types::request::RegisterCapability>( | 139 | }; |
140 | lsp_types::RegistrationParams { registrations: vec![registration] }, | 140 | self.send_request::<lsp_types::request::RegisterCapability>( |
141 | |_, _| (), | 141 | lsp_types::RegistrationParams { registrations: vec![registration] }, |
142 | ); | 142 | |_, _| (), |
143 | ); | ||
144 | } | ||
143 | 145 | ||
144 | self.fetch_workspaces_request(); | 146 | self.fetch_workspaces_request(); |
145 | self.fetch_workspaces_if_needed(); | 147 | self.fetch_workspaces_if_needed(); |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index accf2ef8c..97e20362f 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -182,26 +182,31 @@ impl GlobalState { | |||
182 | } | 182 | } |
183 | 183 | ||
184 | if let FilesWatcher::Client = self.config.files().watcher { | 184 | if let FilesWatcher::Client = self.config.files().watcher { |
185 | let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions { | 185 | if self.config.did_change_watched_files_dynamic_registration() { |
186 | watchers: workspaces | 186 | let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions { |
187 | .iter() | 187 | watchers: workspaces |
188 | .flat_map(ProjectWorkspace::to_roots) | 188 | .iter() |
189 | .filter(|it| it.is_member) | 189 | .flat_map(ProjectWorkspace::to_roots) |
190 | .flat_map(|root| { | 190 | .filter(|it| it.is_member) |
191 | root.include.into_iter().map(|it| format!("{}/**/*.rs", it.display())) | 191 | .flat_map(|root| { |
192 | }) | 192 | root.include.into_iter().map(|it| format!("{}/**/*.rs", it.display())) |
193 | .map(|glob_pattern| lsp_types::FileSystemWatcher { glob_pattern, kind: None }) | 193 | }) |
194 | .collect(), | 194 | .map(|glob_pattern| lsp_types::FileSystemWatcher { |
195 | }; | 195 | glob_pattern, |
196 | let registration = lsp_types::Registration { | 196 | kind: None, |
197 | id: "workspace/didChangeWatchedFiles".to_string(), | 197 | }) |
198 | method: "workspace/didChangeWatchedFiles".to_string(), | 198 | .collect(), |
199 | register_options: Some(serde_json::to_value(registration_options).unwrap()), | 199 | }; |
200 | }; | 200 | let registration = lsp_types::Registration { |
201 | self.send_request::<lsp_types::request::RegisterCapability>( | 201 | id: "workspace/didChangeWatchedFiles".to_string(), |
202 | lsp_types::RegistrationParams { registrations: vec![registration] }, | 202 | method: "workspace/didChangeWatchedFiles".to_string(), |
203 | |_, _| (), | 203 | register_options: Some(serde_json::to_value(registration_options).unwrap()), |
204 | ); | 204 | }; |
205 | self.send_request::<lsp_types::request::RegisterCapability>( | ||
206 | lsp_types::RegistrationParams { registrations: vec![registration] }, | ||
207 | |_, _| (), | ||
208 | ); | ||
209 | } | ||
205 | } | 210 | } |
206 | 211 | ||
207 | let mut change = Change::new(); | 212 | let mut change = Change::new(); |