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.
This commit is contained in:
Florian Diebold 2020-03-07 17:53:22 +01:00
parent 020c00e44d
commit 941a574409
3 changed files with 6 additions and 8 deletions

View 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| {

View 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| {

View 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 @@ impl<'a> CompletionContext<'a> {
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 @@ impl<'a> CompletionContext<'a> {
original_token,
token,
offset: position.offset,
module,
krate,
name_ref_syntax: None,
function_syntax: None,
use_item_syntax: None,
@ -132,7 +131,6 @@ impl<'a> CompletionContext<'a> {
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;