Skip to content

Commit

Permalink
internal: Expose snippet capability to diagnostic quickfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DropDemBits committed Jun 8, 2024
1 parent c501753 commit 4f67f71
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use ide_db::{
label::Label,
source_change::SourceChange,
syntax_helpers::node_ext::parse_tt_as_comma_sep_paths,
FxHashMap, FxHashSet, RootDatabase,
FxHashMap, FxHashSet, RootDatabase, SnippetCap,
};
use once_cell::sync::Lazy;
use stdx::never;
Expand Down Expand Up @@ -229,6 +229,7 @@ pub struct DiagnosticsConfig {
pub expr_fill_default: ExprFillDefaultMode,
pub style_lints: bool,
// FIXME: We may want to include a whole `AssistConfig` here
pub snippet_cap: Option<SnippetCap>,
pub insert_use: InsertUseConfig,
pub prefer_no_std: bool,
pub prefer_prelude: bool,
Expand All @@ -248,6 +249,7 @@ impl DiagnosticsConfig {
disabled: Default::default(),
expr_fill_default: Default::default(),
style_lints: true,
snippet_cap: SnippetCap::new(true),
insert_use: InsertUseConfig {
granularity: ImportGranularity::Preserve,
enforce_granularity: false,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/rust-analyzer/src/caps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProvi

fn more_trigger_character(config: &Config) -> Vec<String> {
let mut res = vec![".".to_owned(), ">".to_owned(), "{".to_owned(), "(".to_owned()];
if config.snippet_cap() {
if config.snippet_cap().is_some() {
res.push("<".to_owned());
}
res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use ide_db::{
salsa::{self, debug::DebugQueryTable, ParallelDatabase},
SourceDatabase, SourceDatabaseExt,
},
LineIndexDatabase,
LineIndexDatabase, SnippetCap,
};
use itertools::Itertools;
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
Expand Down Expand Up @@ -982,6 +982,7 @@ impl flags::AnalysisStats {
disable_experimental: false,
disabled: Default::default(),
expr_fill_default: Default::default(),
snippet_cap: SnippetCap::new(true),
insert_use: ide_db::imports::insert_use::InsertUseConfig {
granularity: ide_db::imports::insert_use::ImportGranularity::Crate,
enforce_granularity: true,
Expand Down
9 changes: 6 additions & 3 deletions src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ impl Config {
impl Config {
pub fn assist(&self, source_root: Option<SourceRootId>) -> AssistConfig {
AssistConfig {
snippet_cap: SnippetCap::new(self.experimental("snippetTextEdit")),
snippet_cap: self.snippet_cap(),
allowed: None,
insert_use: self.insert_use_config(source_root),
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
Expand Down Expand Up @@ -1321,6 +1321,7 @@ impl Config {
ExprFillDefaultDef::Todo => ExprFillDefaultMode::Todo,
ExprFillDefaultDef::Default => ExprFillDefaultMode::Default,
},
snippet_cap: self.snippet_cap(),
insert_use: self.insert_use_config(source_root),
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
Expand Down Expand Up @@ -2007,8 +2008,10 @@ impl Config {
*self.references_excludeTests()
}

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

pub fn call_info(&self) -> CallInfoConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ fn integrated_diagnostics_benchmark() {
disabled: Default::default(),
expr_fill_default: Default::default(),
style_lints: false,
snippet_cap: SnippetCap::new(true),
insert_use: InsertUseConfig {
granularity: ImportGranularity::Crate,
enforce_granularity: false,
Expand Down

0 comments on commit 4f67f71

Please sign in to comment.