From e6709f64af1836460aee41aca34eb19ed3a337dd Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 4 Nov 2019 03:12:19 +0800 Subject: Rename and fix typos --- crates/ra_hir_expand/src/db.rs | 28 +++++++++++++++++++--------- crates/ra_hir_expand/src/lib.rs | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index 8abfbb4ff..b3746924d 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs @@ -18,6 +18,12 @@ pub struct ParseMacroWithInfo { pub expansion_info: Arc, } +#[derive(Debug, PartialEq, Eq, Clone)] +pub struct MacroExpandInfo { + pub arg_map: Arc, + pub def_map: Arc, +} + // FIXME: rename to ExpandDatabase #[salsa::query_group(AstDatabaseStorage)] pub trait AstDatabase: SourceDatabase { @@ -35,7 +41,7 @@ pub trait AstDatabase: SourceDatabase { fn macro_expand( &self, macro_call: MacroCallId, - ) -> Result<(Arc, (Arc, Arc)), String>; + ) -> Result<(Arc, MacroExpandInfo), String>; fn macro_expansion_info(&self, macro_file: MacroFile) -> Option>; } @@ -77,7 +83,7 @@ pub(crate) fn macro_arg( pub(crate) fn macro_expand( db: &dyn AstDatabase, id: MacroCallId, -) -> Result<(Arc, (Arc, Arc)), String> { +) -> Result<(Arc, MacroExpandInfo), String> { let loc = db.lookup_intern_macro(id); let macro_arg = db.macro_arg(id).ok_or("Fail to args in to tt::TokenTree")?; @@ -89,7 +95,10 @@ pub(crate) fn macro_expand( return Err(format!("Total tokens count exceed limit : count = {}", count)); } - Ok((Arc::new(tt), (macro_arg.1.clone(), macro_rules.1.clone()))) + Ok(( + Arc::new(tt), + MacroExpandInfo { arg_map: macro_arg.1.clone(), def_map: macro_rules.1.clone() }, + )) } pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option { @@ -133,7 +142,7 @@ pub(crate) fn parse_macro_with_info( }; res.map(|(parsed, exp_map)| { - let (arg_map, def_map) = tt.1; + let expand_info = tt.1; let loc: MacroCallLoc = db.lookup_intern_macro(macro_call_id); let def_start = @@ -141,11 +150,12 @@ pub(crate) fn parse_macro_with_info( let arg_start = loc.ast_id.to_node(db).token_tree().map(|t| t.syntax().text_range().start()); - let arg_map = - arg_start.map(|start| exp_map.ranges(&arg_map, start)).unwrap_or_else(|| Vec::new()); - - let def_map = - def_start.map(|start| exp_map.ranges(&def_map, start)).unwrap_or_else(|| Vec::new()); + let arg_map = arg_start + .map(|start| exp_map.ranges(&expand_info.arg_map, start)) + .unwrap_or_else(|| Vec::new()); + let def_map = def_start + .map(|start| exp_map.ranges(&expand_info.def_map, start)) + .unwrap_or_else(|| Vec::new()); let info = ExpansionInfo { arg_map, def_map }; diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index b6e55aa6a..63ba17158 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -132,7 +132,7 @@ impl MacroCallId { } #[derive(Debug, Clone, PartialEq, Eq)] -/// ExpansionInfo mainly describle how to map text range between src and expaned macro +/// ExpansionInfo mainly describes how to map text range between src and expanded macro pub struct ExpansionInfo { pub arg_map: Vec<(TextRange, TextRange)>, pub def_map: Vec<(TextRange, TextRange)>, -- cgit v1.2.3