diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 18 |
4 files changed, 11 insertions, 33 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 480eaf171..a2b5db1a1 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, | 13 | Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, |
14 | name::AsName, | 14 | name::AsName, |
15 | type_ref::{Mutability, TypeRef}, | 15 | type_ref::{Mutability, TypeRef}, |
16 | }; | 16 | }; |
@@ -828,7 +828,8 @@ where | |||
828 | .ast_id(e) | 828 | .ast_id(e) |
829 | .with_file_id(self.current_file_id); | 829 | .with_file_id(self.current_file_id); |
830 | 830 | ||
831 | if let Some(call_id) = self.resolver.resolve_macro_call(self.db, path, ast_id) { | 831 | if let Some(def) = self.resolver.resolve_macro_call(path) { |
832 | let call_id = MacroCallLoc { def, ast_id }.id(self.db); | ||
832 | if let Some(tt) = self.db.macro_expand(call_id).ok() { | 833 | if let Some(tt) = self.db.macro_expand(call_id).ok() { |
833 | if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() { | 834 | if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() { |
834 | log::debug!("macro expansion {}", expr.syntax().debug_dump()); | 835 | log::debug!("macro expansion {}", expr.syntax().debug_dump()); |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index a450d7b84..0290b3474 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -272,8 +272,8 @@ impl CrateDefMap { | |||
272 | (res.resolved_def, res.segment_index) | 272 | (res.resolved_def, res.segment_index) |
273 | } | 273 | } |
274 | 274 | ||
275 | pub(crate) fn find_macro(&self, name: &Name) -> Option<&MacroDefId> { | 275 | pub(crate) fn find_macro(&self, name: &Name) -> Option<MacroDefId> { |
276 | self.public_macros.get(name).or(self.local_macros.get(name)) | 276 | self.public_macros.get(name).or(self.local_macros.get(name)).map(|it| *it) |
277 | } | 277 | } |
278 | 278 | ||
279 | // Returns Yes if we are sure that additions to `ItemMap` wouldn't change | 279 | // Returns Yes if we are sure that additions to `ItemMap` wouldn't change |
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index f1c7d7566..3874e28bf 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -1,16 +1,12 @@ | |||
1 | //! Name resolution. | 1 | //! Name resolution. |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use ra_syntax::ast; | ||
5 | |||
6 | use rustc_hash::{FxHashMap, FxHashSet}; | 4 | use rustc_hash::{FxHashMap, FxHashSet}; |
7 | 5 | ||
8 | use crate::{ | 6 | use crate::{ |
9 | ModuleDef, Trait, | 7 | ModuleDef, Trait, |
10 | code_model_api::Crate, | 8 | code_model_api::Crate, |
11 | MacroCallId, | 9 | MacroDefId, |
12 | MacroCallLoc, | ||
13 | AstId, | ||
14 | db::HirDatabase, | 10 | db::HirDatabase, |
15 | name::{Name, KnownName}, | 11 | name::{Name, KnownName}, |
16 | nameres::{PerNs, CrateDefMap, CrateModuleId}, | 12 | nameres::{PerNs, CrateDefMap, CrateModuleId}, |
@@ -134,16 +130,9 @@ impl Resolver { | |||
134 | resolution | 130 | resolution |
135 | } | 131 | } |
136 | 132 | ||
137 | pub(crate) fn resolve_macro_call( | 133 | pub(crate) fn resolve_macro_call(&self, path: Option<Path>) -> Option<MacroDefId> { |
138 | &self, | ||
139 | db: &impl HirDatabase, | ||
140 | path: Option<Path>, | ||
141 | ast_id: AstId<ast::MacroCall>, | ||
142 | ) -> Option<MacroCallId> { | ||
143 | let name = path.and_then(|path| path.expand_macro_expr()).unwrap_or_else(Name::missing); | 134 | let name = path.and_then(|path| path.expand_macro_expr()).unwrap_or_else(Name::missing); |
144 | let def_id = self.module().and_then(|(module, _)| module.find_macro(&name))?; | 135 | self.module()?.0.find_macro(&name) |
145 | let call_loc = MacroCallLoc { def: *def_id, ast_id }.id(db); | ||
146 | Some(call_loc) | ||
147 | } | 136 | } |
148 | 137 | ||
149 | /// Returns the resolved path segments | 138 | /// Returns the resolved path segments |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index bb485e35f..179faebfb 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -283,21 +283,9 @@ impl SourceAnalyzer { | |||
283 | self.infer.as_ref()?.field_resolution(expr_id) | 283 | self.infer.as_ref()?.field_resolution(expr_id) |
284 | } | 284 | } |
285 | 285 | ||
286 | pub fn resolve_macro_call( | 286 | pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroByExampleDef> { |
287 | &self, | 287 | let id = self.resolver.resolve_macro_call(macro_call.path().and_then(Path::from_ast))?; |
288 | db: &impl HirDatabase, | 288 | Some(MacroByExampleDef { id }) |
289 | file_id: FileId, | ||
290 | macro_call: &ast::MacroCall, | ||
291 | ) -> Option<MacroByExampleDef> { | ||
292 | let hir_id = file_id.into(); | ||
293 | let ast_id = db.ast_id_map(hir_id).ast_id(macro_call).with_file_id(hir_id); | ||
294 | let call_id = self.resolver.resolve_macro_call( | ||
295 | db, | ||
296 | macro_call.path().and_then(Path::from_ast), | ||
297 | ast_id, | ||
298 | )?; | ||
299 | let loc = call_id.loc(db); | ||
300 | Some(MacroByExampleDef { id: loc.def }) | ||
301 | } | 289 | } |
302 | 290 | ||
303 | pub fn resolve_hir_path( | 291 | pub fn resolve_hir_path( |