diff options
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r-- | crates/ra_hir_expand/src/db.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 2 |
2 files changed, 20 insertions, 10 deletions
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 { | |||
18 | pub expansion_info: Arc<ExpansionInfo>, | 18 | pub expansion_info: Arc<ExpansionInfo>, |
19 | } | 19 | } |
20 | 20 | ||
21 | #[derive(Debug, PartialEq, Eq, Clone)] | ||
22 | pub struct MacroExpandInfo { | ||
23 | pub arg_map: Arc<mbe::TokenMap>, | ||
24 | pub def_map: Arc<mbe::TokenMap>, | ||
25 | } | ||
26 | |||
21 | // FIXME: rename to ExpandDatabase | 27 | // FIXME: rename to ExpandDatabase |
22 | #[salsa::query_group(AstDatabaseStorage)] | 28 | #[salsa::query_group(AstDatabaseStorage)] |
23 | pub trait AstDatabase: SourceDatabase { | 29 | pub trait AstDatabase: SourceDatabase { |
@@ -35,7 +41,7 @@ pub trait AstDatabase: SourceDatabase { | |||
35 | fn macro_expand( | 41 | fn macro_expand( |
36 | &self, | 42 | &self, |
37 | macro_call: MacroCallId, | 43 | macro_call: MacroCallId, |
38 | ) -> Result<(Arc<tt::Subtree>, (Arc<mbe::TokenMap>, Arc<mbe::TokenMap>)), String>; | 44 | ) -> Result<(Arc<tt::Subtree>, MacroExpandInfo), String>; |
39 | 45 | ||
40 | fn macro_expansion_info(&self, macro_file: MacroFile) -> Option<Arc<ExpansionInfo>>; | 46 | fn macro_expansion_info(&self, macro_file: MacroFile) -> Option<Arc<ExpansionInfo>>; |
41 | } | 47 | } |
@@ -77,7 +83,7 @@ pub(crate) fn macro_arg( | |||
77 | pub(crate) fn macro_expand( | 83 | pub(crate) fn macro_expand( |
78 | db: &dyn AstDatabase, | 84 | db: &dyn AstDatabase, |
79 | id: MacroCallId, | 85 | id: MacroCallId, |
80 | ) -> Result<(Arc<tt::Subtree>, (Arc<mbe::TokenMap>, Arc<mbe::TokenMap>)), String> { | 86 | ) -> Result<(Arc<tt::Subtree>, MacroExpandInfo), String> { |
81 | let loc = db.lookup_intern_macro(id); | 87 | let loc = db.lookup_intern_macro(id); |
82 | let macro_arg = db.macro_arg(id).ok_or("Fail to args in to tt::TokenTree")?; | 88 | let macro_arg = db.macro_arg(id).ok_or("Fail to args in to tt::TokenTree")?; |
83 | 89 | ||
@@ -89,7 +95,10 @@ pub(crate) fn macro_expand( | |||
89 | return Err(format!("Total tokens count exceed limit : count = {}", count)); | 95 | return Err(format!("Total tokens count exceed limit : count = {}", count)); |
90 | } | 96 | } |
91 | 97 | ||
92 | Ok((Arc::new(tt), (macro_arg.1.clone(), macro_rules.1.clone()))) | 98 | Ok(( |
99 | Arc::new(tt), | ||
100 | MacroExpandInfo { arg_map: macro_arg.1.clone(), def_map: macro_rules.1.clone() }, | ||
101 | )) | ||
93 | } | 102 | } |
94 | 103 | ||
95 | pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> { | 104 | pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> { |
@@ -133,7 +142,7 @@ pub(crate) fn parse_macro_with_info( | |||
133 | }; | 142 | }; |
134 | 143 | ||
135 | res.map(|(parsed, exp_map)| { | 144 | res.map(|(parsed, exp_map)| { |
136 | let (arg_map, def_map) = tt.1; | 145 | let expand_info = tt.1; |
137 | let loc: MacroCallLoc = db.lookup_intern_macro(macro_call_id); | 146 | let loc: MacroCallLoc = db.lookup_intern_macro(macro_call_id); |
138 | 147 | ||
139 | let def_start = | 148 | let def_start = |
@@ -141,11 +150,12 @@ pub(crate) fn parse_macro_with_info( | |||
141 | let arg_start = | 150 | let arg_start = |
142 | loc.ast_id.to_node(db).token_tree().map(|t| t.syntax().text_range().start()); | 151 | loc.ast_id.to_node(db).token_tree().map(|t| t.syntax().text_range().start()); |
143 | 152 | ||
144 | let arg_map = | 153 | let arg_map = arg_start |
145 | arg_start.map(|start| exp_map.ranges(&arg_map, start)).unwrap_or_else(|| Vec::new()); | 154 | .map(|start| exp_map.ranges(&expand_info.arg_map, start)) |
146 | 155 | .unwrap_or_else(|| Vec::new()); | |
147 | let def_map = | 156 | let def_map = def_start |
148 | def_start.map(|start| exp_map.ranges(&def_map, start)).unwrap_or_else(|| Vec::new()); | 157 | .map(|start| exp_map.ranges(&expand_info.def_map, start)) |
158 | .unwrap_or_else(|| Vec::new()); | ||
149 | 159 | ||
150 | let info = ExpansionInfo { arg_map, def_map }; | 160 | let info = ExpansionInfo { arg_map, def_map }; |
151 | 161 | ||
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 { | |||
132 | } | 132 | } |
133 | 133 | ||
134 | #[derive(Debug, Clone, PartialEq, Eq)] | 134 | #[derive(Debug, Clone, PartialEq, Eq)] |
135 | /// ExpansionInfo mainly describle how to map text range between src and expaned macro | 135 | /// ExpansionInfo mainly describes how to map text range between src and expanded macro |
136 | pub struct ExpansionInfo { | 136 | pub struct ExpansionInfo { |
137 | pub arg_map: Vec<(TextRange, TextRange)>, | 137 | pub arg_map: Vec<(TextRange, TextRange)>, |
138 | pub def_map: Vec<(TextRange, TextRange)>, | 138 | pub def_map: Vec<(TextRange, TextRange)>, |