mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Complete builtin type paths
This commit is contained in:
parent
216dc856c5
commit
e938d769d9
1 changed files with 33 additions and 1 deletions
|
@ -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::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 {
|
if let hir::ModuleDef::Adt(Adt::Enum(e)) = def {
|
||||||
for variant in e.variants(ctx.db) {
|
for variant in e.variants(ctx.db) {
|
||||||
acc.add_enum_variant(ctx, variant, None);
|
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 {
|
let ty = match def {
|
||||||
hir::ModuleDef::Adt(adt) => adt.ty(ctx.db),
|
hir::ModuleDef::Adt(adt) => adt.ty(ctx.db),
|
||||||
hir::ModuleDef::TypeAlias(a) => a.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!(),
|
_ => 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(…) -> ()
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue