aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/complete_dot.rs4
-rw-r--r--crates/ra_ide/src/completion/complete_path.rs2
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs8
3 files changed, 6 insertions, 8 deletions
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs
index da2c4c1ab..00fd158de 100644
--- a/crates/ra_ide/src/completion/complete_dot.rs
+++ b/crates/ra_ide/src/completion/complete_dot.rs
@@ -38,7 +38,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
38fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) { 38fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
39 for receiver in receiver.autoderef(ctx.db) { 39 for receiver in receiver.autoderef(ctx.db) {
40 for (field, ty) in receiver.fields(ctx.db) { 40 for (field, ty) in receiver.fields(ctx.db) {
41 if ctx.module.map_or(false, |m| !field.is_visible_from(ctx.db, m)) { 41 if ctx.scope().module().map_or(false, |m| !field.is_visible_from(ctx.db, m)) {
42 // Skip private field. FIXME: If the definition location of the 42 // Skip private field. FIXME: If the definition location of the
43 // field is editable, we should show the completion 43 // field is editable, we should show the completion
44 continue; 44 continue;
@@ -53,7 +53,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Ty
53} 53}
54 54
55fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) { 55fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
56 if let Some(krate) = ctx.module.map(|it| it.krate()) { 56 if let Some(krate) = ctx.krate {
57 let mut seen_methods = FxHashSet::default(); 57 let mut seen_methods = FxHashSet::default();
58 let traits_in_scope = ctx.scope().traits_in_scope(); 58 let traits_in_scope = ctx.scope().traits_in_scope();
59 receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| { 59 receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs
index 8c2a28983..d43486d1a 100644
--- a/crates/ra_ide/src/completion/complete_path.rs
+++ b/crates/ra_ide/src/completion/complete_path.rs
@@ -47,7 +47,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
47 }; 47 };
48 // Iterate assoc types separately 48 // Iterate assoc types separately
49 // FIXME: complete T::AssocType 49 // FIXME: complete T::AssocType
50 let krate = ctx.module.map(|m| m.krate()); 50 let krate = ctx.krate;
51 if let Some(krate) = krate { 51 if let Some(krate) = krate {
52 let traits_in_scope = ctx.scope().traits_in_scope(); 52 let traits_in_scope = ctx.scope().traits_in_scope();
53 ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| { 53 ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| {
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index d173ef1f3..e7a8c78d0 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -24,7 +24,7 @@ pub(crate) struct CompletionContext<'a> {
24 pub(super) original_token: SyntaxToken, 24 pub(super) original_token: SyntaxToken,
25 /// The token before the cursor, in the macro-expanded file. 25 /// The token before the cursor, in the macro-expanded file.
26 pub(super) token: SyntaxToken, 26 pub(super) token: SyntaxToken,
27 pub(super) module: Option<hir::Module>, 27 pub(super) krate: Option<hir::Crate>,
28 pub(super) name_ref_syntax: Option<ast::NameRef>, 28 pub(super) name_ref_syntax: Option<ast::NameRef>,
29 pub(super) function_syntax: Option<ast::FnDef>, 29 pub(super) function_syntax: Option<ast::FnDef>,
30 pub(super) use_item_syntax: Option<ast::UseItem>, 30 pub(super) use_item_syntax: Option<ast::UseItem>,
@@ -73,8 +73,7 @@ impl<'a> CompletionContext<'a> {
73 let fake_ident_token = 73 let fake_ident_token =
74 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap(); 74 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
75 75
76 // TODO: shouldn't this take the position into account? (in case we're inside a mod {}) 76 let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
77 let module = sema.to_module_def(position.file_id);
78 let original_token = 77 let original_token =
79 original_file.syntax().token_at_offset(position.offset).left_biased()?; 78 original_file.syntax().token_at_offset(position.offset).left_biased()?;
80 let token = sema.descend_into_macros(original_token.clone()); 79 let token = sema.descend_into_macros(original_token.clone());
@@ -84,7 +83,7 @@ impl<'a> CompletionContext<'a> {
84 original_token, 83 original_token,
85 token, 84 token,
86 offset: position.offset, 85 offset: position.offset,
87 module, 86 krate,
88 name_ref_syntax: None, 87 name_ref_syntax: None,
89 function_syntax: None, 88 function_syntax: None,
90 use_item_syntax: None, 89 use_item_syntax: None,
@@ -132,7 +131,6 @@ impl<'a> CompletionContext<'a> {
132 if new_offset >= actual_expansion.text_range().end() { 131 if new_offset >= actual_expansion.text_range().end() {
133 break; 132 break;
134 } 133 }
135 // TODO check that the expansions 'look the same' up to the inserted token?
136 original_file = actual_expansion; 134 original_file = actual_expansion;
137 hypothetical_file = hypothetical_expansion.0; 135 hypothetical_file = hypothetical_expansion.0;
138 fake_ident_token = hypothetical_expansion.1; 136 fake_ident_token = hypothetical_expansion.1;