mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
adapt ide_api to the new API
This commit is contained in:
parent
ce2041252a
commit
aea1f95a66
4 changed files with 46 additions and 47 deletions
|
@ -1,4 +1,4 @@
|
||||||
use hir::{Ty, Def, AdtDef};
|
use hir::{Ty, AdtDef};
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
|
use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
|
||||||
use crate::completion::completion_item::CompletionKind;
|
use crate::completion::completion_item::CompletionKind;
|
||||||
|
@ -29,23 +29,21 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
|
||||||
def_id, ref substs, ..
|
def_id, ref substs, ..
|
||||||
} => {
|
} => {
|
||||||
match def_id {
|
match def_id {
|
||||||
AdtDef::Struct() => {}
|
AdtDef::Struct(s) => {
|
||||||
AdtDef::Def(def_id) => match def_id.resolve(ctx.db) {
|
for field in s.fields(ctx.db) {
|
||||||
Def::Struct(s) => {
|
CompletionItem::new(
|
||||||
for field in s.fields(ctx.db) {
|
CompletionKind::Reference,
|
||||||
CompletionItem::new(
|
ctx.source_range(),
|
||||||
CompletionKind::Reference,
|
field.name().to_string(),
|
||||||
ctx.source_range(),
|
)
|
||||||
field.name().to_string(),
|
.kind(CompletionItemKind::Field)
|
||||||
)
|
.set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string()))
|
||||||
.kind(CompletionItemKind::Field)
|
.add_to(acc);
|
||||||
.set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string()))
|
|
||||||
.add_to(acc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO unions
|
}
|
||||||
_ => {}
|
|
||||||
},
|
// TODO unions
|
||||||
|
AdtDef::Enum(_) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ty::Tuple(fields) => {
|
Ty::Tuple(fields) => {
|
||||||
|
|
|
@ -26,26 +26,21 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hir::ModuleDef::Enum(e) => {
|
||||||
hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) {
|
e.variants(ctx.db)
|
||||||
hir::Def::Enum(e) => {
|
.into_iter()
|
||||||
e.variants(ctx.db)
|
.for_each(|(variant_name, variant)| {
|
||||||
.into_iter()
|
CompletionItem::new(
|
||||||
.for_each(|(variant_name, variant)| {
|
CompletionKind::Reference,
|
||||||
CompletionItem::new(
|
ctx.source_range(),
|
||||||
CompletionKind::Reference,
|
variant_name.to_string(),
|
||||||
ctx.source_range(),
|
)
|
||||||
variant_name.to_string(),
|
.kind(CompletionItemKind::EnumVariant)
|
||||||
)
|
.set_documentation(variant.docs(ctx.db))
|
||||||
.kind(CompletionItemKind::EnumVariant)
|
.add_to(acc)
|
||||||
.set_documentation(variant.docs(ctx.db))
|
});
|
||||||
.add_to(acc)
|
}
|
||||||
});
|
hir::ModuleDef::Function(_) | hir::ModuleDef::Struct(_) | hir::ModuleDef::Def(_) => return,
|
||||||
}
|
|
||||||
_ => return,
|
|
||||||
},
|
|
||||||
|
|
||||||
hir::ModuleDef::Function(_) => return,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,9 +220,9 @@ impl Builder {
|
||||||
let (kind, docs) = match def {
|
let (kind, docs) = match def {
|
||||||
hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None),
|
hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None),
|
||||||
hir::ModuleDef::Function(func) => return self.from_function(ctx, func),
|
hir::ModuleDef::Function(func) => return self.from_function(ctx, func),
|
||||||
|
hir::ModuleDef::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
|
||||||
|
hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),
|
||||||
hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) {
|
hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) {
|
||||||
hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
|
|
||||||
hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),
|
|
||||||
hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)),
|
hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)),
|
||||||
hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
|
hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
|
||||||
hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)),
|
hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)),
|
||||||
|
|
|
@ -114,17 +114,23 @@ impl NavigationTarget {
|
||||||
hir::ModuleDef::Function(func) => {
|
hir::ModuleDef::Function(func) => {
|
||||||
return Some(NavigationTarget::from_function(db, func));
|
return Some(NavigationTarget::from_function(db, func));
|
||||||
}
|
}
|
||||||
|
hir::ModuleDef::Struct(s) => {
|
||||||
|
let (file_id, node) = s.source(db);
|
||||||
|
return Some(NavigationTarget::from_named(
|
||||||
|
file_id.original_file(db),
|
||||||
|
&*node,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
hir::ModuleDef::Enum(e) => {
|
||||||
|
let (file_id, node) = e.source(db);
|
||||||
|
return Some(NavigationTarget::from_named(
|
||||||
|
file_id.original_file(db),
|
||||||
|
&*node,
|
||||||
|
));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = match def {
|
let res = match def {
|
||||||
Def::Struct(s) => {
|
|
||||||
let (file_id, node) = s.source(db);
|
|
||||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
|
||||||
}
|
|
||||||
Def::Enum(e) => {
|
|
||||||
let (file_id, node) = e.source(db);
|
|
||||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
|
||||||
}
|
|
||||||
Def::EnumVariant(ev) => {
|
Def::EnumVariant(ev) => {
|
||||||
let (file_id, node) = ev.source(db);
|
let (file_id, node) = ev.source(db);
|
||||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue