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

0 commit comments

Comments
 (0)