Skip to content

Commit 8fd7ae9

Browse files
committed
Make borrow checking configurable for term search
1 parent fde5564 commit 8fd7ae9

File tree

10 files changed

+38
-2
lines changed

10 files changed

+38
-2
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/assist_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ pub struct AssistConfig {
1717
pub prefer_prelude: bool,
1818
pub assist_emit_must_use: bool,
1919
pub term_search_fuel: u64,
20+
pub term_search_borrowck: bool,
2021
}

src/tools/rust-analyzer/crates/ide-assists/src/handlers/term_search.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ pub(crate) fn term_search(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
3737
sema: &ctx.sema,
3838
scope: &scope,
3939
goal: target_ty,
40-
config: TermSearchConfig { fuel: ctx.config.term_search_fuel, ..Default::default() },
40+
config: TermSearchConfig {
41+
fuel: ctx.config.term_search_fuel,
42+
enable_borrowcheck: ctx.config.term_search_borrowck,
43+
..Default::default()
44+
},
4145
};
4246
let paths = hir::term_search::term_search(&term_search_ctx);
4347

src/tools/rust-analyzer/crates/ide-assists/src/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
3232
prefer_prelude: true,
3333
assist_emit_must_use: false,
3434
term_search_fuel: 400,
35+
term_search_borrowck: true,
3536
};
3637

3738
pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
@@ -48,6 +49,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
4849
prefer_prelude: true,
4950
assist_emit_must_use: false,
5051
term_search_fuel: 400,
52+
term_search_borrowck: true,
5153
};
5254

5355
pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
@@ -64,6 +66,7 @@ pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
6466
prefer_prelude: true,
6567
assist_emit_must_use: false,
6668
term_search_fuel: 400,
69+
term_search_borrowck: true,
6770
};
6871

6972
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {

src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/typed_hole.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Option<Vec<Assist>
4747
sema: &ctx.sema,
4848
scope: &scope,
4949
goal: d.expected.clone(),
50-
config: TermSearchConfig { fuel: ctx.config.term_search_fuel, ..Default::default() },
50+
config: TermSearchConfig {
51+
fuel: ctx.config.term_search_fuel,
52+
enable_borrowcheck: ctx.config.term_search_borrowck,
53+
54+
..Default::default()
55+
},
5156
};
5257
let paths = term_search(&term_search_ctx);
5358

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub struct DiagnosticsConfig {
234234
pub prefer_no_std: bool,
235235
pub prefer_prelude: bool,
236236
pub term_search_fuel: u64,
237+
pub term_search_borrowck: bool,
237238
}
238239

239240
impl DiagnosticsConfig {
@@ -260,6 +261,7 @@ impl DiagnosticsConfig {
260261
prefer_no_std: false,
261262
prefer_prelude: true,
262263
term_search_fuel: 400,
264+
term_search_borrowck: true,
263265
}
264266
}
265267
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ impl flags::AnalysisStats {
994994
prefer_prelude: true,
995995
style_lints: false,
996996
term_search_fuel: 400,
997+
term_search_borrowck: true,
997998
},
998999
ide::AssistResolveStrategy::All,
9991000
file_id,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ config_data! {
341341
assist_emitMustUse: bool = false,
342342
/// Placeholder expression to use for missing expressions in assists.
343343
assist_expressionFillDefault: ExprFillDefaultDef = ExprFillDefaultDef::Todo,
344+
/// 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.
345+
assist_termSearch_borrowcheck: bool = true,
344346
/// Term search fuel in "units of work" for assists (Defaults to 1800).
345347
assist_termSearch_fuel: usize = 1800,
346348

@@ -1269,6 +1271,7 @@ impl Config {
12691271
assist_emit_must_use: self.assist_emitMustUse(source_root).to_owned(),
12701272
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
12711273
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
1274+
term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(),
12721275
}
12731276
}
12741277

@@ -1328,6 +1331,7 @@ impl Config {
13281331
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
13291332
style_lints: self.diagnostics_styleLints_enable().to_owned(),
13301333
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
1334+
term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(),
13311335
}
13321336
}
13331337
pub fn expand_proc_attr_macros(&self) -> bool {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ fn integrated_diagnostics_benchmark() {
300300
prefer_no_std: false,
301301
prefer_prelude: false,
302302
term_search_fuel: 400,
303+
term_search_borrowck: true,
303304
};
304305
host.analysis()
305306
.diagnostics(&diagnostics_config, ide::AssistResolveStrategy::None, file_id)

src/tools/rust-analyzer/docs/user/generated_config.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ for enum variants.
99
--
1010
Placeholder expression to use for missing expressions in assists.
1111
--
12+
[[rust-analyzer.assist.termSearch.borrowcheck]]rust-analyzer.assist.termSearch.borrowcheck (default: `true`)::
13+
+
14+
--
15+
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.
16+
--
1217
[[rust-analyzer.assist.termSearch.fuel]]rust-analyzer.assist.termSearch.fuel (default: `1800`)::
1318
+
1419
--

src/tools/rust-analyzer/editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,16 @@
588588
}
589589
}
590590
},
591+
{
592+
"title": "assist",
593+
"properties": {
594+
"rust-analyzer.assist.termSearch.borrowcheck": {
595+
"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.",
596+
"default": true,
597+
"type": "boolean"
598+
}
599+
}
600+
},
591601
{
592602
"title": "assist",
593603
"properties": {

0 commit comments

Comments
 (0)