|
1 | 1 | //! Look up accessible paths for items.
|
2 | 2 | use either::Either;
|
3 | 3 | use hir::{
|
4 |
| - AsAssocItem, AssocItem, Crate, ItemInNs, MacroDef, ModPath, Module, ModuleDef, PathResolution, |
5 |
| - PrefixKind, Semantics, |
| 4 | + AsAssocItem, AssocItem, Crate, ItemInNs, MacroDef, ModPath, Module, ModuleDef, PrefixKind, |
| 5 | + Semantics, |
6 | 6 | };
|
7 | 7 | use rustc_hash::FxHashSet;
|
8 | 8 | use syntax::{ast, AstNode};
|
@@ -192,7 +192,7 @@ impl ImportAssets {
|
192 | 192 | let db = sema.db;
|
193 | 193 |
|
194 | 194 | match &self.import_candidate {
|
195 |
| - ImportCandidate::Path(path_candidate) => Box::new(path_applicable_defs( |
| 195 | + ImportCandidate::Path(path_candidate) => Box::new(path_applicable_items( |
196 | 196 | sema,
|
197 | 197 | path_candidate,
|
198 | 198 | unfiltered_defs
|
@@ -223,37 +223,28 @@ impl ImportAssets {
|
223 | 223 | }
|
224 | 224 | }
|
225 | 225 |
|
226 |
| -fn path_applicable_defs<'a>( |
| 226 | +fn path_applicable_items<'a>( |
227 | 227 | sema: &'a Semantics<RootDatabase>,
|
228 | 228 | path_candidate: &PathImportCandidate,
|
229 | 229 | unfiltered_defs: impl Iterator<Item = (ModPath, ItemInNs)> + 'a,
|
230 |
| -) -> impl Iterator<Item = (ModPath, ItemInNs)> + 'a { |
| 230 | +) -> Box<dyn Iterator<Item = (ModPath, ItemInNs)> + 'a> { |
231 | 231 | let unresolved_qualifier = match &path_candidate.unresolved_qualifier {
|
232 | 232 | Some(qualifier) => qualifier,
|
233 | 233 | None => {
|
234 |
| - return unfiltered_defs; |
| 234 | + return Box::new(unfiltered_defs); |
235 | 235 | }
|
236 | 236 | };
|
237 | 237 |
|
238 |
| - // TODO kb filter out items: found path should end with `qualifier::Name` or `qualifier::Something` for fuzzy search case. |
| 238 | + let qualifier_string = unresolved_qualifier.to_string(); |
| 239 | + Box::new(unfiltered_defs.filter(move |(candidate_path, _)| { |
| 240 | + let mut candidate_qualifier = candidate_path.clone(); |
| 241 | + candidate_qualifier.pop_segment(); |
239 | 242 |
|
240 |
| - // TODO kb find a way to turn a qualifier into the corresponding ModuleDef. Maybe through the unfiltered data? |
241 |
| - if let Some(qualifier_start_resolution) = resolve_qualifier_start(sema, unresolved_qualifier) { |
242 |
| - // TODO kb ascend until an unresolved segment part appears |
243 |
| - } else { |
244 |
| - // first segment is already unresolved, need to turn it into ModuleDef somehow |
245 |
| - } |
246 |
| - |
247 |
| - return unfiltered_defs; |
248 |
| -} |
249 |
| - |
250 |
| -fn resolve_qualifier_start( |
251 |
| - sema: &Semantics<RootDatabase>, |
252 |
| - qualifier: &ast::Path, |
253 |
| -) -> Option<PathResolution> { |
254 |
| - let qualifier_start = qualifier.syntax().descendants().find_map(ast::NameRef::cast)?; |
255 |
| - let qualifier_start_path = qualifier_start.syntax().ancestors().find_map(ast::Path::cast)?; |
256 |
| - sema.resolve_path(&qualifier_start_path) |
| 243 | + // TODO kb |
| 244 | + // * take 1st segment of `unresolved_qualifier` and return it instead of the original `ItemInNs` |
| 245 | + // * Update `ModPath`: pop until 1st segment of `unresolved_qualifier` reached (do not rely on name comparison, nested mod names can repeat) |
| 246 | + candidate_qualifier.to_string().ends_with(&qualifier_string) |
| 247 | + })) |
257 | 248 | }
|
258 | 249 |
|
259 | 250 | fn trait_applicable_defs<'a>(
|
|
0 commit comments