mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +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
|
@ -46,9 +46,23 @@ impl TokenMap {
|
|||
Some(token_id)
|
||||
}
|
||||
|
||||
pub fn range_by_token(&self, token_id: tt::TokenId, kind: SyntaxKind) -> Option<TextRange> {
|
||||
let &(_, range) = self.entries.iter().find(|(tid, _)| *tid == token_id)?;
|
||||
range.by_kind(kind)
|
||||
pub fn ranges_by_token(
|
||||
&self,
|
||||
token_id: tt::TokenId,
|
||||
kind: SyntaxKind,
|
||||
) -> impl Iterator<Item = TextRange> + '_ {
|
||||
self.entries
|
||||
.iter()
|
||||
.filter(move |&&(tid, _)| tid == token_id)
|
||||
.filter_map(move |(_, range)| range.by_kind(kind))
|
||||
}
|
||||
|
||||
pub fn first_range_by_token(
|
||||
&self,
|
||||
token_id: tt::TokenId,
|
||||
kind: SyntaxKind,
|
||||
) -> Option<TextRange> {
|
||||
self.ranges_by_token(token_id, kind).next()
|
||||
}
|
||||
|
||||
pub(crate) fn shrink_to_fit(&mut self) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue