Unnamed repository; edit this file 'description' to name the repository.
Make borrow checking configurable for term search
Tavo Annus 2024-06-29
parent 9463d9e · commit 1389312
-rw-r--r--crates/ide-assists/src/assist_config.rs1
-rw-r--r--crates/ide-assists/src/handlers/term_search.rs6
-rw-r--r--crates/ide-assists/src/tests.rs3
-rw-r--r--crates/ide-diagnostics/src/handlers/typed_hole.rs7
-rw-r--r--crates/ide-diagnostics/src/lib.rs2
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs1
-rw-r--r--docs/user/generated_config.adoc5
-rw-r--r--editors/code/package.json10
10 files changed, 38 insertions, 2 deletions
diff --git a/crates/ide-assists/src/assist_config.rs b/crates/ide-assists/src/assist_config.rs
index 5d76cb0432..410237f9ca 100644
--- a/crates/ide-assists/src/assist_config.rs
+++ b/crates/ide-assists/src/assist_config.rs
@@ -17,4 +17,5 @@ pub struct AssistConfig {
pub prefer_prelude: bool,
pub assist_emit_must_use: bool,
pub term_search_fuel: u64,
+ pub term_search_borrowck: bool,
}
diff --git a/crates/ide-assists/src/handlers/term_search.rs b/crates/ide-assists/src/handlers/term_search.rs
index b62c3b3323..148b951a4b 100644
--- a/crates/ide-assists/src/handlers/term_search.rs
+++ b/crates/ide-assists/src/handlers/term_search.rs
@@ -37,7 +37,11 @@ pub(crate) fn term_search(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
sema: &ctx.sema,
scope: &scope,
goal: target_ty,
- config: TermSearchConfig { fuel: ctx.config.term_search_fuel, ..Default::default() },
+ config: TermSearchConfig {
+ fuel: ctx.config.term_search_fuel,
+ enable_borrowcheck: ctx.config.term_search_borrowck,
+ ..Default::default()
+ },
};
let paths = hir::term_search::term_search(&term_search_ctx);
diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs
index 3b6c951251..bd10b5481b 100644
--- a/crates/ide-assists/src/tests.rs
+++ b/crates/ide-assists/src/tests.rs
@@ -32,6 +32,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
prefer_prelude: true,
assist_emit_must_use: false,
term_search_fuel: 400,
+ term_search_borrowck: true,
};
pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
@@ -48,6 +49,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
prefer_prelude: true,
assist_emit_must_use: false,
term_search_fuel: 400,
+ term_search_borrowck: true,
};
pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
@@ -64,6 +66,7 @@ pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
prefer_prelude: true,
assist_emit_must_use: false,
term_search_fuel: 400,
+ term_search_borrowck: true,
};
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
diff --git a/crates/ide-diagnostics/src/handlers/typed_hole.rs b/crates/ide-diagnostics/src/handlers/typed_hole.rs
index 71917e09f0..a64bac2949 100644
--- a/crates/ide-diagnostics/src/handlers/typed_hole.rs
+++ b/crates/ide-diagnostics/src/handlers/typed_hole.rs
@@ -47,7 +47,12 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Option<Vec<Assist>
sema: &ctx.sema,
scope: &scope,
goal: d.expected.clone(),
- config: TermSearchConfig { fuel: ctx.config.term_search_fuel, ..Default::default() },
+ config: TermSearchConfig {
+ fuel: ctx.config.term_search_fuel,
+ enable_borrowcheck: ctx.config.term_search_borrowck,
+
+ ..Default::default()
+ },
};
let paths = term_search(&term_search_ctx);
diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs
index a419f04bfa..f176c30c4a 100644
--- a/crates/ide-diagnostics/src/lib.rs
+++ b/crates/ide-diagnostics/src/lib.rs
@@ -234,6 +234,7 @@ pub struct DiagnosticsConfig {
pub prefer_no_std: bool,
pub prefer_prelude: bool,
pub term_search_fuel: u64,
+ pub term_search_borrowck: bool,
}
impl DiagnosticsConfig {
@@ -260,6 +261,7 @@ impl DiagnosticsConfig {
prefer_no_std: false,
prefer_prelude: true,
term_search_fuel: 400,
+ term_search_borrowck: true,
}
}
}
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 90b81d0a80..a429f75568 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -994,6 +994,7 @@ impl flags::AnalysisStats {
prefer_prelude: true,
style_lints: false,
term_search_fuel: 400,
+ term_search_borrowck: true,
},
ide::AssistResolveStrategy::All,
file_id,
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index f719a47248..86b61629e3 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -341,6 +341,8 @@ config_data! {
assist_emitMustUse: bool = false,
/// Placeholder expression to use for missing expressions in assists.
assist_expressionFillDefault: ExprFillDefaultDef = ExprFillDefaultDef::Todo,
+ /// Enable borrow checking for term search code assists. If set to false, also there will be more suggestions, but some of them may not borrow-check.
+ assist_termSearch_borrowcheck: bool = true,
/// Term search fuel in "units of work" for assists (Defaults to 1800).
assist_termSearch_fuel: usize = 1800,
@@ -1269,6 +1271,7 @@ impl Config {
assist_emit_must_use: self.assist_emitMustUse(source_root).to_owned(),
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
+ term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(),
}
}
@@ -1328,6 +1331,7 @@ impl Config {
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
style_lints: self.diagnostics_styleLints_enable().to_owned(),
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
+ term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(),
}
}
pub fn expand_proc_attr_macros(&self) -> bool {
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index 1e2cd4339b..65fbc96dad 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -300,6 +300,7 @@ fn integrated_diagnostics_benchmark() {
prefer_no_std: false,
prefer_prelude: false,
term_search_fuel: 400,
+ term_search_borrowck: true,
};
host.analysis()
.diagnostics(&diagnostics_config, ide::AssistResolveStrategy::None, file_id)
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 81f30dc56e..25d9430621 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -9,6 +9,11 @@ for enum variants.
--
Placeholder expression to use for missing expressions in assists.
--
+[[rust-analyzer.assist.termSearch.borrowcheck]]rust-analyzer.assist.termSearch.borrowcheck (default: `true`)::
++
+--
+Enable borrow checking for term search code assists. If set to false, also there will be more suggestions, but some of them may not borrow-check.
+--
[[rust-analyzer.assist.termSearch.fuel]]rust-analyzer.assist.termSearch.fuel (default: `1800`)::
+
--
diff --git a/editors/code/package.json b/editors/code/package.json
index 0da5b920a7..7f9987b935 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -591,6 +591,16 @@
{
"title": "assist",
"properties": {
+ "rust-analyzer.assist.termSearch.borrowcheck": {
+ "markdownDescription": "Enable borrow checking for term search code assists. If set to false, also there will be more suggestions, but some of them may not borrow-check.",
+ "default": true,
+ "type": "boolean"
+ }
+ }
+ },
+ {
+ "title": "assist",
+ "properties": {
"rust-analyzer.assist.termSearch.fuel": {
"markdownDescription": "Term search fuel in \"units of work\" for assists (Defaults to 1800).",
"default": 1800,