Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/token_map.rs')
-rw-r--r--crates/mbe/src/token_map.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/crates/mbe/src/token_map.rs b/crates/mbe/src/token_map.rs
index ff0c106cf2..9053526d20 100644
--- a/crates/mbe/src/token_map.rs
+++ b/crates/mbe/src/token_map.rs
@@ -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) {