Two uses only needed the crate; one was wrong and should use the module from the
scope instead.
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;
}
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| {
};
// 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| {
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>,
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());
original_token,
token,
offset: position.offset,
- module,
+ krate,
name_ref_syntax: None,
function_syntax: None,
use_item_syntax: None,
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;