@@ -15,7 +15,6 @@ use crate::{
15
15
symbol_index:: { self , FileSymbol } ,
16
16
RootDatabase ,
17
17
} ;
18
- use rustc_hash:: FxHashSet ;
19
18
20
19
/// A value to use, when uncertain which limit to pick.
21
20
pub const DEFAULT_QUERY_SEARCH_LIMIT : usize = 40 ;
@@ -32,13 +31,13 @@ pub enum AssocItemSearch {
32
31
}
33
32
34
33
/// Searches for importable items with the given name in the crate and its dependencies.
35
- pub fn items_with_name (
36
- sema : & Semantics < ' _ , RootDatabase > ,
34
+ pub fn items_with_name < ' a > (
35
+ sema : & ' a Semantics < ' _ , RootDatabase > ,
37
36
krate : Crate ,
38
37
name : NameToImport ,
39
38
assoc_item_search : AssocItemSearch ,
40
39
limit : Option < usize > ,
41
- ) -> FxHashSet < ItemInNs > {
40
+ ) -> impl Iterator < Item = ItemInNs > + ' a {
42
41
let _p = profile:: span ( "items_with_name" ) . detail ( || {
43
42
format ! (
44
43
"Name: {} ({:?}), crate: {:?}, limit: {:?}" ,
@@ -94,13 +93,13 @@ pub fn items_with_name(
94
93
find_items ( sema, krate, assoc_item_search, local_query, external_query)
95
94
}
96
95
97
- fn find_items (
98
- sema : & Semantics < ' _ , RootDatabase > ,
96
+ fn find_items < ' a > (
97
+ sema : & ' a Semantics < ' _ , RootDatabase > ,
99
98
krate : Crate ,
100
99
assoc_item_search : AssocItemSearch ,
101
100
local_query : symbol_index:: Query ,
102
101
external_query : import_map:: Query ,
103
- ) -> FxHashSet < ItemInNs > {
102
+ ) -> impl Iterator < Item = ItemInNs > + ' a {
104
103
let _p = profile:: span ( "find_items" ) ;
105
104
let db = sema. db ;
106
105
@@ -115,21 +114,18 @@ fn find_items(
115
114
// Query the local crate using the symbol index.
116
115
let local_results = symbol_index:: crate_symbols ( db, krate. into ( ) , local_query)
117
116
. into_iter ( )
118
- . filter_map ( |local_candidate| get_name_definition ( sema, & local_candidate) )
117
+ . filter_map ( move |local_candidate| get_name_definition ( sema, & local_candidate) )
119
118
. filter_map ( |name_definition_to_import| match name_definition_to_import {
120
119
Definition :: ModuleDef ( module_def) => Some ( ItemInNs :: from ( module_def) ) ,
121
120
Definition :: Macro ( macro_def) => Some ( ItemInNs :: from ( macro_def) ) ,
122
121
_ => None ,
123
122
} ) ;
124
123
125
- external_importables
126
- . chain ( local_results)
127
- . filter ( move |& item| match assoc_item_search {
128
- AssocItemSearch :: Include => true ,
129
- AssocItemSearch :: Exclude => !is_assoc_item ( item, sema. db ) ,
130
- AssocItemSearch :: AssocItemsOnly => is_assoc_item ( item, sema. db ) ,
131
- } )
132
- . collect ( )
124
+ external_importables. chain ( local_results) . filter ( move |& item| match assoc_item_search {
125
+ AssocItemSearch :: Include => true ,
126
+ AssocItemSearch :: Exclude => !is_assoc_item ( item, sema. db ) ,
127
+ AssocItemSearch :: AssocItemsOnly => is_assoc_item ( item, sema. db ) ,
128
+ } )
133
129
}
134
130
135
131
fn get_name_definition (
0 commit comments