diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 9ea4e695d..bcbcd3dd7 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{ast, AstNode, Parse, SyntaxNode}; | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::{AstDatabase, DefDatabase, InternDatabase}, | 12 | db::{AstDatabase, DefDatabase, InternDatabase}, |
13 | AstId, FileAstId, Module, Source, | 13 | AstId, Crate, FileAstId, Module, Source, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You | 16 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You |
@@ -58,6 +58,17 @@ impl HirFileId { | |||
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | /// Get the crate which the macro lives in, if it is a macro file. | ||
62 | pub(crate) fn macro_crate(self, db: &impl AstDatabase) -> Option<Crate> { | ||
63 | match self.0 { | ||
64 | HirFileIdRepr::File(_) => None, | ||
65 | HirFileIdRepr::Macro(macro_file) => { | ||
66 | let loc = macro_file.macro_call_id.loc(db); | ||
67 | Some(loc.def.krate) | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
61 | pub(crate) fn parse_or_expand_query( | 72 | pub(crate) fn parse_or_expand_query( |
62 | db: &impl AstDatabase, | 73 | db: &impl AstDatabase, |
63 | file_id: HirFileId, | 74 | file_id: HirFileId, |
@@ -121,10 +132,13 @@ impl From<FileId> for HirFileId { | |||
121 | } | 132 | } |
122 | 133 | ||
123 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 134 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
124 | pub struct MacroDefId(pub(crate) AstId<ast::MacroCall>); | 135 | pub struct MacroDefId { |
136 | pub(crate) ast_id: AstId<ast::MacroCall>, | ||
137 | pub(crate) krate: Crate, | ||
138 | } | ||
125 | 139 | ||
126 | pub(crate) fn macro_def_query(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { | 140 | pub(crate) fn macro_def_query(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { |
127 | let macro_call = id.0.to_node(db); | 141 | let macro_call = id.ast_id.to_node(db); |
128 | let arg = macro_call.token_tree()?; | 142 | let arg = macro_call.token_tree()?; |
129 | let (tt, _) = mbe::ast_to_token_tree(&arg).or_else(|| { | 143 | let (tt, _) = mbe::ast_to_token_tree(&arg).or_else(|| { |
130 | log::warn!("fail on macro_def to token tree: {:#?}", arg); | 144 | log::warn!("fail on macro_def to token tree: {:#?}", arg); |