diff options
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 1def032f9..d1f97c104 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -1,12 +1,15 @@ | |||
1 | //! Name resolution. | 1 | //! Name resolution. |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use ra_syntax::ast; | ||
5 | |||
4 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
5 | 7 | ||
6 | use crate::{ | 8 | use crate::{ |
7 | ModuleDef, | 9 | ModuleDef, |
8 | code_model_api::Crate, | 10 | code_model_api::Crate, |
9 | MacroDefId, | 11 | MacroCallId, |
12 | MacroCallLoc, | ||
10 | db::HirDatabase, | 13 | db::HirDatabase, |
11 | name::{Name, KnownName}, | 14 | name::{Name, KnownName}, |
12 | nameres::{PerNs, CrateDefMap, CrateModuleId}, | 15 | nameres::{PerNs, CrateDefMap, CrateModuleId}, |
@@ -131,8 +134,29 @@ impl Resolver { | |||
131 | resolution | 134 | resolution |
132 | } | 135 | } |
133 | 136 | ||
134 | pub fn resolve_macro_call(&self, name: &Name) -> Option<&MacroDefId> { | 137 | pub fn resolve_macro_call( |
135 | self.module().and_then(|(module, _)| module.find_macro(name)) | 138 | &self, |
139 | db: &impl HirDatabase, | ||
140 | path: Option<Path>, | ||
141 | call: &ast::MacroCall, | ||
142 | ) -> Option<MacroCallId> { | ||
143 | let name = path.and_then(|path| path.expand_macro_expr()).unwrap_or_else(Name::missing); | ||
144 | let macro_def_id = self.module().and_then(|(module, _)| module.find_macro(&name)); | ||
145 | if let Some(def_id) = macro_def_id { | ||
146 | self.module().and_then(|(module, _)| { | ||
147 | // we do this to get the ast_id for the macro call | ||
148 | // if we used the ast_id from the def_id variable | ||
149 | // it gives us the ast_id of the defenition site | ||
150 | let module = module.mk_module(module.root()); | ||
151 | let hir_file_id = module.definition_source(db).0; | ||
152 | let ast_id = db.ast_id_map(hir_file_id).ast_id(call).with_file_id(hir_file_id); | ||
153 | let call_loc = MacroCallLoc { def: *def_id, ast_id }.id(db); | ||
154 | |||
155 | Some(call_loc) | ||
156 | }) | ||
157 | } else { | ||
158 | None | ||
159 | } | ||
136 | } | 160 | } |
137 | 161 | ||
138 | /// Returns the resolved path segments | 162 | /// Returns the resolved path segments |
@@ -197,7 +221,7 @@ impl Resolver { | |||
197 | .flatten() | 221 | .flatten() |
198 | } | 222 | } |
199 | 223 | ||
200 | pub(crate) fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> { | 224 | fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> { |
201 | self.scopes.iter().rev().find_map(|scope| match scope { | 225 | self.scopes.iter().rev().find_map(|scope| match scope { |
202 | Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)), | 226 | Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)), |
203 | 227 | ||