mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Return all ranges corresponding to a token id in TokenMap
This commit is contained in:
parent
7e31c5ec0d
commit
c5059e0623
6 changed files with 99 additions and 71 deletions
|
@ -163,7 +163,7 @@ pub fn expand_speculative(
|
|||
mbe::token_tree_to_syntax_node(&speculative_expansion.value, fragment_kind).ok()?;
|
||||
|
||||
let token_id = macro_def.map_id_down(token_id);
|
||||
let range = tmap_2.range_by_token(token_id, token_to_map.kind())?;
|
||||
let range = tmap_2.first_range_by_token(token_id, token_to_map.kind())?;
|
||||
let token = node.syntax_node().covering_element(range).into_token()?;
|
||||
Some((node.syntax_node(), token))
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ impl HygieneInfo {
|
|||
},
|
||||
};
|
||||
|
||||
let range = token_map.range_by_token(token_id, SyntaxKind::IDENT)?;
|
||||
let range = token_map.first_range_by_token(token_id, SyntaxKind::IDENT)?;
|
||||
Some((tt.with_value(range + tt.value), origin))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -368,7 +368,7 @@ impl ExpansionInfo {
|
|||
db: &dyn db::AstDatabase,
|
||||
item: Option<ast::Item>,
|
||||
token: InFile<&SyntaxToken>,
|
||||
) -> Option<InFile<SyntaxToken>> {
|
||||
) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + '_> {
|
||||
assert_eq!(token.file_id, self.arg.file_id);
|
||||
let token_id = if let Some(item) = item {
|
||||
let call_id = match self.expanded.file_id.0 {
|
||||
|
@ -411,11 +411,12 @@ impl ExpansionInfo {
|
|||
}
|
||||
};
|
||||
|
||||
let range = self.exp_map.range_by_token(token_id, token.value.kind())?;
|
||||
let tokens = self
|
||||
.exp_map
|
||||
.ranges_by_token(token_id, token.value.kind())
|
||||
.flat_map(move |range| self.expanded.value.covering_element(range).into_token());
|
||||
|
||||
let token = self.expanded.value.covering_element(range).into_token()?;
|
||||
|
||||
Some(self.expanded.with_value(token))
|
||||
Some(tokens.map(move |token| self.expanded.with_value(token)))
|
||||
}
|
||||
|
||||
pub fn map_token_up(
|
||||
|
@ -453,7 +454,7 @@ impl ExpansionInfo {
|
|||
},
|
||||
};
|
||||
|
||||
let range = token_map.range_by_token(token_id, token.value.kind())?;
|
||||
let range = token_map.first_range_by_token(token_id, token.value.kind())?;
|
||||
let token =
|
||||
tt.value.covering_element(range + tt.value.text_range().start()).into_token()?;
|
||||
Some((tt.with_value(token), origin))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue