aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r--crates/ra_hir_expand/src/lib.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 94e1e466a..cb4e1950b 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -214,7 +214,13 @@ pub struct ExpansionInfo {
214 exp_map: Arc<mbe::TokenMap>, 214 exp_map: Arc<mbe::TokenMap>,
215} 215}
216 216
217pub use mbe::Origin;
218
217impl ExpansionInfo { 219impl ExpansionInfo {
220 pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
221 Some(self.arg.with_value(self.arg.value.parent()?))
222 }
223
218 pub fn map_token_down(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> { 224 pub fn map_token_down(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> {
219 assert_eq!(token.file_id, self.arg.file_id); 225 assert_eq!(token.file_id, self.arg.file_id);
220 let range = token.value.text_range().checked_sub(self.arg.value.text_range().start())?; 226 let range = token.value.text_range().checked_sub(self.arg.value.text_range().start())?;
@@ -228,7 +234,10 @@ impl ExpansionInfo {
228 Some(self.expanded.with_value(token)) 234 Some(self.expanded.with_value(token))
229 } 235 }
230 236
231 pub fn map_token_up(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> { 237 pub fn map_token_up(
238 &self,
239 token: InFile<&SyntaxToken>,
240 ) -> Option<(InFile<SyntaxToken>, Origin)> {
232 let token_id = self.exp_map.token_by_range(token.value.text_range())?; 241 let token_id = self.exp_map.token_by_range(token.value.text_range())?;
233 242
234 let (token_id, origin) = self.macro_def.0.map_id_up(token_id); 243 let (token_id, origin) = self.macro_def.0.map_id_up(token_id);
@@ -242,7 +251,7 @@ impl ExpansionInfo {
242 let range = token_map.range_by_token(token_id)?; 251 let range = token_map.range_by_token(token_id)?;
243 let token = algo::find_covering_element(&tt.value, range + tt.value.text_range().start()) 252 let token = algo::find_covering_element(&tt.value, range + tt.value.text_range().start())
244 .into_token()?; 253 .into_token()?;
245 Some(tt.with_value(token)) 254 Some((tt.with_value(token), origin))
246 } 255 }
247} 256}
248 257