diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-17 13:37:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-17 13:37:32 +0000 |
commit | 4a58522119955f36d95212be902fe3ab79c5e922 (patch) | |
tree | 56905131854a5d820a9c2b5e7d9e80484e763b41 /crates/ra_hir_expand | |
parent | a26840d603e672bace319f45b28dd615de1b0c2d (diff) | |
parent | 3ba4b3c554ee94cf96d62c57f9bb80eaff19beed (diff) |
Merge #2562
2562: Fix NavigationTarget ranges r=matklad a=edwin0cheng
Fix the issue described in https://github.com/rust-analyzer/rust-analyzer/pull/2544#issuecomment-565572553
This PR change the order for finding `full_range` of `focus_range` in following orders:
1. map both ranges to macro_call
2. map focus range to a token inside macro call, and full range to the whole of macro call
3. map both ranges to the whole of macro call
And fix the corresponding tests and make these tests easily to follow.
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 13 |
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 | ||
217 | pub use mbe::Origin; | ||
218 | |||
217 | impl ExpansionInfo { | 219 | impl 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 | ||