From e938d769d922feb374967d5b695e3b3baa70a566 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 11 Feb 2021 19:52:46 +0100 Subject: Complete builtin type paths --- .../completion/src/completions/qualified_path.rs | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions/qualified_path.rs b/crates/completion/src/completions/qualified_path.rs index bbeaab496..2afa6979e 100644 --- a/crates/completion/src/completions/qualified_path.rs +++ b/crates/completion/src/completions/qualified_path.rs @@ -50,7 +50,8 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon } } PathResolution::Def(def @ hir::ModuleDef::Adt(_)) - | PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_)) => { + | PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_)) + | PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => { if let hir::ModuleDef::Adt(Adt::Enum(e)) = def { for variant in e.variants(ctx.db) { acc.add_enum_variant(ctx, variant, None); @@ -59,6 +60,13 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon let ty = match def { hir::ModuleDef::Adt(adt) => adt.ty(ctx.db), hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), + hir::ModuleDef::BuiltinType(builtin) => { + let module = match ctx.scope.module() { + Some(it) => it, + None => return, + }; + builtin.ty(ctx.db, module) + } _ => unreachable!(), }; @@ -780,4 +788,28 @@ impl Foo { "#]], ); } + + #[test] + fn completes_primitive_assoc_const() { + check( + r#" +//- /lib.rs crate:lib deps:core +fn f() { + u8::$0 +} + +//- /core.rs crate:core +#[lang = "u8"] +impl u8 { + pub const MAX: Self = 255; + + pub fn func(self) {} +} +"#, + expect![[r#" + ct MAX pub const MAX: Self = 255; + me func(…) -> () + "#]], + ); + } } -- cgit v1.2.3