diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-05 12:04:35 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-05 12:04:35 +0000 |
commit | d7013a5934af1e2aaa60dcf19b1b6bb529594565 (patch) | |
tree | d9383f5f08d2beed056aa013da3a21f76002f06c /crates/ide_db | |
parent | 5c10f2f705d6757b9821387a5be759789b7ee480 (diff) | |
parent | 543e950e305aa7bd7e0b185753752d0561c70459 (diff) |
Merge #7140
7140: Store trait associated items in fst r=matklad a=SomeoneToIgnore
Store imported traits' associated function/methods and constants into `ImportMap.fst` and pefrorm the imports search on them.
This is a first step towards trait autoimport during completion functionality, the way I see it, after this PR, only a few major things are left to be done:
* store all traits' assoc items into fst, not only the ones in scope, as we do now. Any code pointers on how to do this are welcome 😄
* adjust a few modules in completions crate (`dot.rs`, `qualified_path.rs` at least) to query the import map, reusing the `import_assets` logic heavily
==
With the current import and autoimport implementations, it looks like for a single query, we're either interested in either associated items lookup or in all other `fst` contents lookup, but never both simultaneously.
I would rather not split `fst` in two but add another `Query` parameter to separate those, but let me know if you have any ideas.
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/imports_locator.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index 0f4c2ca47..0782ab070 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! This module contains an import search funcionality that is provided to the assists module. | 1 | //! This module contains an import search funcionality that is provided to the assists module. |
2 | //! Later, this should be moved away to a separate crate that is accessible from the assists module. | 2 | //! Later, this should be moved away to a separate crate that is accessible from the assists module. |
3 | 3 | ||
4 | use hir::{import_map, Crate, MacroDef, ModuleDef, Semantics}; | 4 | use hir::{import_map, AsAssocItem, Crate, MacroDef, ModuleDef, Semantics}; |
5 | use syntax::{ast, AstNode, SyntaxKind::NAME}; | 5 | use syntax::{ast, AstNode, SyntaxKind::NAME}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
@@ -40,8 +40,9 @@ pub fn find_similar_imports<'a>( | |||
40 | krate: Crate, | 40 | krate: Crate, |
41 | limit: Option<usize>, | 41 | limit: Option<usize>, |
42 | fuzzy_search_string: String, | 42 | fuzzy_search_string: String, |
43 | ignore_assoc_items: bool, | ||
43 | name_only: bool, | 44 | name_only: bool, |
44 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { | 45 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> + 'a { |
45 | let _p = profile::span("find_similar_imports"); | 46 | let _p = profile::span("find_similar_imports"); |
46 | 47 | ||
47 | let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) | 48 | let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) |
@@ -57,7 +58,21 @@ pub fn find_similar_imports<'a>( | |||
57 | external_query = external_query.limit(limit); | 58 | external_query = external_query.limit(limit); |
58 | } | 59 | } |
59 | 60 | ||
60 | find_imports(sema, krate, local_query, external_query) | 61 | let db = sema.db; |
62 | find_imports(sema, krate, local_query, external_query).filter(move |import_candidate| { | ||
63 | if ignore_assoc_items { | ||
64 | match import_candidate { | ||
65 | Either::Left(ModuleDef::Function(function)) => function.as_assoc_item(db).is_none(), | ||
66 | Either::Left(ModuleDef::Const(const_)) => const_.as_assoc_item(db).is_none(), | ||
67 | Either::Left(ModuleDef::TypeAlias(type_alias)) => { | ||
68 | type_alias.as_assoc_item(db).is_none() | ||
69 | } | ||
70 | _ => true, | ||
71 | } | ||
72 | } else { | ||
73 | true | ||
74 | } | ||
75 | }) | ||
61 | } | 76 | } |
62 | 77 | ||
63 | fn find_imports<'a>( | 78 | fn find_imports<'a>( |