aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs36
1 files changed, 30 insertions, 6 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 3fab7965c..a240a10b8 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -13,6 +13,7 @@ pub mod path;
13pub mod type_ref; 13pub mod type_ref;
14pub mod builtin_type; 14pub mod builtin_type;
15pub mod adt; 15pub mod adt;
16pub mod imp;
16pub mod diagnostics; 17pub mod diagnostics;
17pub mod expr; 18pub mod expr;
18pub mod body; 19pub mod body;
@@ -77,14 +78,13 @@ impl ModuleSource {
77 } 78 }
78 } 79 }
79 80
80 pub fn from_child_node( 81 pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource {
81 db: &impl db::DefDatabase2, 82 if let Some(m) =
82 file_id: FileId, 83 child.ast.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi())
83 child: &SyntaxNode, 84 {
84 ) -> ModuleSource {
85 if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) {
86 ModuleSource::Module(m) 85 ModuleSource::Module(m)
87 } else { 86 } else {
87 let file_id = child.file_id.original_file(db);
88 let source_file = db.parse(file_id).tree(); 88 let source_file = db.parse(file_id).tree();
89 ModuleSource::SourceFile(source_file) 89 ModuleSource::SourceFile(source_file)
90 } 90 }
@@ -321,6 +321,18 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
321 } 321 }
322} 322}
323 323
324#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
325pub struct ImplId(salsa::InternId);
326impl_intern_key!(ImplId);
327impl AstItemDef<ast::ImplBlock> for ImplId {
328 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::ImplBlock>) -> Self {
329 db.intern_impl(loc)
330 }
331 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::ImplBlock> {
332 db.lookup_intern_impl(self)
333 }
334}
335
324macro_rules! impl_froms { 336macro_rules! impl_froms {
325 ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { 337 ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
326 $( 338 $(
@@ -384,3 +396,15 @@ pub enum DefWithBodyId {
384} 396}
385 397
386impl_froms!(DefWithBodyId: FunctionId, ConstId, StaticId); 398impl_froms!(DefWithBodyId: FunctionId, ConstId, StaticId);
399
400#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
401pub enum AssocItemId {
402 FunctionId(FunctionId),
403 ConstId(ConstId),
404 TypeAliasId(TypeAliasId),
405}
406// FIXME: not every function, ... is actually an assoc item. maybe we should make
407// sure that you can only turn actual assoc items into AssocItemIds. This would
408// require not implementing From, and instead having some checked way of
409// casting them, and somehow making the constructors private, which would be annoying.
410impl_froms!(AssocItemId: FunctionId, ConstId, TypeAliasId);