mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 08:05:12 +00:00
Check client capabilities before sending progress notifications
Fixes #4384
This commit is contained in:
parent
05399250d4
commit
d4471dccfe
@ -100,9 +100,8 @@ fn run_server() -> Result<()> {
|
||||
if let Some(value) = &initialize_params.initialization_options {
|
||||
config.update(value);
|
||||
}
|
||||
if let Some(caps) = &initialize_params.capabilities.text_document {
|
||||
config.update_caps(caps);
|
||||
}
|
||||
config.update_caps(&initialize_params.capabilities);
|
||||
|
||||
config
|
||||
};
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
use std::{ffi::OsString, path::PathBuf};
|
||||
|
||||
use lsp_types::TextDocumentClientCapabilities;
|
||||
use lsp_types::ClientCapabilities;
|
||||
use ra_flycheck::FlycheckConfig;
|
||||
use ra_ide::{CompletionConfig, InlayHintsConfig};
|
||||
use ra_project_model::CargoConfig;
|
||||
@ -70,6 +70,7 @@ pub struct ClientCapsConfig {
|
||||
pub line_folding_only: bool,
|
||||
pub hierarchical_symbols: bool,
|
||||
pub code_action_literals: bool,
|
||||
pub work_done_progress: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@ -208,30 +209,43 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_caps(&mut self, caps: &TextDocumentClientCapabilities) {
|
||||
if let Some(value) = 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) =
|
||||
caps.document_symbol.as_ref().and_then(|it| it.hierarchical_document_symbol_support)
|
||||
{
|
||||
self.client_caps.hierarchical_symbols = value
|
||||
}
|
||||
if let Some(value) =
|
||||
caps.code_action.as_ref().and_then(|it| Some(it.code_action_literal_support.is_some()))
|
||||
{
|
||||
self.client_caps.code_action_literals = value;
|
||||
}
|
||||
self.completion.allow_snippets(false);
|
||||
if let Some(completion) = &caps.completion {
|
||||
if let Some(completion_item) = &completion.completion_item {
|
||||
if let Some(value) = completion_item.snippet_support {
|
||||
self.completion.allow_snippets(value);
|
||||
pub fn update_caps(&mut self, caps: &ClientCapabilities) {
|
||||
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) {
|
||||
self.client_caps.location_link = value;
|
||||
}
|
||||
if let Some(value) = doc_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
|
||||
.document_symbol
|
||||
.as_ref()
|
||||
.and_then(|it| it.hierarchical_document_symbol_support)
|
||||
{
|
||||
self.client_caps.hierarchical_symbols = value
|
||||
}
|
||||
if let Some(value) = doc_caps
|
||||
.code_action
|
||||
.as_ref()
|
||||
.and_then(|it| Some(it.code_action_literal_support.is_some()))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
&& loop_state.roots_scanned == loop_state.roots_total
|
||||
@ -750,12 +751,16 @@ fn on_check_task(
|
||||
}
|
||||
|
||||
CheckTask::Status(progress) => {
|
||||
let params = lsp_types::ProgressParams {
|
||||
token: lsp_types::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()),
|
||||
value: lsp_types::ProgressParamsValue::WorkDone(progress),
|
||||
};
|
||||
let not = notification_new::<lsp_types::notification::Progress>(params);
|
||||
task_sender.send(Task::Notify(not)).unwrap();
|
||||
if world_state.config.client_caps.work_done_progress {
|
||||
let params = lsp_types::ProgressParams {
|
||||
token: lsp_types::ProgressToken::String(
|
||||
"rustAnalyzer/cargoWatcher".to_string(),
|
||||
),
|
||||
value: lsp_types::ProgressParamsValue::WorkDone(progress),
|
||||
};
|
||||
let not = notification_new::<lsp_types::notification::Progress>(params);
|
||||
task_sender.send(Task::Notify(not)).unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -80,6 +80,7 @@ impl<'a> Project<'a> {
|
||||
client_caps: ClientCapsConfig {
|
||||
location_link: true,
|
||||
code_action_literals: true,
|
||||
work_done_progress: true,
|
||||
..Default::default()
|
||||
},
|
||||
with_sysroot: self.with_sysroot,
|
||||
|
Loading…
Reference in New Issue
Block a user