Skip to content

Commit 941a574

Browse files
committed
Fix CompletionContext module field (by removing it)
Two uses only needed the crate; one was wrong and should use the module from the scope instead.
1 parent 020c00e commit 941a574

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

crates/ra_ide/src/completion/complete_dot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
3838
fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
3939
for receiver in receiver.autoderef(ctx.db) {
4040
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)) {
4242
// Skip private field. FIXME: If the definition location of the
4343
// field is editable, we should show the completion
4444
continue;
@@ -53,7 +53,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Ty
5353
}
5454

5555
fn 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 {
5757
let mut seen_methods = FxHashSet::default();
5858
let traits_in_scope = ctx.scope().traits_in_scope();
5959
receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {

crates/ra_ide/src/completion/complete_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
4747
};
4848
// Iterate assoc types separately
4949
// FIXME: complete T::AssocType
50-
let krate = ctx.module.map(|m| m.krate());
50+
let krate = ctx.krate;
5151
if let Some(krate) = krate {
5252
let traits_in_scope = ctx.scope().traits_in_scope();
5353
ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| {

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(crate) struct CompletionContext<'a> {
2424
pub(super) original_token: SyntaxToken,
2525
/// The token before the cursor, in the macro-expanded file.
2626
pub(super) token: SyntaxToken,
27-
pub(super) module: Option<hir::Module>,
27+
pub(super) krate: Option<hir::Crate>,
2828
pub(super) name_ref_syntax: Option<ast::NameRef>,
2929
pub(super) function_syntax: Option<ast::FnDef>,
3030
pub(super) use_item_syntax: Option<ast::UseItem>,
@@ -73,8 +73,7 @@ impl<'a> CompletionContext<'a> {
7373
let fake_ident_token =
7474
file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
7575

76-
// TODO: shouldn't this take the position into account? (in case we're inside a mod {})
77-
let module = sema.to_module_def(position.file_id);
76+
let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
7877
let original_token =
7978
original_file.syntax().token_at_offset(position.offset).left_biased()?;
8079
let token = sema.descend_into_macros(original_token.clone());
@@ -84,7 +83,7 @@ impl<'a> CompletionContext<'a> {
8483
original_token,
8584
token,
8685
offset: position.offset,
87-
module,
86+
krate,
8887
name_ref_syntax: None,
8988
function_syntax: None,
9089
use_item_syntax: None,
@@ -132,7 +131,6 @@ impl<'a> CompletionContext<'a> {
132131
if new_offset >= actual_expansion.text_range().end() {
133132
break;
134133
}
135-
// TODO check that the expansions 'look the same' up to the inserted token?
136134
original_file = actual_expansion;
137135
hypothetical_file = hypothetical_expansion.0;
138136
fake_ident_token = hypothetical_expansion.1;

0 commit comments

Comments
 (0)