From 9cba67b2ad0ef43b5c405f21f516c9ebee63a932 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 12 May 2019 23:03:37 +0300 Subject: simplify --- crates/ra_hir/src/expr.rs | 5 +++-- crates/ra_hir/src/nameres.rs | 4 ++-- crates/ra_hir/src/resolve.rs | 17 +++-------------- crates/ra_hir/src/source_binder.rs | 18 +++--------------- crates/ra_ide_api/src/goto_definition.rs | 2 +- 5 files changed, 12 insertions(+), 34 deletions(-) (limited to 'crates') 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::{ }; use crate::{ - Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, + Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, name::AsName, type_ref::{Mutability, TypeRef}, }; @@ -828,7 +828,8 @@ where .ast_id(e) .with_file_id(self.current_file_id); - if let Some(call_id) = self.resolver.resolve_macro_call(self.db, path, ast_id) { + if let Some(def) = self.resolver.resolve_macro_call(path) { + let call_id = MacroCallLoc { def, ast_id }.id(self.db); if let Some(tt) = self.db.macro_expand(call_id).ok() { if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() { 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 { (res.resolved_def, res.segment_index) } - pub(crate) fn find_macro(&self, name: &Name) -> Option<&MacroDefId> { - self.public_macros.get(name).or(self.local_macros.get(name)) + pub(crate) fn find_macro(&self, name: &Name) -> Option { + self.public_macros.get(name).or(self.local_macros.get(name)).map(|it| *it) } // 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 @@ //! Name resolution. use std::sync::Arc; -use ra_syntax::ast; - use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ ModuleDef, Trait, code_model_api::Crate, - MacroCallId, - MacroCallLoc, - AstId, + MacroDefId, db::HirDatabase, name::{Name, KnownName}, nameres::{PerNs, CrateDefMap, CrateModuleId}, @@ -134,16 +130,9 @@ impl Resolver { resolution } - pub(crate) fn resolve_macro_call( - &self, - db: &impl HirDatabase, - path: Option, - ast_id: AstId, - ) -> Option { + pub(crate) fn resolve_macro_call(&self, path: Option) -> Option { let name = path.and_then(|path| path.expand_macro_expr()).unwrap_or_else(Name::missing); - let def_id = self.module().and_then(|(module, _)| module.find_macro(&name))?; - let call_loc = MacroCallLoc { def: *def_id, ast_id }.id(db); - Some(call_loc) + self.module()?.0.find_macro(&name) } /// 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 { self.infer.as_ref()?.field_resolution(expr_id) } - pub fn resolve_macro_call( - &self, - db: &impl HirDatabase, - file_id: FileId, - macro_call: &ast::MacroCall, - ) -> Option { - let hir_id = file_id.into(); - let ast_id = db.ast_id_map(hir_id).ast_id(macro_call).with_file_id(hir_id); - let call_id = self.resolver.resolve_macro_call( - db, - macro_call.path().and_then(Path::from_ast), - ast_id, - )?; - let loc = call_id.loc(db); - Some(MacroByExampleDef { id: loc.def }) + pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option { + let id = self.resolver.resolve_macro_call(macro_call.path().and_then(Path::from_ast))?; + Some(MacroByExampleDef { id }) } pub fn resolve_hir_path( diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 533c229fe..adae29e9c 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -69,7 +69,7 @@ pub(crate) fn reference_definition( .and_then(ast::MacroCall::cast) { tested_by!(goto_definition_works_for_macros); - if let Some(macro_call) = analyzer.resolve_macro_call(db, file_id, macro_call) { + if let Some(macro_call) = analyzer.resolve_macro_call(macro_call) { return Exact(NavigationTarget::from_macro_def(db, macro_call)); } } -- cgit v1.2.3