Check client capabilities before sending progress notifications

Fixes #4384
This commit is contained in:
Jeremy Kolb 2020-05-09 17:15:22 -04:00 committed by kjeremy
parent 05399250d4
commit d4471dccfe
4 changed files with 52 additions and 33 deletions

View File

@ -100,9 +100,8 @@ fn run_server() -> Result<()> {
if let Some(value) = &initialize_params.initialization_options { if let Some(value) = &initialize_params.initialization_options {
config.update(value); config.update(value);
} }
if let Some(caps) = &initialize_params.capabilities.text_document { config.update_caps(&initialize_params.capabilities);
config.update_caps(caps);
}
config config
}; };

View File

@ -9,7 +9,7 @@
use std::{ffi::OsString, path::PathBuf}; use std::{ffi::OsString, path::PathBuf};
use lsp_types::TextDocumentClientCapabilities; use lsp_types::ClientCapabilities;
use ra_flycheck::FlycheckConfig; use ra_flycheck::FlycheckConfig;
use ra_ide::{CompletionConfig, InlayHintsConfig}; use ra_ide::{CompletionConfig, InlayHintsConfig};
use ra_project_model::CargoConfig; use ra_project_model::CargoConfig;
@ -70,6 +70,7 @@ pub struct ClientCapsConfig {
pub line_folding_only: bool, pub line_folding_only: bool,
pub hierarchical_symbols: bool, pub hierarchical_symbols: bool,
pub code_action_literals: bool, pub code_action_literals: bool,
pub work_done_progress: bool,
} }
impl Default for Config { impl Default for Config {
@ -208,30 +209,43 @@ impl Config {
} }
} }
pub fn update_caps(&mut self, caps: &TextDocumentClientCapabilities) { pub fn update_caps(&mut self, caps: &ClientCapabilities) {
if let Some(value) = caps.definition.as_ref().and_then(|it| it.link_support) { if let Some(doc_caps) = caps.text_document.as_ref() {
self.client_caps.location_link = value; if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) {
} self.client_caps.location_link = value;
if let Some(value) = caps.folding_range.as_ref().and_then(|it| it.line_folding_only) { }
self.client_caps.line_folding_only = value if let Some(value) = doc_caps.folding_range.as_ref().and_then(|it| it.line_folding_only)
} {
if let Some(value) = self.client_caps.line_folding_only = value
caps.document_symbol.as_ref().and_then(|it| it.hierarchical_document_symbol_support) }
{ if let Some(value) = doc_caps
self.client_caps.hierarchical_symbols = value .document_symbol
} .as_ref()
if let Some(value) = .and_then(|it| it.hierarchical_document_symbol_support)
caps.code_action.as_ref().and_then(|it| Some(it.code_action_literal_support.is_some())) {
{ self.client_caps.hierarchical_symbols = value
self.client_caps.code_action_literals = value; }
} if let Some(value) = doc_caps
self.completion.allow_snippets(false); .code_action
if let Some(completion) = &caps.completion { .as_ref()
if let Some(completion_item) = &completion.completion_item { .and_then(|it| Some(it.code_action_literal_support.is_some()))
if let Some(value) = completion_item.snippet_support { {
self.completion.allow_snippets(value); self.client_caps.code_action_literals = value;
}
self.completion.allow_snippets(false);
if let Some(completion) = &doc_caps.completion {
if let Some(completion_item) = &completion.completion_item {
if let Some(value) = completion_item.snippet_support {
self.completion.allow_snippets(value);
}
} }
} }
} }
if let Some(window_caps) = caps.window.as_ref() {
if let Some(value) = window_caps.work_done_progress {
self.client_caps.work_done_progress = value;
}
}
} }
} }

View File

@ -415,7 +415,8 @@ fn loop_turn(
}); });
} }
let show_progress = !loop_state.workspace_loaded; let show_progress =
!loop_state.workspace_loaded && world_state.config.client_caps.work_done_progress;
if !loop_state.workspace_loaded if !loop_state.workspace_loaded
&& loop_state.roots_scanned == loop_state.roots_total && loop_state.roots_scanned == loop_state.roots_total
@ -750,12 +751,16 @@ fn on_check_task(
} }
CheckTask::Status(progress) => { CheckTask::Status(progress) => {
let params = lsp_types::ProgressParams { if world_state.config.client_caps.work_done_progress {
token: lsp_types::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()), let params = lsp_types::ProgressParams {
value: lsp_types::ProgressParamsValue::WorkDone(progress), token: lsp_types::ProgressToken::String(
}; "rustAnalyzer/cargoWatcher".to_string(),
let not = notification_new::<lsp_types::notification::Progress>(params); ),
task_sender.send(Task::Notify(not)).unwrap(); value: lsp_types::ProgressParamsValue::WorkDone(progress),
};
let not = notification_new::<lsp_types::notification::Progress>(params);
task_sender.send(Task::Notify(not)).unwrap();
}
} }
}; };

View File

@ -80,6 +80,7 @@ impl<'a> Project<'a> {
client_caps: ClientCapsConfig { client_caps: ClientCapsConfig {
location_link: true, location_link: true,
code_action_literals: true, code_action_literals: true,
work_done_progress: true,
..Default::default() ..Default::default()
}, },
with_sysroot: self.with_sysroot, with_sysroot: self.with_sysroot,