Skip to content

Commit

Permalink
Complete builtin type paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Feb 11, 2021
1 parent 216dc85 commit e938d76
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion crates/completion/src/completions/qualified_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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!(),
};

Expand Down Expand Up @@ -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(…) -> ()
"#]],
);
}
}

0 comments on commit e938d76

Please sign in to comment.