aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/lib.rs')
-rw-r--r--crates/ra_hir/src/lib.rs20
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;
25mod krate; 25mod krate;
26mod module; 26mod module;
27mod function; 27mod function;
28mod ty;
28 29
29use std::ops::Index; 30use std::ops::Index;
30 31
31use ra_syntax::{SyntaxNodeRef, SyntaxNode}; 32use ra_syntax::{SyntaxNodeRef, SyntaxNode, SyntaxKind};
32use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable}; 33use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable};
33 34
34use crate::{ 35use crate::{
@@ -66,6 +67,23 @@ pub struct DefLoc {
66 source_item_id: SourceItemId, 67 source_item_id: SourceItemId,
67} 68}
68 69
70impl 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
69impl DefId { 87impl 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)