mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
Make borrow checking configurable for term search
This commit is contained in:
parent
9463d9eea4
commit
1389312871
10 changed files with 38 additions and 2 deletions
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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`)::
|
||||
+
|
||||
--
|
||||
|
|
|
@ -588,6 +588,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": {
|
||||
|
|
Loading…
Reference in a new issue