diff options
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index d6a44c3e0..67fb7ba4e 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -6,46 +6,48 @@ use rustc_hash::FxHashMap; | |||
6 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; | 6 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; |
7 | 7 | ||
8 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | 8 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { |
9 | if ctx.is_trivial_path { | 9 | if !ctx.is_trivial_path { |
10 | let names = ctx.analyzer.all_names(ctx.db); | 10 | return; |
11 | names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); | 11 | } |
12 | 12 | ||
13 | // auto-import | 13 | let names = ctx.analyzer.all_names(ctx.db); |
14 | // We fetch ident from the original file, because we need to pre-filter auto-imports | 14 | names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); |
15 | if ast::NameRef::cast(ctx.token.parent()).is_some() { | ||
16 | let import_resolver = ImportResolver::new(); | ||
17 | let import_names = import_resolver.all_names(ctx.token.text()); | ||
18 | import_names.into_iter().for_each(|(name, path)| { | ||
19 | let edit = { | ||
20 | let mut builder = TextEditBuilder::default(); | ||
21 | builder.replace(ctx.source_range(), name.to_string()); | ||
22 | auto_import::auto_import_text_edit( | ||
23 | &ctx.token.parent(), | ||
24 | &ctx.token.parent(), | ||
25 | &path, | ||
26 | &mut builder, | ||
27 | ); | ||
28 | builder.finish() | ||
29 | }; | ||
30 | 15 | ||
31 | // Hack: copied this check form conv.rs beacause auto import can produce edits | 16 | // auto-import |
32 | // that invalidate assert in conv_with. | 17 | // We fetch ident from the original file, because we need to pre-filter auto-imports |
33 | if edit | 18 | if ast::NameRef::cast(ctx.token.parent()).is_some() { |
34 | .as_atoms() | 19 | let import_resolver = ImportResolver::new(); |
35 | .iter() | 20 | let import_names = import_resolver.all_names(ctx.token.text()); |
36 | .filter(|atom| !ctx.source_range().is_subrange(&atom.delete)) | 21 | import_names.into_iter().for_each(|(name, path)| { |
37 | .all(|atom| ctx.source_range().intersection(&atom.delete).is_none()) | 22 | let edit = { |
38 | { | 23 | let mut builder = TextEditBuilder::default(); |
39 | CompletionItem::new( | 24 | builder.replace(ctx.source_range(), name.to_string()); |
40 | CompletionKind::Reference, | 25 | auto_import::auto_import_text_edit( |
41 | ctx.source_range(), | 26 | &ctx.token.parent(), |
42 | build_import_label(&name, &path), | 27 | &ctx.token.parent(), |
43 | ) | 28 | &path, |
44 | .text_edit(edit) | 29 | &mut builder, |
45 | .add_to(acc); | 30 | ); |
46 | } | 31 | builder.finish() |
47 | }); | 32 | }; |
48 | } | 33 | |
34 | // Hack: copied this check form conv.rs beacause auto import can produce edits | ||
35 | // that invalidate assert in conv_with. | ||
36 | if edit | ||
37 | .as_atoms() | ||
38 | .iter() | ||
39 | .filter(|atom| !ctx.source_range().is_subrange(&atom.delete)) | ||
40 | .all(|atom| ctx.source_range().intersection(&atom.delete).is_none()) | ||
41 | { | ||
42 | CompletionItem::new( | ||
43 | CompletionKind::Reference, | ||
44 | ctx.source_range(), | ||
45 | build_import_label(&name, &path), | ||
46 | ) | ||
47 | .text_edit(edit) | ||
48 | .add_to(acc); | ||
49 | } | ||
50 | }); | ||
49 | } | 51 | } |
50 | } | 52 | } |
51 | 53 | ||