mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Add basic HIR and types for structs/enums
This commit is contained in:
parent
5fb426cb9e
commit
b5b68f2094
9 changed files with 244 additions and 29 deletions
|
@ -25,6 +25,7 @@ pub mod source_binder;
|
|||
mod krate;
|
||||
mod module;
|
||||
mod function;
|
||||
mod adt;
|
||||
mod ty;
|
||||
|
||||
use std::ops::Index;
|
||||
|
@ -42,6 +43,7 @@ pub use self::{
|
|||
krate::Crate,
|
||||
module::{Module, ModuleId, Problem, nameres::ItemMap, ModuleScope, Resolution},
|
||||
function::{Function, FnScopes},
|
||||
adt::{Struct, Enum},
|
||||
};
|
||||
|
||||
pub use self::function::FnSignatureInfo;
|
||||
|
@ -56,6 +58,8 @@ ra_db::impl_numeric_id!(DefId);
|
|||
pub(crate) enum DefKind {
|
||||
Module,
|
||||
Function,
|
||||
Struct,
|
||||
Enum,
|
||||
Item,
|
||||
}
|
||||
|
||||
|
@ -73,8 +77,8 @@ impl DefKind {
|
|||
SyntaxKind::FN_DEF => Some(DefKind::Function),
|
||||
SyntaxKind::MODULE => Some(DefKind::Module),
|
||||
// These define items, but don't have their own DefKinds yet:
|
||||
SyntaxKind::STRUCT_DEF => Some(DefKind::Item),
|
||||
SyntaxKind::ENUM_DEF => Some(DefKind::Item),
|
||||
SyntaxKind::STRUCT_DEF => Some(DefKind::Struct),
|
||||
SyntaxKind::ENUM_DEF => Some(DefKind::Enum),
|
||||
SyntaxKind::TRAIT_DEF => Some(DefKind::Item),
|
||||
SyntaxKind::TYPE_DEF => Some(DefKind::Item),
|
||||
SyntaxKind::CONST_DEF => Some(DefKind::Item),
|
||||
|
@ -99,6 +103,8 @@ impl DefLoc {
|
|||
pub enum Def {
|
||||
Module(Module),
|
||||
Function(Function),
|
||||
Struct(Struct),
|
||||
Enum(Enum),
|
||||
Item,
|
||||
}
|
||||
|
||||
|
@ -114,6 +120,14 @@ impl DefId {
|
|||
let function = Function::new(self);
|
||||
Def::Function(function)
|
||||
}
|
||||
DefKind::Struct => {
|
||||
let struct_def = Struct::new(self);
|
||||
Def::Struct(struct_def)
|
||||
}
|
||||
DefKind::Enum => {
|
||||
let enum_def = Enum::new(self);
|
||||
Def::Enum(enum_def)
|
||||
}
|
||||
DefKind::Item => Def::Item,
|
||||
};
|
||||
Ok(res)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue