From 98531dc785535ccde9edc798a17275b9a2f5c1fb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 12 May 2019 22:51:03 +0300 Subject: simplify --- crates/ra_hir/src/resolve.rs | 2 +- crates/ra_hir/src/source_binder.rs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 2fb219908..f1c7d7566 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -134,7 +134,7 @@ impl Resolver { resolution } - pub fn resolve_macro_call( + pub(crate) fn resolve_macro_call( &self, db: &impl HirDatabase, path: Option, diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 31bf13425..bb485e35f 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -20,7 +20,7 @@ use crate::{ HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, AsName, Module, HirFileId, Crate, Trait, Resolver, Ty,Path, expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, - ids::{LocationCtx,MacroCallId}, + ids::{LocationCtx, MacroDefId}, docs::{docs_from_ast,Documentation}, expr, AstId, }; @@ -191,13 +191,12 @@ pub enum PathResolution { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MacroByExampleDef { - pub(crate) id: MacroCallId, + pub(crate) id: MacroDefId, } impl MacroByExampleDef { pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { - let loc = self.id.loc(db); - (self.id.into(), loc.def.0.to_node(db)) + (self.id.0.file_id(), self.id.0.to_node(db)) } } @@ -296,9 +295,9 @@ impl SourceAnalyzer { db, macro_call.path().and_then(Path::from_ast), ast_id, - ); - - call_id.map(|id| MacroByExampleDef { id }) + )?; + let loc = call_id.loc(db); + Some(MacroByExampleDef { id: loc.def }) } pub fn resolve_hir_path( -- cgit v1.2.3 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 +++--------------- 4 files changed, 11 insertions(+), 33 deletions(-) (limited to 'crates/ra_hir') 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( -- cgit v1.2.3