diff options
Diffstat (limited to 'crates/ra_hir/src/lib.rs')
-rw-r--r-- | crates/ra_hir/src/lib.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index f56214b47..a0d99a84d 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -25,10 +25,11 @@ pub mod source_binder; | |||
25 | mod krate; | 25 | mod krate; |
26 | mod module; | 26 | mod module; |
27 | mod function; | 27 | mod function; |
28 | mod ty; | ||
28 | 29 | ||
29 | use std::ops::Index; | 30 | use std::ops::Index; |
30 | 31 | ||
31 | use ra_syntax::{SyntaxNodeRef, SyntaxNode}; | 32 | use ra_syntax::{SyntaxNodeRef, SyntaxNode, SyntaxKind}; |
32 | use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable}; | 33 | use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable}; |
33 | 34 | ||
34 | use crate::{ | 35 | use crate::{ |
@@ -66,6 +67,23 @@ pub struct DefLoc { | |||
66 | source_item_id: SourceItemId, | 67 | source_item_id: SourceItemId, |
67 | } | 68 | } |
68 | 69 | ||
70 | impl DefKind { | ||
71 | pub(crate) fn for_syntax_kind(kind: SyntaxKind) -> Option<DefKind> { | ||
72 | match kind { | ||
73 | SyntaxKind::FN_DEF => Some(DefKind::Function), | ||
74 | SyntaxKind::MODULE => Some(DefKind::Module), | ||
75 | // These define items, but don't have their own DefKinds yet: | ||
76 | SyntaxKind::STRUCT_DEF => Some(DefKind::Item), | ||
77 | SyntaxKind::ENUM_DEF => Some(DefKind::Item), | ||
78 | SyntaxKind::TRAIT_DEF => Some(DefKind::Item), | ||
79 | SyntaxKind::TYPE_DEF => Some(DefKind::Item), | ||
80 | SyntaxKind::CONST_DEF => Some(DefKind::Item), | ||
81 | SyntaxKind::STATIC_DEF => Some(DefKind::Item), | ||
82 | _ => None, | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
69 | impl DefId { | 87 | impl DefId { |
70 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { | 88 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { |
71 | db.as_ref().id2loc(self) | 89 | db.as_ref().id2loc(self) |