Add completion for type aliases
This commit is contained in:
parent
dd698fc3f7
commit
546442df68
2 changed files with 45 additions and 1 deletions
|
@ -849,6 +849,10 @@ impl TypeAlias {
|
|||
db.type_alias_data(self).type_ref.clone()
|
||||
}
|
||||
|
||||
pub fn ty(self, db: &impl HirDatabase) -> Ty {
|
||||
db.type_for_def(self.into(), Namespace::Types)
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||
db.type_alias_data(self).name.clone()
|
||||
}
|
||||
|
|
|
@ -37,7 +37,10 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def));
|
||||
}
|
||||
}
|
||||
hir::ModuleDef::Enum(_) | hir::ModuleDef::Struct(_) | hir::ModuleDef::Union(_) => {
|
||||
hir::ModuleDef::Enum(_)
|
||||
| hir::ModuleDef::Struct(_)
|
||||
| hir::ModuleDef::Union(_)
|
||||
| hir::ModuleDef::TypeAlias(_) => {
|
||||
if let hir::ModuleDef::Enum(e) = def {
|
||||
for variant in e.variants(ctx.db) {
|
||||
acc.add_enum_variant(ctx, variant);
|
||||
|
@ -47,6 +50,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
hir::ModuleDef::Enum(e) => e.ty(ctx.db),
|
||||
hir::ModuleDef::Struct(s) => s.ty(ctx.db),
|
||||
hir::ModuleDef::Union(u) => u.ty(ctx.db),
|
||||
hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let krate = ctx.module.and_then(|m| m.krate(ctx.db));
|
||||
|
@ -544,6 +548,42 @@ mod tests {
|
|||
insert: "bar",
|
||||
kind: Module,
|
||||
},
|
||||
]"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completes_type_alias() {
|
||||
assert_debug_snapshot_matches!(
|
||||
do_reference_completion(
|
||||
"
|
||||
struct S;
|
||||
impl S { fn foo() {} }
|
||||
type T = S;
|
||||
impl T { fn bar() {} }
|
||||
|
||||
fn main() {
|
||||
T::<|>;
|
||||
}
|
||||
"
|
||||
),
|
||||
@r###"[
|
||||
CompletionItem {
|
||||
label: "bar",
|
||||
source_range: [185; 185),
|
||||
delete: [185; 185),
|
||||
insert: "bar()$0",
|
||||
kind: Function,
|
||||
detail: "fn bar()",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "foo",
|
||||
source_range: [185; 185),
|
||||
delete: [185; 185),
|
||||
insert: "foo()$0",
|
||||
kind: Function,
|
||||
detail: "fn foo()",
|
||||
},
|
||||
]"###
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue