]> git.lizzy.rs Git - rust.git/commitdiff
Fix CompletionContext module field (by removing it)
authorFlorian Diebold <flodiebold@gmail.com>
Sat, 7 Mar 2020 16:53:22 +0000 (17:53 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Sat, 7 Mar 2020 16:53:22 +0000 (17:53 +0100)
Two uses only needed the crate; one was wrong and should use the module from the
scope instead.

crates/ra_ide/src/completion/complete_dot.rs
crates/ra_ide/src/completion/complete_path.rs
crates/ra_ide/src/completion/completion_context.rs

index da2c4c1ab28a47d39a7b6f775aacb08f34386354..00fd158de1b2651051c6f2fbd17acf599c81d76b 100644 (file)
@@ -38,7 +38,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
 fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
     for receiver in receiver.autoderef(ctx.db) {
         for (field, ty) in receiver.fields(ctx.db) {
-            if ctx.module.map_or(false, |m| !field.is_visible_from(ctx.db, m)) {
+            if ctx.scope().module().map_or(false, |m| !field.is_visible_from(ctx.db, m)) {
                 // Skip private field. FIXME: If the definition location of the
                 // field is editable, we should show the completion
                 continue;
@@ -53,7 +53,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Ty
 }
 
 fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
-    if let Some(krate) = ctx.module.map(|it| it.krate()) {
+    if let Some(krate) = ctx.krate {
         let mut seen_methods = FxHashSet::default();
         let traits_in_scope = ctx.scope().traits_in_scope();
         receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {
index 8c2a2898346526b90a9aed77d72007db2dd196d2..d43486d1a8c31138af0e75deacfb38aa5681774e 100644 (file)
@@ -47,7 +47,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
             };
             // Iterate assoc types separately
             // FIXME: complete T::AssocType
-            let krate = ctx.module.map(|m| m.krate());
+            let krate = ctx.krate;
             if let Some(krate) = krate {
                 let traits_in_scope = ctx.scope().traits_in_scope();
                 ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| {
index d173ef1f34412d9f3a794d9ac30be39bfc72ab3b..e7a8c78d008d2b35ee153ed51b7d854f65ca2f08 100644 (file)
@@ -24,7 +24,7 @@ pub(crate) struct CompletionContext<'a> {
     pub(super) original_token: SyntaxToken,
     /// The token before the cursor, in the macro-expanded file.
     pub(super) token: SyntaxToken,
-    pub(super) module: Option<hir::Module>,
+    pub(super) krate: Option<hir::Crate>,
     pub(super) name_ref_syntax: Option<ast::NameRef>,
     pub(super) function_syntax: Option<ast::FnDef>,
     pub(super) use_item_syntax: Option<ast::UseItem>,
@@ -73,8 +73,7 @@ pub(super) fn new(
         let fake_ident_token =
             file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
 
-        // TODO: shouldn't this take the position into account? (in case we're inside a mod {})
-        let module = sema.to_module_def(position.file_id);
+        let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
         let original_token =
             original_file.syntax().token_at_offset(position.offset).left_biased()?;
         let token = sema.descend_into_macros(original_token.clone());
@@ -84,7 +83,7 @@ pub(super) fn new(
             original_token,
             token,
             offset: position.offset,
-            module,
+            krate,
             name_ref_syntax: None,
             function_syntax: None,
             use_item_syntax: None,
@@ -132,7 +131,6 @@ pub(super) fn new(
                 if new_offset >= actual_expansion.text_range().end() {
                     break;
                 }
-                // TODO check that the expansions 'look the same' up to the inserted token?
                 original_file = actual_expansion;
                 hypothetical_file = hypothetical_expansion.0;
                 fake_ident_token = hypothetical_expansion.1;