Skip to content

Commit 8ef19e7

Browse files
committed
Make term search fuel configurable
1 parent f9f1d31 commit 8ef19e7

File tree

16 files changed

+56
-9
lines changed

16 files changed

+56
-9
lines changed

src/tools/rust-analyzer/crates/hir/src/term_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub struct TermSearchConfig {
269269
pub enable_borrowcheck: bool,
270270
/// Indicate when to squash multiple trees to `Many` as there are too many to keep track
271271
pub many_alternatives_threshold: usize,
272-
/// Fuel for term search
272+
/// Fuel for term search in "units of work"
273273
pub fuel: u64,
274274
}
275275

src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,7 @@ impl Expr {
474474
Expr::Method { target, func, .. } => {
475475
match func.as_assoc_item(db).and_then(|it| it.container_or_implemented_trait(db)) {
476476
Some(_) => false,
477-
None => {
478-
target.is_many()
479-
}
477+
None => target.is_many(),
480478
}
481479
}
482480
Expr::Field { expr, .. } => expr.contains_many_in_illegal_pos(db),

src/tools/rust-analyzer/crates/hir/src/term_search/tactics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! * `ctx` - Context for the term search
55
//! * `defs` - Set of items in scope at term search target location
66
//! * `lookup` - Lookup table for types
7+
//! * `should_continue` - Function that indicates when to stop iterating
78
//! And they return iterator that yields type trees that unify with the `goal` type.
89
910
use std::iter;
@@ -97,6 +98,7 @@ pub(super) fn trivial<'a, DB: HirDatabase>(
9798
/// * `ctx` - Context for the term search
9899
/// * `defs` - Set of items in scope at term search target location
99100
/// * `lookup` - Lookup table for types
101+
/// * `should_continue` - Function that indicates when to stop iterating
100102
pub(super) fn type_constructor<'a, DB: HirDatabase>(
101103
ctx: &'a TermSearchCtx<'a, DB>,
102104
defs: &'a FxHashSet<ScopeDef>,
@@ -357,6 +359,7 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
357359
/// * `ctx` - Context for the term search
358360
/// * `defs` - Set of items in scope at term search target location
359361
/// * `lookup` - Lookup table for types
362+
/// * `should_continue` - Function that indicates when to stop iterating
360363
pub(super) fn free_function<'a, DB: HirDatabase>(
361364
ctx: &'a TermSearchCtx<'a, DB>,
362365
defs: &'a FxHashSet<ScopeDef>,
@@ -488,6 +491,7 @@ pub(super) fn free_function<'a, DB: HirDatabase>(
488491
/// * `ctx` - Context for the term search
489492
/// * `defs` - Set of items in scope at term search target location
490493
/// * `lookup` - Lookup table for types
494+
/// * `should_continue` - Function that indicates when to stop iterating
491495
pub(super) fn impl_method<'a, DB: HirDatabase>(
492496
ctx: &'a TermSearchCtx<'a, DB>,
493497
_defs: &'a FxHashSet<ScopeDef>,
@@ -661,6 +665,7 @@ pub(super) fn impl_method<'a, DB: HirDatabase>(
661665
/// * `ctx` - Context for the term search
662666
/// * `defs` - Set of items in scope at term search target location
663667
/// * `lookup` - Lookup table for types
668+
/// * `should_continue` - Function that indicates when to stop iterating
664669
pub(super) fn struct_projection<'a, DB: HirDatabase>(
665670
ctx: &'a TermSearchCtx<'a, DB>,
666671
_defs: &'a FxHashSet<ScopeDef>,
@@ -734,6 +739,7 @@ pub(super) fn famous_types<'a, DB: HirDatabase>(
734739
/// * `ctx` - Context for the term search
735740
/// * `defs` - Set of items in scope at term search target location
736741
/// * `lookup` - Lookup table for types
742+
/// * `should_continue` - Function that indicates when to stop iterating
737743
pub(super) fn impl_static_method<'a, DB: HirDatabase>(
738744
ctx: &'a TermSearchCtx<'a, DB>,
739745
_defs: &'a FxHashSet<ScopeDef>,
@@ -905,6 +911,7 @@ pub(super) fn impl_static_method<'a, DB: HirDatabase>(
905911
/// * `ctx` - Context for the term search
906912
/// * `defs` - Set of items in scope at term search target location
907913
/// * `lookup` - Lookup table for types
914+
/// * `should_continue` - Function that indicates when to stop iterating
908915
pub(super) fn make_tuple<'a, DB: HirDatabase>(
909916
ctx: &'a TermSearchCtx<'a, DB>,
910917
_defs: &'a FxHashSet<ScopeDef>,

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
@@ -16,4 +16,5 @@ pub struct AssistConfig {
1616
pub prefer_no_std: bool,
1717
pub prefer_prelude: bool,
1818
pub assist_emit_must_use: bool,
19+
pub term_search_fuel: u64,
1920
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Term search assist
2-
use hir::term_search::TermSearchCtx;
2+
use hir::term_search::{TermSearchConfig, TermSearchCtx};
33
use ide_db::{
44
assists::{AssistId, AssistKind, GroupLabel},
55
famous_defs::FamousDefs,
@@ -34,7 +34,7 @@ pub(crate) fn term_search(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
3434
sema: &ctx.sema,
3535
scope: &scope,
3636
goal: target_ty,
37-
config: Default::default(),
37+
config: TermSearchConfig { fuel: ctx.config.term_search_fuel, ..Default::default() },
3838
};
3939
let paths = hir::term_search::term_search(&term_search_ctx);
4040

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
3131
prefer_no_std: false,
3232
prefer_prelude: true,
3333
assist_emit_must_use: false,
34+
term_search_fuel: 400,
3435
};
3536

3637
pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
@@ -46,6 +47,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
4647
prefer_no_std: false,
4748
prefer_prelude: true,
4849
assist_emit_must_use: false,
50+
term_search_fuel: 400,
4951
};
5052

5153
pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
@@ -61,6 +63,7 @@ pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
6163
prefer_no_std: false,
6264
prefer_prelude: true,
6365
assist_emit_must_use: false,
66+
term_search_fuel: 400,
6467
};
6568

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

src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ pub(crate) fn complete_expr(acc: &mut Completions, ctx: &CompletionContext<'_>)
354354
enable_borrowcheck: false,
355355
many_alternatives_threshold: 1,
356356
fuel: 200,
357-
..Default::default()
358357
},
359358
};
360359
let exprs = hir::term_search::term_search(&term_search_ctx);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct CompletionConfig {
1515
pub enable_self_on_the_fly: bool,
1616
pub enable_private_editable: bool,
1717
pub enable_term_search: bool,
18+
pub term_search_fuel: u64,
1819
pub full_function_signatures: bool,
1920
pub callable: Option<CallableSnippets>,
2021
pub snippet_cap: Option<SnippetCap>,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
8080
},
8181
snippets: Vec::new(),
8282
limit: None,
83+
term_search_fuel: 200,
8384
};
8485

8586
pub(crate) fn completion_list(ra_fixture: &str) -> String {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hir::{
22
db::ExpandDatabase,
3-
term_search::{term_search, TermSearchCtx},
3+
term_search::{term_search, TermSearchConfig, TermSearchCtx},
44
ClosureStyle, HirDisplay,
55
};
66
use ide_db::{
@@ -47,7 +47,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Option<Vec<Assist>
4747
sema: &ctx.sema,
4848
scope: &scope,
4949
goal: d.expected.clone(),
50-
config: Default::default(),
50+
config: TermSearchConfig { fuel: ctx.config.term_search_fuel, ..Default::default() },
5151
};
5252
let paths = term_search(&term_search_ctx);
5353

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub struct DiagnosticsConfig {
232232
pub insert_use: InsertUseConfig,
233233
pub prefer_no_std: bool,
234234
pub prefer_prelude: bool,
235+
pub term_search_fuel: u64,
235236
}
236237

237238
impl DiagnosticsConfig {
@@ -256,6 +257,7 @@ impl DiagnosticsConfig {
256257
},
257258
prefer_no_std: false,
258259
prefer_prelude: true,
260+
term_search_fuel: 400,
259261
}
260262
}
261263
}

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
@@ -986,6 +986,7 @@ impl flags::AnalysisStats {
986986
prefer_no_std: false,
987987
prefer_prelude: true,
988988
style_lints: false,
989+
term_search_fuel: 400,
989990
},
990991
ide::AssistResolveStrategy::All,
991992
file_id,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ config_data! {
454454
/// Local configurations can be overridden for every crate by placing a `rust-analyzer.toml` on crate root.
455455
/// A config is searched for by traversing a "config tree" in a bottom up fashion. It is chosen by the nearest first principle.
456456
local: struct LocalDefaultConfigData <- LocalConfigInput -> {
457+
/// Term search fuel in "units of work" for assists (Defaults to 400).
458+
assist_termSearch_fuel: usize = 400,
459+
457460
/// Toggles the additional completions that automatically add imports when completed.
458461
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
459462
completion_autoimport_enable: bool = true,
@@ -515,6 +518,8 @@ config_data! {
515518
}"#).unwrap(),
516519
/// Whether to enable term search based snippets like `Some(foo.bar().baz())`.
517520
completion_termSearch_enable: bool = false,
521+
/// Term search fuel in "units of work" for autocompletion (Defaults to 200).
522+
completion_termSearch_fuel: usize = 200,
518523

519524
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
520525
highlightRelated_breakPoints_enable: bool = true,
@@ -1015,6 +1020,7 @@ impl Config {
10151020
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
10161021
assist_emit_must_use: self.assist_emitMustUse().to_owned(),
10171022
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
1023+
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
10181024
}
10191025
}
10201026

@@ -1048,6 +1054,7 @@ impl Config {
10481054
snippets: self.snippets.clone().to_vec(),
10491055
limit: self.completion_limit(source_root).to_owned(),
10501056
enable_term_search: self.completion_termSearch_enable(source_root).to_owned(),
1057+
term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64,
10511058
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
10521059
}
10531060
}
@@ -1067,6 +1074,7 @@ impl Config {
10671074
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
10681075
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
10691076
style_lints: self.diagnostics_styleLints_enable().to_owned(),
1077+
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
10701078
}
10711079
}
10721080
pub fn expand_proc_attr_macros(&self) -> bool {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fn integrated_completion_benchmark() {
153153
prefer_no_std: false,
154154
prefer_prelude: true,
155155
limit: None,
156+
term_search_fuel: 200,
156157
};
157158
let position =
158159
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
@@ -197,6 +198,7 @@ fn integrated_completion_benchmark() {
197198
prefer_no_std: false,
198199
prefer_prelude: true,
199200
limit: None,
201+
term_search_fuel: 200,
200202
};
201203
let position =
202204
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
@@ -239,6 +241,7 @@ fn integrated_completion_benchmark() {
239241
prefer_no_std: false,
240242
prefer_prelude: true,
241243
limit: None,
244+
term_search_fuel: 200,
242245
};
243246
let position =
244247
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
@@ -295,6 +298,7 @@ fn integrated_diagnostics_benchmark() {
295298
},
296299
prefer_no_std: false,
297300
prefer_prelude: false,
301+
term_search_fuel: 400,
298302
};
299303
host.analysis()
300304
.diagnostics(&diagnostics_config, ide::AssistResolveStrategy::None, file_id)

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

Lines changed: 10 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.fuel]]rust-analyzer.assist.termSearch.fuel (default: `400`)::
13+
+
14+
--
15+
Term search fuel in "units of work" for assists (Defaults to 400).
16+
--
1217
[[rust-analyzer.cachePriming.enable]]rust-analyzer.cachePriming.enable (default: `true`)::
1318
+
1419
--
@@ -373,6 +378,11 @@ Custom completion snippets.
373378
--
374379
Whether to enable term search based snippets like `Some(foo.bar().baz())`.
375380
--
381+
[[rust-analyzer.completion.termSearch.fuel]]rust-analyzer.completion.termSearch.fuel (default: `200`)::
382+
+
383+
--
384+
Term search fuel in "units of work" for autocompletion (Defaults to 200).
385+
--
376386
[[rust-analyzer.diagnostics.disabled]]rust-analyzer.diagnostics.disabled (default: `[]`)::
377387
+
378388
--

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@
534534
"Fill missing expressions with reasonable defaults, `new` or `default` constructors."
535535
]
536536
},
537+
"rust-analyzer.assist.termSearch.fuel": {
538+
"markdownDescription": "Term search fuel in \"units of work\" for assists (Defaults to 400).",
539+
"default": 400,
540+
"type": "integer",
541+
"minimum": 0
542+
},
537543
"rust-analyzer.cachePriming.enable": {
538544
"markdownDescription": "Warm up caches on project load.",
539545
"default": true,
@@ -930,6 +936,12 @@
930936
"default": false,
931937
"type": "boolean"
932938
},
939+
"rust-analyzer.completion.termSearch.fuel": {
940+
"markdownDescription": "Term search fuel in \"units of work\" for autocompletion (Defaults to 200).",
941+
"default": 200,
942+
"type": "integer",
943+
"minimum": 0
944+
},
933945
"rust-analyzer.diagnostics.disabled": {
934946
"markdownDescription": "List of rust-analyzer diagnostics to disable.",
935947
"default": [],

0 commit comments

Comments
 (0)