mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 15:58:47 +00:00
simplify
This commit is contained in:
parent
219287a14c
commit
6c11935712
1 changed files with 40 additions and 38 deletions
|
@ -6,46 +6,48 @@ use rustc_hash::FxHashMap;
|
||||||
use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
|
use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
|
||||||
|
|
||||||
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if ctx.is_trivial_path {
|
if !ctx.is_trivial_path {
|
||||||
let names = ctx.analyzer.all_names(ctx.db);
|
return;
|
||||||
names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res));
|
}
|
||||||
|
|
||||||
// auto-import
|
let names = ctx.analyzer.all_names(ctx.db);
|
||||||
// We fetch ident from the original file, because we need to pre-filter auto-imports
|
names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res));
|
||||||
if ast::NameRef::cast(ctx.token.parent()).is_some() {
|
|
||||||
let import_resolver = ImportResolver::new();
|
|
||||||
let import_names = import_resolver.all_names(ctx.token.text());
|
|
||||||
import_names.into_iter().for_each(|(name, path)| {
|
|
||||||
let edit = {
|
|
||||||
let mut builder = TextEditBuilder::default();
|
|
||||||
builder.replace(ctx.source_range(), name.to_string());
|
|
||||||
auto_import::auto_import_text_edit(
|
|
||||||
&ctx.token.parent(),
|
|
||||||
&ctx.token.parent(),
|
|
||||||
&path,
|
|
||||||
&mut builder,
|
|
||||||
);
|
|
||||||
builder.finish()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Hack: copied this check form conv.rs beacause auto import can produce edits
|
// auto-import
|
||||||
// that invalidate assert in conv_with.
|
// We fetch ident from the original file, because we need to pre-filter auto-imports
|
||||||
if edit
|
if ast::NameRef::cast(ctx.token.parent()).is_some() {
|
||||||
.as_atoms()
|
let import_resolver = ImportResolver::new();
|
||||||
.iter()
|
let import_names = import_resolver.all_names(ctx.token.text());
|
||||||
.filter(|atom| !ctx.source_range().is_subrange(&atom.delete))
|
import_names.into_iter().for_each(|(name, path)| {
|
||||||
.all(|atom| ctx.source_range().intersection(&atom.delete).is_none())
|
let edit = {
|
||||||
{
|
let mut builder = TextEditBuilder::default();
|
||||||
CompletionItem::new(
|
builder.replace(ctx.source_range(), name.to_string());
|
||||||
CompletionKind::Reference,
|
auto_import::auto_import_text_edit(
|
||||||
ctx.source_range(),
|
&ctx.token.parent(),
|
||||||
build_import_label(&name, &path),
|
&ctx.token.parent(),
|
||||||
)
|
&path,
|
||||||
.text_edit(edit)
|
&mut builder,
|
||||||
.add_to(acc);
|
);
|
||||||
}
|
builder.finish()
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
// Hack: copied this check form conv.rs beacause auto import can produce edits
|
||||||
|
// that invalidate assert in conv_with.
|
||||||
|
if edit
|
||||||
|
.as_atoms()
|
||||||
|
.iter()
|
||||||
|
.filter(|atom| !ctx.source_range().is_subrange(&atom.delete))
|
||||||
|
.all(|atom| ctx.source_range().intersection(&atom.delete).is_none())
|
||||||
|
{
|
||||||
|
CompletionItem::new(
|
||||||
|
CompletionKind::Reference,
|
||||||
|
ctx.source_range(),
|
||||||
|
build_import_label(&name, &path),
|
||||||
|
)
|
||||||
|
.text_edit(edit)
|
||||||
|
.add_to(acc);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue