mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-15 13:36:49 +00:00
actually produce missing def kinds
This commit is contained in:
parent
19136cde00
commit
f193fbcbae
@ -41,12 +41,17 @@ impl Crate {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Def {
|
||||
Module(Module),
|
||||
Struct(Struct),
|
||||
Enum(Enum),
|
||||
EnumVariant(EnumVariant),
|
||||
Function(Function),
|
||||
Const(Const),
|
||||
Static(Static),
|
||||
Trait(Trait),
|
||||
Type(Type),
|
||||
Item,
|
||||
}
|
||||
|
||||
@ -317,17 +322,60 @@ pub struct Const {
|
||||
pub(crate) def_id: DefId,
|
||||
}
|
||||
|
||||
impl Const {
|
||||
pub(crate) fn new(def_id: DefId) -> Const {
|
||||
Const { def_id }
|
||||
}
|
||||
|
||||
pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::ConstDef>)> {
|
||||
Ok(def_id_to_ast(db, self.def_id))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Static {
|
||||
pub(crate) def_id: DefId,
|
||||
}
|
||||
|
||||
impl Static {
|
||||
pub(crate) fn new(def_id: DefId) -> Static {
|
||||
Static { def_id }
|
||||
}
|
||||
|
||||
pub fn source(
|
||||
&self,
|
||||
db: &impl HirDatabase,
|
||||
) -> Cancelable<(HirFileId, TreeArc<ast::StaticDef>)> {
|
||||
Ok(def_id_to_ast(db, self.def_id))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Trait {
|
||||
pub(crate) def_id: DefId,
|
||||
}
|
||||
|
||||
impl Trait {
|
||||
pub(crate) fn new(def_id: DefId) -> Trait {
|
||||
Trait { def_id }
|
||||
}
|
||||
|
||||
pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TraitDef>)> {
|
||||
Ok(def_id_to_ast(db, self.def_id))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Type {
|
||||
pub(crate) def_id: DefId,
|
||||
}
|
||||
|
||||
impl Type {
|
||||
pub(crate) fn new(def_id: DefId) -> Type {
|
||||
Type { def_id }
|
||||
}
|
||||
|
||||
pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TypeDef>)> {
|
||||
Ok(def_id_to_ast(db, self.def_id))
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,10 @@ use ra_arena::{Arena, RawId, impl_arena_id};
|
||||
|
||||
use crate::{
|
||||
HirDatabase, PerNs, Def, Function, Struct, Enum, EnumVariant, ImplBlock, Crate,
|
||||
Module, Trait, Type, Static, Const,
|
||||
module_tree::ModuleId,
|
||||
};
|
||||
|
||||
use crate::code_model_api::Module;
|
||||
|
||||
/// hir makes heavy use of ids: integer (u32) handlers to various things. You
|
||||
/// can think of id as a pointer (but without a lifetime) or a file descriptor
|
||||
/// (but for hir objects).
|
||||
@ -146,6 +145,10 @@ pub(crate) enum DefKind {
|
||||
Struct,
|
||||
Enum,
|
||||
EnumVariant,
|
||||
Const,
|
||||
Static,
|
||||
Trait,
|
||||
Type,
|
||||
Item,
|
||||
|
||||
StructCtor,
|
||||
@ -173,6 +176,23 @@ impl DefId {
|
||||
}
|
||||
DefKind::Enum => Def::Enum(Enum::new(self)),
|
||||
DefKind::EnumVariant => Def::EnumVariant(EnumVariant::new(self)),
|
||||
DefKind::Const => {
|
||||
let def = Const::new(self);
|
||||
Def::Const(def)
|
||||
}
|
||||
DefKind::Static => {
|
||||
let def = Static::new(self);
|
||||
Def::Static(def)
|
||||
}
|
||||
DefKind::Trait => {
|
||||
let def = Trait::new(self);
|
||||
Def::Trait(def)
|
||||
}
|
||||
DefKind::Type => {
|
||||
let def = Type::new(self);
|
||||
Def::Type(def)
|
||||
}
|
||||
|
||||
DefKind::StructCtor => Def::Item,
|
||||
DefKind::Item => Def::Item,
|
||||
};
|
||||
@ -218,10 +238,10 @@ impl DefKind {
|
||||
SyntaxKind::STRUCT_DEF => PerNs::both(DefKind::Struct, DefKind::StructCtor),
|
||||
SyntaxKind::ENUM_DEF => PerNs::types(DefKind::Enum),
|
||||
// These define items, but don't have their own DefKinds yet:
|
||||
SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Item),
|
||||
SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Item),
|
||||
SyntaxKind::CONST_DEF => PerNs::values(DefKind::Item),
|
||||
SyntaxKind::STATIC_DEF => PerNs::values(DefKind::Item),
|
||||
SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Trait),
|
||||
SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Type),
|
||||
SyntaxKind::CONST_DEF => PerNs::values(DefKind::Const),
|
||||
SyntaxKind::STATIC_DEF => PerNs::values(DefKind::Static),
|
||||
_ => PerNs::none(),
|
||||
}
|
||||
}
|
||||
|
@ -60,4 +60,6 @@ pub use self::code_model_api::{
|
||||
Module, ModuleSource, Problem,
|
||||
Struct, Enum, EnumVariant,
|
||||
Function, FnSignature, ScopeEntryWithSyntax,
|
||||
Static, Const,
|
||||
Trait, Type,
|
||||
};
|
||||
|
@ -470,8 +470,12 @@ pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<T
|
||||
Def::Struct(s) => type_for_struct(db, s),
|
||||
Def::Enum(e) => type_for_enum(db, e),
|
||||
Def::EnumVariant(ev) => type_for_enum_variant(db, ev),
|
||||
Def::Item => {
|
||||
log::debug!("trying to get type for item of unknown type {:?}", def_id);
|
||||
_ => {
|
||||
log::debug!(
|
||||
"trying to get type for item of unknown type {:?} {:?}",
|
||||
def_id,
|
||||
def
|
||||
);
|
||||
Ok(Ty::Unknown)
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ pub enum CompletionItemKind {
|
||||
EnumVariant,
|
||||
Binding,
|
||||
Field,
|
||||
Static,
|
||||
Const,
|
||||
Trait,
|
||||
TypeAlias,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@ -153,6 +157,22 @@ impl Builder {
|
||||
types: Some(hir::Def::Enum(..)),
|
||||
..
|
||||
} => CompletionItemKind::Enum,
|
||||
PerNs {
|
||||
types: Some(hir::Def::Trait(..)),
|
||||
..
|
||||
} => CompletionItemKind::Trait,
|
||||
PerNs {
|
||||
types: Some(hir::Def::Type(..)),
|
||||
..
|
||||
} => CompletionItemKind::TypeAlias,
|
||||
PerNs {
|
||||
values: Some(hir::Def::Const(..)),
|
||||
..
|
||||
} => CompletionItemKind::Const,
|
||||
PerNs {
|
||||
values: Some(hir::Def::Static(..)),
|
||||
..
|
||||
} => CompletionItemKind::Static,
|
||||
PerNs {
|
||||
values: Some(hir::Def::Function(function)),
|
||||
..
|
||||
|
@ -108,6 +108,22 @@ impl NavigationTarget {
|
||||
let (file_id, node) = f.source(db)?;
|
||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
||||
}
|
||||
Def::Trait(f) => {
|
||||
let (file_id, node) = f.source(db)?;
|
||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
||||
}
|
||||
Def::Type(f) => {
|
||||
let (file_id, node) = f.source(db)?;
|
||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
||||
}
|
||||
Def::Static(f) => {
|
||||
let (file_id, node) = f.source(db)?;
|
||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
||||
}
|
||||
Def::Const(f) => {
|
||||
let (file_id, node) = f.source(db)?;
|
||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
||||
}
|
||||
Def::Module(m) => NavigationTarget::from_module(db, m)?,
|
||||
Def::Item => return Ok(None),
|
||||
};
|
||||
|
@ -65,6 +65,10 @@ impl Conv for CompletionItemKind {
|
||||
CompletionItemKind::EnumVariant => EnumMember,
|
||||
CompletionItemKind::Binding => Variable,
|
||||
CompletionItemKind::Field => Field,
|
||||
CompletionItemKind::Trait => Interface,
|
||||
CompletionItemKind::TypeAlias => Struct,
|
||||
CompletionItemKind::Const => Constant,
|
||||
CompletionItemKind::Static => Value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user