aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/change.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_path.rs17
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs4
3 files changed, 12 insertions, 11 deletions
diff --git a/crates/ra_ide/src/change.rs b/crates/ra_ide/src/change.rs
index 387a9cafb..4a76d1dd8 100644
--- a/crates/ra_ide/src/change.rs
+++ b/crates/ra_ide/src/change.rs
@@ -270,6 +270,7 @@ impl RootDatabase {
270 270
271 self.query(hir::db::AstIdMapQuery).sweep(sweep); 271 self.query(hir::db::AstIdMapQuery).sweep(sweep);
272 272
273 self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep);
273 self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); 274 self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep);
274 275
275 self.query(hir::db::ExprScopesQuery).sweep(sweep); 276 self.query(hir::db::ExprScopesQuery).sweep(sweep);
@@ -308,6 +309,7 @@ impl RootDatabase {
308 hir::db::StructDataQuery 309 hir::db::StructDataQuery
309 hir::db::EnumDataQuery 310 hir::db::EnumDataQuery
310 hir::db::TraitDataQuery 311 hir::db::TraitDataQuery
312 hir::db::RawItemsWithSourceMapQuery
311 hir::db::RawItemsQuery 313 hir::db::RawItemsQuery
312 hir::db::CrateDefMapQuery 314 hir::db::CrateDefMapQuery
313 hir::db::GenericParamsQuery 315 hir::db::GenericParamsQuery
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs
index 8ce86ad7d..28f94e0a7 100644
--- a/crates/ra_ide/src/completion/complete_path.rs
+++ b/crates/ra_ide/src/completion/complete_path.rs
@@ -1,6 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{Adt, PathResolution, ScopeDef}; 3use either::Either;
4use hir::{Adt, HasSource, PathResolution};
4use ra_syntax::AstNode; 5use ra_syntax::AstNode;
5use test_utils::tested_by; 6use test_utils::tested_by;
6 7
@@ -18,15 +19,17 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
18 match def { 19 match def {
19 hir::ModuleDef::Module(module) => { 20 hir::ModuleDef::Module(module) => {
20 let module_scope = module.scope(ctx.db); 21 let module_scope = module.scope(ctx.db);
21 for (name, def) in module_scope { 22 for (name, def, import) in module_scope {
22 if ctx.use_item_syntax.is_some() { 23 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def {
23 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def { 24 if ctx.use_item_syntax.is_some() {
24 tested_by!(dont_complete_primitive_in_use); 25 tested_by!(dont_complete_primitive_in_use);
25 continue; 26 continue;
26 } 27 }
27 if let ScopeDef::Unknown = def { 28 }
28 if let Some(name_ref) = ctx.name_ref.as_ref() { 29 if Some(module) == ctx.module {
29 if &name_ref.syntax().text() == name.to_string().as_str() { 30 if let Some(import) = import {
31 if let Either::Left(use_tree) = import.source(ctx.db).value {
32 if use_tree.syntax().text_range().contains_inclusive(ctx.offset) {
30 // for `use self::foo<|>`, don't suggest `foo` as a completion 33 // for `use self::foo<|>`, don't suggest `foo` as a completion
31 tested_by!(dont_complete_current_use); 34 tested_by!(dont_complete_current_use);
32 continue; 35 continue;
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 8f56ce706..4894ea2f6 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -18,7 +18,6 @@ pub(crate) struct CompletionContext<'a> {
18 pub(super) analyzer: hir::SourceAnalyzer, 18 pub(super) analyzer: hir::SourceAnalyzer,
19 pub(super) offset: TextUnit, 19 pub(super) offset: TextUnit,
20 pub(super) token: SyntaxToken, 20 pub(super) token: SyntaxToken,
21 pub(super) name_ref: Option<ast::NameRef>,
22 pub(super) module: Option<hir::Module>, 21 pub(super) module: Option<hir::Module>,
23 pub(super) function_syntax: Option<ast::FnDef>, 22 pub(super) function_syntax: Option<ast::FnDef>,
24 pub(super) use_item_syntax: Option<ast::UseItem>, 23 pub(super) use_item_syntax: Option<ast::UseItem>,
@@ -69,7 +68,6 @@ impl<'a> CompletionContext<'a> {
69 analyzer, 68 analyzer,
70 token, 69 token,
71 offset: position.offset, 70 offset: position.offset,
72 name_ref: None,
73 module, 71 module,
74 function_syntax: None, 72 function_syntax: None,
75 use_item_syntax: None, 73 use_item_syntax: None,
@@ -144,8 +142,6 @@ impl<'a> CompletionContext<'a> {
144 } 142 }
145 143
146 fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { 144 fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) {
147 self.name_ref =
148 find_node_at_offset(original_file.syntax(), name_ref.syntax().text_range().start());
149 let name_range = name_ref.syntax().text_range(); 145 let name_range = name_ref.syntax().text_range();
150 if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { 146 if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() {
151 self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); 147 self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset);