X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fide_completion%2Fsrc%2Fcompletions%2Frecord.rs;h=78d06231060d766dd78629e562792fcc6b23b51b;hb=24255e5b3dbabe7eaec1a42668d50d96d6b1aa0f;hp=d50f889ee47ad96b36f67ee9d8f7f18a9cbc4a6a;hpb=393cbd0982707a20b0ef40277385737f8de1833e;p=rust.git diff --git a/crates/ide_completion/src/completions/record.rs b/crates/ide_completion/src/completions/record.rs index d50f889ee47..78d06231060 100644 --- a/crates/ide_completion/src/completions/record.rs +++ b/crates/ide_completion/src/completions/record.rs @@ -1,9 +1,10 @@ //! Complete fields in record literals and patterns. -use ide_db::{helpers::FamousDefs, SymbolKind}; +use ide_db::SymbolKind; use syntax::{ast::Expr, T}; use crate::{ - patterns::ImmediateLocation, CompletionContext, CompletionItem, CompletionItemKind, Completions, + patterns::ImmediateLocation, CompletionContext, CompletionItem, CompletionItemKind, + CompletionRelevance, Completions, }; pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { @@ -13,7 +14,7 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> | ImmediateLocation::RecordExprUpdate(record_expr), ) => { let ty = ctx.sema.type_of_expr(&Expr::RecordExpr(record_expr.clone())); - let default_trait = FamousDefs(&ctx.sema, ctx.krate).core_default_Default(); + let default_trait = ctx.famous_defs().core_default_Default(); let impl_default_trait = default_trait.zip(ty).map_or(false, |(default_trait, ty)| { ty.original.impls_trait(ctx.db, default_trait, &[]) }); @@ -25,7 +26,10 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> CompletionItem::new(SymbolKind::Field, ctx.source_range(), completion_text); let completion_text = completion_text.strip_prefix(ctx.token.text()).unwrap_or(completion_text); - item.insert_text(completion_text); + item.insert_text(completion_text).set_relevance(CompletionRelevance { + exact_postfix_snippet_match: true, + ..Default::default() + }); item.add_to(acc); } if ctx.previous_token_is(T![.]) { @@ -59,12 +63,12 @@ pub(crate) fn complete_record_literal( } if let hir::Adt::Struct(strukt) = ctx.expected_type.as_ref()?.as_adt()? { - let module = - if let Some(module) = ctx.scope.module() { module } else { strukt.module(ctx.db) }; + if ctx.path_qual().is_none() { + let module = if let Some(module) = ctx.module { module } else { strukt.module(ctx.db) }; + let path = module.find_use_path(ctx.db, hir::ModuleDef::from(strukt)); - let path = module.find_use_path(ctx.db, hir::ModuleDef::from(strukt)); - - acc.add_struct_literal(ctx, strukt, path, None); + acc.add_struct_literal(ctx, strukt, path, None); + } } Some(())