diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index e73dd5d21..b503e0ee5 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -10,7 +10,7 @@ use ra_arena::{RawId, ArenaId, impl_arena_id}; | |||
10 | use mbe::MacroRules; | 10 | use mbe::MacroRules; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | Module, DefDatabase, SourceItemId, SourceFileItemId, | 13 | Module, DefDatabase, SourceItemId, SourceFileItemId, AstId, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | #[derive(Debug, Default)] | 16 | #[derive(Debug, Default)] |
@@ -68,7 +68,7 @@ impl HirFileId { | |||
68 | HirFileIdRepr::File(file_id) => file_id, | 68 | HirFileIdRepr::File(file_id) => file_id, |
69 | HirFileIdRepr::Macro(macro_call_id) => { | 69 | HirFileIdRepr::Macro(macro_call_id) => { |
70 | let loc = macro_call_id.loc(db); | 70 | let loc = macro_call_id.loc(db); |
71 | loc.source_item_id.file_id.original_file(db) | 71 | loc.ast_id.file_id().original_file(db) |
72 | } | 72 | } |
73 | } | 73 | } |
74 | } | 74 | } |
@@ -96,8 +96,7 @@ impl HirFileId { | |||
96 | 96 | ||
97 | fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option<TreeArc<SourceFile>> { | 97 | fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option<TreeArc<SourceFile>> { |
98 | let loc = macro_call_id.loc(db); | 98 | let loc = macro_call_id.loc(db); |
99 | let syntax = db.file_item(loc.source_item_id); | 99 | let macro_call = loc.ast_id.to_node(db); |
100 | let macro_call = ast::MacroCall::cast(&syntax).unwrap(); | ||
101 | let (macro_arg, _) = macro_call.token_tree().and_then(mbe::ast_to_token_tree)?; | 100 | let (macro_arg, _) = macro_call.token_tree().and_then(mbe::ast_to_token_tree)?; |
102 | 101 | ||
103 | let macro_rules = db.macro_def(loc.def)?; | 102 | let macro_rules = db.macro_def(loc.def)?; |
@@ -124,15 +123,10 @@ impl From<MacroCallId> for HirFileId { | |||
124 | } | 123 | } |
125 | 124 | ||
126 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 125 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
127 | pub enum MacroDefId { | 126 | pub struct MacroDefId(pub(crate) AstId<ast::MacroCall>); |
128 | MacroByExample { source_item_id: SourceItemId }, | ||
129 | } | ||
130 | 127 | ||
131 | pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { | 128 | pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { |
132 | let syntax_node = match id { | 129 | let macro_call = id.0.to_node(db); |
133 | MacroDefId::MacroByExample { source_item_id } => db.file_item(source_item_id), | ||
134 | }; | ||
135 | let macro_call = ast::MacroCall::cast(&syntax_node).unwrap(); | ||
136 | let arg = macro_call.token_tree()?; | 130 | let arg = macro_call.token_tree()?; |
137 | let (tt, _) = mbe::ast_to_token_tree(arg)?; | 131 | let (tt, _) = mbe::ast_to_token_tree(arg)?; |
138 | let rules = MacroRules::parse(&tt).ok()?; | 132 | let rules = MacroRules::parse(&tt).ok()?; |
@@ -148,7 +142,7 @@ impl_arena_id!(MacroCallId); | |||
148 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 142 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
149 | pub struct MacroCallLoc { | 143 | pub struct MacroCallLoc { |
150 | pub(crate) def: MacroDefId, | 144 | pub(crate) def: MacroDefId, |
151 | pub(crate) source_item_id: SourceItemId, | 145 | pub(crate) ast_id: AstId<ast::MacroCall>, |
152 | } | 146 | } |
153 | 147 | ||
154 | impl MacroCallId { | 148 | impl MacroCallId { |