Skip to content

Commit 994a9b8

Browse files
committed
Auto merge of #17365 - DropDemBits:diagnostic-snippet-cap, r=Veykril
internal: Expose snippet capability to diagnostic quickfixes Fixes #16767
2 parents 4f180b6 + 4f67f71 commit 994a9b8

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ use ide_db::{
8686
label::Label,
8787
source_change::SourceChange,
8888
syntax_helpers::node_ext::parse_tt_as_comma_sep_paths,
89-
FxHashMap, FxHashSet, RootDatabase,
89+
FxHashMap, FxHashSet, RootDatabase, SnippetCap,
9090
};
9191
use once_cell::sync::Lazy;
9292
use stdx::never;
@@ -229,6 +229,7 @@ pub struct DiagnosticsConfig {
229229
pub expr_fill_default: ExprFillDefaultMode,
230230
pub style_lints: bool,
231231
// FIXME: We may want to include a whole `AssistConfig` here
232+
pub snippet_cap: Option<SnippetCap>,
232233
pub insert_use: InsertUseConfig,
233234
pub prefer_no_std: bool,
234235
pub prefer_prelude: bool,
@@ -248,6 +249,7 @@ impl DiagnosticsConfig {
248249
disabled: Default::default(),
249250
expr_fill_default: Default::default(),
250251
style_lints: true,
252+
snippet_cap: SnippetCap::new(true),
251253
insert_use: InsertUseConfig {
252254
granularity: ImportGranularity::Preserve,
253255
enforce_granularity: false,

src/tools/rust-analyzer/crates/rust-analyzer/src/caps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProvi
223223

224224
fn more_trigger_character(config: &Config) -> Vec<String> {
225225
let mut res = vec![".".to_owned(), ">".to_owned(), "{".to_owned(), "(".to_owned()];
226-
if config.snippet_cap() {
226+
if config.snippet_cap().is_some() {
227227
res.push("<".to_owned());
228228
}
229229
res

src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use ide_db::{
2525
salsa::{self, debug::DebugQueryTable, ParallelDatabase},
2626
SourceDatabase, SourceDatabaseExt,
2727
},
28-
LineIndexDatabase,
28+
LineIndexDatabase, SnippetCap,
2929
};
3030
use itertools::Itertools;
3131
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
@@ -982,6 +982,7 @@ impl flags::AnalysisStats {
982982
disable_experimental: false,
983983
disabled: Default::default(),
984984
expr_fill_default: Default::default(),
985+
snippet_cap: SnippetCap::new(true),
985986
insert_use: ide_db::imports::insert_use::InsertUseConfig {
986987
granularity: ide_db::imports::insert_use::ImportGranularity::Crate,
987988
enforce_granularity: true,

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ impl Config {
12611261
impl Config {
12621262
pub fn assist(&self, source_root: Option<SourceRootId>) -> AssistConfig {
12631263
AssistConfig {
1264-
snippet_cap: SnippetCap::new(self.experimental("snippetTextEdit")),
1264+
snippet_cap: self.snippet_cap(),
12651265
allowed: None,
12661266
insert_use: self.insert_use_config(source_root),
12671267
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
@@ -1321,6 +1321,7 @@ impl Config {
13211321
ExprFillDefaultDef::Todo => ExprFillDefaultMode::Todo,
13221322
ExprFillDefaultDef::Default => ExprFillDefaultMode::Default,
13231323
},
1324+
snippet_cap: self.snippet_cap(),
13241325
insert_use: self.insert_use_config(source_root),
13251326
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
13261327
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
@@ -2007,8 +2008,10 @@ impl Config {
20072008
*self.references_excludeTests()
20082009
}
20092010

2010-
pub fn snippet_cap(&self) -> bool {
2011-
self.experimental("snippetTextEdit")
2011+
pub fn snippet_cap(&self) -> Option<SnippetCap> {
2012+
// FIXME: Also detect the proposed lsp version at caps.workspace.workspaceEdit.snippetEditSupport
2013+
// once lsp-types has it.
2014+
SnippetCap::new(self.experimental("snippetTextEdit"))
20122015
}
20132016

20142017
pub fn call_info(&self) -> CallInfoConfig {

src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ fn integrated_diagnostics_benchmark() {
289289
disabled: Default::default(),
290290
expr_fill_default: Default::default(),
291291
style_lints: false,
292+
snippet_cap: SnippetCap::new(true),
292293
insert_use: InsertUseConfig {
293294
granularity: ImportGranularity::Crate,
294295
enforce_granularity: false,

0 commit comments

Comments
 (0)