diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/db.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 |
3 files changed, 8 insertions, 5 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 6eb916149..492814cbb 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -4,7 +4,7 @@ use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; | |||
4 | use ra_db::{SourceDatabase, salsa}; | 4 | use ra_db::{SourceDatabase, salsa}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | HirFileId, SourceFileItems, SourceItemId, Crate, Module, HirInterner, | 7 | HirFileId, MacroDefId, SourceFileItems, SourceItemId, Crate, Module, HirInterner, |
8 | Function, FnSignature, ExprScopes, TypeAlias, | 8 | Function, FnSignature, ExprScopes, TypeAlias, |
9 | Struct, Enum, StructField, | 9 | Struct, Enum, StructField, |
10 | Const, ConstSignature, Static, | 10 | Const, ConstSignature, Static, |
@@ -19,6 +19,9 @@ use crate::{ | |||
19 | 19 | ||
20 | #[salsa::query_group(DefDatabaseStorage)] | 20 | #[salsa::query_group(DefDatabaseStorage)] |
21 | pub trait DefDatabase: SourceDatabase + AsRef<HirInterner> { | 21 | pub trait DefDatabase: SourceDatabase + AsRef<HirInterner> { |
22 | #[salsa::invoke(crate::ids::macro_def_query)] | ||
23 | fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; | ||
24 | |||
22 | #[salsa::invoke(HirFileId::hir_parse)] | 25 | #[salsa::invoke(HirFileId::hir_parse)] |
23 | fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>; | 26 | fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>; |
24 | 27 | ||
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index cf0566308..bac7b9e46 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -101,7 +101,7 @@ fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option<Tree | |||
101 | let macro_call = ast::MacroCall::cast(&syntax).unwrap(); | 101 | let macro_call = ast::MacroCall::cast(&syntax).unwrap(); |
102 | let (macro_arg, _) = macro_call.token_tree().and_then(mbe::ast_to_token_tree)?; | 102 | let (macro_arg, _) = macro_call.token_tree().and_then(mbe::ast_to_token_tree)?; |
103 | 103 | ||
104 | let macro_rules = macro_def_query(db, loc.def)?; | 104 | let macro_rules = db.macro_def(loc.def)?; |
105 | let tt = macro_rules.expand(¯o_arg).ok()?; | 105 | let tt = macro_rules.expand(¯o_arg).ok()?; |
106 | Some(mbe::token_tree_to_ast_item_list(&tt)) | 106 | Some(mbe::token_tree_to_ast_item_list(&tt)) |
107 | } | 107 | } |
@@ -125,11 +125,11 @@ impl From<MacroCallId> for HirFileId { | |||
125 | } | 125 | } |
126 | 126 | ||
127 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 127 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
128 | pub(crate) enum MacroDefId { | 128 | pub enum MacroDefId { |
129 | MacroByExample { source_item_id: SourceItemId }, | 129 | MacroByExample { source_item_id: SourceItemId }, |
130 | } | 130 | } |
131 | 131 | ||
132 | fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { | 132 | pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { |
133 | let syntax_node = match id { | 133 | let syntax_node = match id { |
134 | MacroDefId::MacroByExample { source_item_id } => db.file_item(source_item_id), | 134 | MacroDefId::MacroByExample { source_item_id } => db.file_item(source_item_id), |
135 | }; | 135 | }; |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 974ebd831..87bc8009d 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -53,7 +53,7 @@ use crate::{ | |||
53 | pub use self::{ | 53 | pub use self::{ |
54 | path::{Path, PathKind}, | 54 | path::{Path, PathKind}, |
55 | name::Name, | 55 | name::Name, |
56 | ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner}, | 56 | ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc, HirInterner}, |
57 | nameres::{PerNs, Namespace}, | 57 | nameres::{PerNs, Namespace}, |
58 | ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay}, | 58 | ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay}, |
59 | impl_block::{ImplBlock, ImplItem}, | 59 | impl_block::{ImplBlock, ImplItem}, |