mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Send dynamic didSave only if the client supports
This commit is contained in:
parent
594ce72d1e
commit
f195f876c3
2 changed files with 41 additions and 31 deletions
|
@ -128,6 +128,7 @@ pub struct ClientCapsConfig {
|
||||||
pub hover_actions: bool,
|
pub hover_actions: bool,
|
||||||
pub status_notification: bool,
|
pub status_notification: bool,
|
||||||
pub signature_help_label_offsets: bool,
|
pub signature_help_label_offsets: bool,
|
||||||
|
pub dynamic_watched_files: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -290,6 +291,12 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_caps(&mut self, caps: &ClientCapabilities) {
|
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(doc_caps) = caps.text_document.as_ref() {
|
||||||
if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) {
|
if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) {
|
||||||
self.client_caps.location_link = value;
|
self.client_caps.location_link = value;
|
||||||
|
|
|
@ -106,38 +106,41 @@ impl GlobalState {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions {
|
if self.config.client_caps.dynamic_watched_files {
|
||||||
include_text: Some(false),
|
let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions {
|
||||||
text_document_registration_options: lsp_types::TextDocumentRegistrationOptions {
|
include_text: Some(false),
|
||||||
document_selector: Some(vec![
|
text_document_registration_options: lsp_types::TextDocumentRegistrationOptions {
|
||||||
lsp_types::DocumentFilter {
|
document_selector: Some(vec![
|
||||||
language: None,
|
lsp_types::DocumentFilter {
|
||||||
scheme: None,
|
language: None,
|
||||||
pattern: Some("**/*.rs".into()),
|
scheme: None,
|
||||||
},
|
pattern: Some("**/*.rs".into()),
|
||||||
lsp_types::DocumentFilter {
|
},
|
||||||
language: None,
|
lsp_types::DocumentFilter {
|
||||||
scheme: None,
|
language: None,
|
||||||
pattern: Some("**/Cargo.toml".into()),
|
scheme: None,
|
||||||
},
|
pattern: Some("**/Cargo.toml".into()),
|
||||||
lsp_types::DocumentFilter {
|
},
|
||||||
language: None,
|
lsp_types::DocumentFilter {
|
||||||
scheme: None,
|
language: None,
|
||||||
pattern: Some("**/Cargo.lock".into()),
|
scheme: None,
|
||||||
},
|
pattern: Some("**/Cargo.lock".into()),
|
||||||
]),
|
},
|
||||||
},
|
]),
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let registration = lsp_types::Registration {
|
let registration = lsp_types::Registration {
|
||||||
id: "textDocument/didSave".to_string(),
|
id: "textDocument/didSave".to_string(),
|
||||||
method: "textDocument/didSave".to_string(),
|
method: "textDocument/didSave".to_string(),
|
||||||
register_options: Some(serde_json::to_value(save_registration_options).unwrap()),
|
register_options: Some(serde_json::to_value(save_registration_options).unwrap()),
|
||||||
};
|
};
|
||||||
self.send_request::<lsp_types::request::RegisterCapability>(
|
|
||||||
lsp_types::RegistrationParams { registrations: vec![registration] },
|
self.send_request::<lsp_types::request::RegisterCapability>(
|
||||||
|_, _| (),
|
lsp_types::RegistrationParams { registrations: vec![registration] },
|
||||||
);
|
|_, _| (),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
self.fetch_workspaces();
|
self.fetch_workspaces();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue