Skip to content

Commit

Permalink
Merge #6922
Browse files Browse the repository at this point in the history
6922: Show first fuzzy completions fully containing the input r=matklad a=SomeoneToIgnore



Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
  • Loading branch information
bors[bot] and SomeoneToIgnore authored Dec 17, 2020
2 parents b55cb89 + 9d2cbf0 commit a4e17a5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions crates/completion/src/completions/unqualified_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
let anchor = ctx.name_ref_syntax.as_ref()?;
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;

let possible_imports = imports_locator::find_similar_imports(
let mut all_mod_paths = imports_locator::find_similar_imports(
&ctx.sema,
ctx.krate?,
Some(100),
Expand All @@ -144,15 +144,24 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
})
})
.filter(|(mod_path, _)| mod_path.len() > 1)
.filter_map(|(import_path, definition)| {
.collect::<Vec<_>>();

all_mod_paths.sort_by_cached_key(|(mod_path, _)| {
if let Some(name) = mod_path.segments.last().map(|name| name.to_string().to_lowercase()) {
if name.contains(&potential_import_name.to_lowercase()) {
return 0;
}
}
1
});

acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| {
render_resolution_with_import(
RenderContext::new(ctx),
ImportEdit { import_path, import_scope: import_scope.clone() },
&definition,
)
});

acc.add_all(possible_imports);
}));
Some(())
}

Expand Down

0 comments on commit a4e17a5

Please sign in to comment.