From 4e0168ec14b74003e8388b72b64c2ca78b580274 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 15:17:10 +0100 Subject: Remove imports from hir --- crates/ra_ide/src/completion/complete_path.rs | 18 ++++++++---------- crates/ra_ide/src/completion/completion_context.rs | 4 ++++ 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index 28f94e0a7..cc1f7c830 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs @@ -1,7 +1,6 @@ //! FIXME: write short doc here -use either::Either; -use hir::{Adt, HasSource, PathResolution}; +use hir::{Adt, PathResolution, ScopeDef}; use ra_syntax::AstNode; use test_utils::tested_by; @@ -19,17 +18,15 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { match def { hir::ModuleDef::Module(module) => { let module_scope = module.scope(ctx.db); - for (name, def, import) in module_scope { - if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def { - if ctx.use_item_syntax.is_some() { + for (name, def) in module_scope { + if ctx.use_item_syntax.is_some() { + if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def { tested_by!(dont_complete_primitive_in_use); continue; } - } - if Some(module) == ctx.module { - if let Some(import) = import { - if let Either::Left(use_tree) = import.source(ctx.db).value { - if use_tree.syntax().text_range().contains_inclusive(ctx.offset) { + if let ScopeDef::Unknown = def { + if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { + if &name_ref.syntax().text() == name.to_string().as_str() { // for `use self::foo<|>`, don't suggest `foo` as a completion tested_by!(dont_complete_current_use); continue; @@ -37,6 +34,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { } } } + acc.add_resolution(ctx, name.to_string(), &def); } } diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 4894ea2f6..48d69f7e5 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -19,6 +19,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) offset: TextUnit, pub(super) token: SyntaxToken, pub(super) module: Option, + pub(super) name_ref_syntax: Option, pub(super) function_syntax: Option, pub(super) use_item_syntax: Option, pub(super) record_lit_syntax: Option, @@ -69,6 +70,7 @@ impl<'a> CompletionContext<'a> { token, offset: position.offset, module, + name_ref_syntax: None, function_syntax: None, use_item_syntax: None, record_lit_syntax: None, @@ -142,6 +144,8 @@ impl<'a> CompletionContext<'a> { } fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { + self.name_ref_syntax = + find_node_at_offset(original_file.syntax(), name_ref.syntax().text_range().start()); let name_range = name_ref.syntax().text_range(); if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); -- cgit v1.2.3