Skip to content

Commit de1fe23

Browse files
bors[bot]kjeremy
andauthored
Merge #4403
4403: Check client capabilities before sending progress notifications r=kjeremy a=kjeremy Fixes #4384 Co-authored-by: Jeremy Kolb <[email protected]>
2 parents 115347a + d4471dc commit de1fe23

File tree

4 files changed

+52
-33
lines changed

4 files changed

+52
-33
lines changed

crates/rust-analyzer/src/bin/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ fn run_server() -> Result<()> {
100100
if let Some(value) = &initialize_params.initialization_options {
101101
config.update(value);
102102
}
103-
if let Some(caps) = &initialize_params.capabilities.text_document {
104-
config.update_caps(caps);
105-
}
103+
config.update_caps(&initialize_params.capabilities);
104+
106105
config
107106
};
108107

crates/rust-analyzer/src/config.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
use std::{ffi::OsString, path::PathBuf};
1111

12-
use lsp_types::TextDocumentClientCapabilities;
12+
use lsp_types::ClientCapabilities;
1313
use ra_flycheck::FlycheckConfig;
1414
use ra_ide::{CompletionConfig, InlayHintsConfig};
1515
use ra_project_model::CargoConfig;
@@ -70,6 +70,7 @@ pub struct ClientCapsConfig {
7070
pub line_folding_only: bool,
7171
pub hierarchical_symbols: bool,
7272
pub code_action_literals: bool,
73+
pub work_done_progress: bool,
7374
}
7475

7576
impl Default for Config {
@@ -208,30 +209,43 @@ impl Config {
208209
}
209210
}
210211

211-
pub fn update_caps(&mut self, caps: &TextDocumentClientCapabilities) {
212-
if let Some(value) = caps.definition.as_ref().and_then(|it| it.link_support) {
213-
self.client_caps.location_link = value;
214-
}
215-
if let Some(value) = caps.folding_range.as_ref().and_then(|it| it.line_folding_only) {
216-
self.client_caps.line_folding_only = value
217-
}
218-
if let Some(value) =
219-
caps.document_symbol.as_ref().and_then(|it| it.hierarchical_document_symbol_support)
220-
{
221-
self.client_caps.hierarchical_symbols = value
222-
}
223-
if let Some(value) =
224-
caps.code_action.as_ref().and_then(|it| Some(it.code_action_literal_support.is_some()))
225-
{
226-
self.client_caps.code_action_literals = value;
227-
}
228-
self.completion.allow_snippets(false);
229-
if let Some(completion) = &caps.completion {
230-
if let Some(completion_item) = &completion.completion_item {
231-
if let Some(value) = completion_item.snippet_support {
232-
self.completion.allow_snippets(value);
212+
pub fn update_caps(&mut self, caps: &ClientCapabilities) {
213+
if let Some(doc_caps) = caps.text_document.as_ref() {
214+
if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) {
215+
self.client_caps.location_link = value;
216+
}
217+
if let Some(value) = doc_caps.folding_range.as_ref().and_then(|it| it.line_folding_only)
218+
{
219+
self.client_caps.line_folding_only = value
220+
}
221+
if let Some(value) = doc_caps
222+
.document_symbol
223+
.as_ref()
224+
.and_then(|it| it.hierarchical_document_symbol_support)
225+
{
226+
self.client_caps.hierarchical_symbols = value
227+
}
228+
if let Some(value) = doc_caps
229+
.code_action
230+
.as_ref()
231+
.and_then(|it| Some(it.code_action_literal_support.is_some()))
232+
{
233+
self.client_caps.code_action_literals = value;
234+
}
235+
self.completion.allow_snippets(false);
236+
if let Some(completion) = &doc_caps.completion {
237+
if let Some(completion_item) = &completion.completion_item {
238+
if let Some(value) = completion_item.snippet_support {
239+
self.completion.allow_snippets(value);
240+
}
233241
}
234242
}
235243
}
244+
245+
if let Some(window_caps) = caps.window.as_ref() {
246+
if let Some(value) = window_caps.work_done_progress {
247+
self.client_caps.work_done_progress = value;
248+
}
249+
}
236250
}
237251
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ fn loop_turn(
415415
});
416416
}
417417

418-
let show_progress = !loop_state.workspace_loaded;
418+
let show_progress =
419+
!loop_state.workspace_loaded && world_state.config.client_caps.work_done_progress;
419420

420421
if !loop_state.workspace_loaded
421422
&& loop_state.roots_scanned == loop_state.roots_total
@@ -750,12 +751,16 @@ fn on_check_task(
750751
}
751752

752753
CheckTask::Status(progress) => {
753-
let params = lsp_types::ProgressParams {
754-
token: lsp_types::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()),
755-
value: lsp_types::ProgressParamsValue::WorkDone(progress),
756-
};
757-
let not = notification_new::<lsp_types::notification::Progress>(params);
758-
task_sender.send(Task::Notify(not)).unwrap();
754+
if world_state.config.client_caps.work_done_progress {
755+
let params = lsp_types::ProgressParams {
756+
token: lsp_types::ProgressToken::String(
757+
"rustAnalyzer/cargoWatcher".to_string(),
758+
),
759+
value: lsp_types::ProgressParamsValue::WorkDone(progress),
760+
};
761+
let not = notification_new::<lsp_types::notification::Progress>(params);
762+
task_sender.send(Task::Notify(not)).unwrap();
763+
}
759764
}
760765
};
761766

crates/rust-analyzer/tests/heavy_tests/support.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl<'a> Project<'a> {
8080
client_caps: ClientCapsConfig {
8181
location_link: true,
8282
code_action_literals: true,
83+
work_done_progress: true,
8384
..Default::default()
8485
},
8586
with_sysroot: self.with_sysroot,

0 commit comments

Comments
 (0)