aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model_api.rs48
-rw-r--r--crates/ra_hir/src/ids.rs32
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/ty.rs8
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs20
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs16
-rw-r--r--crates/ra_lsp_server/src/conv.rs4
7 files changed, 122 insertions, 8 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 5f61bb589..d4244f70c 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -41,12 +41,17 @@ impl Crate {
41 } 41 }
42} 42}
43 43
44#[derive(Debug)]
44pub enum Def { 45pub enum Def {
45 Module(Module), 46 Module(Module),
46 Struct(Struct), 47 Struct(Struct),
47 Enum(Enum), 48 Enum(Enum),
48 EnumVariant(EnumVariant), 49 EnumVariant(EnumVariant),
49 Function(Function), 50 Function(Function),
51 Const(Const),
52 Static(Static),
53 Trait(Trait),
54 Type(Type),
50 Item, 55 Item,
51} 56}
52 57
@@ -317,17 +322,60 @@ pub struct Const {
317 pub(crate) def_id: DefId, 322 pub(crate) def_id: DefId,
318} 323}
319 324
325impl Const {
326 pub(crate) fn new(def_id: DefId) -> Const {
327 Const { def_id }
328 }
329
330 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::ConstDef>)> {
331 Ok(def_id_to_ast(db, self.def_id))
332 }
333}
334
320#[derive(Debug, Clone, PartialEq, Eq, Hash)] 335#[derive(Debug, Clone, PartialEq, Eq, Hash)]
321pub struct Static { 336pub struct Static {
322 pub(crate) def_id: DefId, 337 pub(crate) def_id: DefId,
323} 338}
324 339
340impl Static {
341 pub(crate) fn new(def_id: DefId) -> Static {
342 Static { def_id }
343 }
344
345 pub fn source(
346 &self,
347 db: &impl HirDatabase,
348 ) -> Cancelable<(HirFileId, TreeArc<ast::StaticDef>)> {
349 Ok(def_id_to_ast(db, self.def_id))
350 }
351}
352
325#[derive(Debug, Clone, PartialEq, Eq, Hash)] 353#[derive(Debug, Clone, PartialEq, Eq, Hash)]
326pub struct Trait { 354pub struct Trait {
327 pub(crate) def_id: DefId, 355 pub(crate) def_id: DefId,
328} 356}
329 357
358impl Trait {
359 pub(crate) fn new(def_id: DefId) -> Trait {
360 Trait { def_id }
361 }
362
363 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TraitDef>)> {
364 Ok(def_id_to_ast(db, self.def_id))
365 }
366}
367
330#[derive(Debug, Clone, PartialEq, Eq, Hash)] 368#[derive(Debug, Clone, PartialEq, Eq, Hash)]
331pub struct Type { 369pub struct Type {
332 pub(crate) def_id: DefId, 370 pub(crate) def_id: DefId,
333} 371}
372
373impl Type {
374 pub(crate) fn new(def_id: DefId) -> Type {
375 Type { def_id }
376 }
377
378 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TypeDef>)> {
379 Ok(def_id_to_ast(db, self.def_id))
380 }
381}
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 0805fd3db..316896dce 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -4,11 +4,10 @@ use ra_arena::{Arena, RawId, impl_arena_id};
4 4
5use crate::{ 5use crate::{
6 HirDatabase, PerNs, Def, Function, Struct, Enum, EnumVariant, ImplBlock, Crate, 6 HirDatabase, PerNs, Def, Function, Struct, Enum, EnumVariant, ImplBlock, Crate,
7 Module, Trait, Type, Static, Const,
7 module_tree::ModuleId, 8 module_tree::ModuleId,
8}; 9};
9 10
10use crate::code_model_api::Module;
11
12/// hir makes heavy use of ids: integer (u32) handlers to various things. You 11/// hir makes heavy use of ids: integer (u32) handlers to various things. You
13/// can think of id as a pointer (but without a lifetime) or a file descriptor 12/// can think of id as a pointer (but without a lifetime) or a file descriptor
14/// (but for hir objects). 13/// (but for hir objects).
@@ -146,6 +145,10 @@ pub(crate) enum DefKind {
146 Struct, 145 Struct,
147 Enum, 146 Enum,
148 EnumVariant, 147 EnumVariant,
148 Const,
149 Static,
150 Trait,
151 Type,
149 Item, 152 Item,
150 153
151 StructCtor, 154 StructCtor,
@@ -173,6 +176,23 @@ impl DefId {
173 } 176 }
174 DefKind::Enum => Def::Enum(Enum::new(self)), 177 DefKind::Enum => Def::Enum(Enum::new(self)),
175 DefKind::EnumVariant => Def::EnumVariant(EnumVariant::new(self)), 178 DefKind::EnumVariant => Def::EnumVariant(EnumVariant::new(self)),
179 DefKind::Const => {
180 let def = Const::new(self);
181 Def::Const(def)
182 }
183 DefKind::Static => {
184 let def = Static::new(self);
185 Def::Static(def)
186 }
187 DefKind::Trait => {
188 let def = Trait::new(self);
189 Def::Trait(def)
190 }
191 DefKind::Type => {
192 let def = Type::new(self);
193 Def::Type(def)
194 }
195
176 DefKind::StructCtor => Def::Item, 196 DefKind::StructCtor => Def::Item,
177 DefKind::Item => Def::Item, 197 DefKind::Item => Def::Item,
178 }; 198 };
@@ -218,10 +238,10 @@ impl DefKind {
218 SyntaxKind::STRUCT_DEF => PerNs::both(DefKind::Struct, DefKind::StructCtor), 238 SyntaxKind::STRUCT_DEF => PerNs::both(DefKind::Struct, DefKind::StructCtor),
219 SyntaxKind::ENUM_DEF => PerNs::types(DefKind::Enum), 239 SyntaxKind::ENUM_DEF => PerNs::types(DefKind::Enum),
220 // These define items, but don't have their own DefKinds yet: 240 // These define items, but don't have their own DefKinds yet:
221 SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Item), 241 SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Trait),
222 SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Item), 242 SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Type),
223 SyntaxKind::CONST_DEF => PerNs::values(DefKind::Item), 243 SyntaxKind::CONST_DEF => PerNs::values(DefKind::Const),
224 SyntaxKind::STATIC_DEF => PerNs::values(DefKind::Item), 244 SyntaxKind::STATIC_DEF => PerNs::values(DefKind::Static),
225 _ => PerNs::none(), 245 _ => PerNs::none(),
226 } 246 }
227 } 247 }
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index fe8be5700..45dda4f7f 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -60,4 +60,6 @@ pub use self::code_model_api::{
60 Module, ModuleSource, Problem, 60 Module, ModuleSource, Problem,
61 Struct, Enum, EnumVariant, 61 Struct, Enum, EnumVariant,
62 Function, FnSignature, ScopeEntryWithSyntax, 62 Function, FnSignature, ScopeEntryWithSyntax,
63 Static, Const,
64 Trait, Type,
63}; 65};
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 18c41a015..0c24a0652 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -470,8 +470,12 @@ pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<T
470 Def::Struct(s) => type_for_struct(db, s), 470 Def::Struct(s) => type_for_struct(db, s),
471 Def::Enum(e) => type_for_enum(db, e), 471 Def::Enum(e) => type_for_enum(db, e),
472 Def::EnumVariant(ev) => type_for_enum_variant(db, ev), 472 Def::EnumVariant(ev) => type_for_enum_variant(db, ev),
473 Def::Item => { 473 _ => {
474 log::debug!("trying to get type for item of unknown type {:?}", def_id); 474 log::debug!(
475 "trying to get type for item of unknown type {:?} {:?}",
476 def_id,
477 def
478 );
475 Ok(Ty::Unknown) 479 Ok(Ty::Unknown)
476 } 480 }
477 } 481 }
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 6a9770429..e7fa967a0 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -33,6 +33,10 @@ pub enum CompletionItemKind {
33 EnumVariant, 33 EnumVariant,
34 Binding, 34 Binding,
35 Field, 35 Field,
36 Static,
37 Const,
38 Trait,
39 TypeAlias,
36} 40}
37 41
38#[derive(Debug, PartialEq, Eq)] 42#[derive(Debug, PartialEq, Eq)]
@@ -154,6 +158,22 @@ impl Builder {
154 .. 158 ..
155 } => CompletionItemKind::Enum, 159 } => CompletionItemKind::Enum,
156 PerNs { 160 PerNs {
161 types: Some(hir::Def::Trait(..)),
162 ..
163 } => CompletionItemKind::Trait,
164 PerNs {
165 types: Some(hir::Def::Type(..)),
166 ..
167 } => CompletionItemKind::TypeAlias,
168 PerNs {
169 values: Some(hir::Def::Const(..)),
170 ..
171 } => CompletionItemKind::Const,
172 PerNs {
173 values: Some(hir::Def::Static(..)),
174 ..
175 } => CompletionItemKind::Static,
176 PerNs {
157 values: Some(hir::Def::Function(function)), 177 values: Some(hir::Def::Function(function)),
158 .. 178 ..
159 } => return self.from_function(ctx, function), 179 } => return self.from_function(ctx, function),
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index b955bbe42..b0d0a3e8b 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -108,6 +108,22 @@ impl NavigationTarget {
108 let (file_id, node) = f.source(db)?; 108 let (file_id, node) = f.source(db)?;
109 NavigationTarget::from_named(file_id.original_file(db), &*node) 109 NavigationTarget::from_named(file_id.original_file(db), &*node)
110 } 110 }
111 Def::Trait(f) => {
112 let (file_id, node) = f.source(db)?;
113 NavigationTarget::from_named(file_id.original_file(db), &*node)
114 }
115 Def::Type(f) => {
116 let (file_id, node) = f.source(db)?;
117 NavigationTarget::from_named(file_id.original_file(db), &*node)
118 }
119 Def::Static(f) => {
120 let (file_id, node) = f.source(db)?;
121 NavigationTarget::from_named(file_id.original_file(db), &*node)
122 }
123 Def::Const(f) => {
124 let (file_id, node) = f.source(db)?;
125 NavigationTarget::from_named(file_id.original_file(db), &*node)
126 }
111 Def::Module(m) => NavigationTarget::from_module(db, m)?, 127 Def::Module(m) => NavigationTarget::from_module(db, m)?,
112 Def::Item => return Ok(None), 128 Def::Item => return Ok(None),
113 }; 129 };
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 76fa98cbe..7ca2f437d 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -65,6 +65,10 @@ impl Conv for CompletionItemKind {
65 CompletionItemKind::EnumVariant => EnumMember, 65 CompletionItemKind::EnumVariant => EnumMember,
66 CompletionItemKind::Binding => Variable, 66 CompletionItemKind::Binding => Variable,
67 CompletionItemKind::Field => Field, 67 CompletionItemKind::Field => Field,
68 CompletionItemKind::Trait => Interface,
69 CompletionItemKind::TypeAlias => Struct,
70 CompletionItemKind::Const => Constant,
71 CompletionItemKind::Static => Value,
68 } 72 }
69 } 73 }
70} 74}