mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 12:25:05 +00:00
Merge #5516
5516: Better LSP conformance r=matklad a=vsrs At the moment rust-analyzer does not fully conform to the LSP. This PR fixes two LSP related issues: 1) rust-analyzer sends predefined server capabilities and does not take supplied client capabilities in mind. 2) rust-analyzer uses dynamic `textDocument/didSave` registration even if the client does not support it. Co-authored-by: vsrs <vit@conrlab.com>
This commit is contained in:
commit
5b13c2411f
2 changed files with 42 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,13 @@ 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,6 +106,7 @@ impl GlobalState {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if self.config.client_caps.dynamic_watched_files {
|
||||||
let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions {
|
let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions {
|
||||||
include_text: Some(false),
|
include_text: Some(false),
|
||||||
text_document_registration_options: lsp_types::TextDocumentRegistrationOptions {
|
text_document_registration_options: lsp_types::TextDocumentRegistrationOptions {
|
||||||
|
@ -134,10 +135,12 @@ impl GlobalState {
|
||||||
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>(
|
self.send_request::<lsp_types::request::RegisterCapability>(
|
||||||
lsp_types::RegistrationParams { registrations: vec![registration] },
|
lsp_types::RegistrationParams { registrations: vec![registration] },
|
||||||
|_, _| (),
|
|_, _| (),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
self.fetch_workspaces();
|
self.fetch_workspaces();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue