Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/lib.rs')
-rw-r--r--crates/hir-expand/src/lib.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index 9538097949..56cb5fd375 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -25,6 +25,7 @@ mod prettify_macro_expansion_;
use attrs::collect_attrs;
use rustc_hash::FxHashMap;
+use stdx::TupleExt;
use triomphe::Arc;
use std::hash::Hash;
@@ -772,14 +773,15 @@ impl ExpansionInfo {
/// Maps the passed in file range down into a macro expansion if it is the input to a macro call.
///
/// Note this does a linear search through the entire backing vector of the spanmap.
+ // FIXME: Consider adding a reverse map to ExpansionInfo to get rid of the linear search which
+ // potentially results in quadratic look ups (notably this might improve semantic highlighting perf)
pub fn map_range_down_exact(
&self,
span: Span,
- ) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + '_>> {
- let tokens = self
- .exp_map
- .ranges_with_span_exact(span)
- .flat_map(move |range| self.expanded.value.covering_element(range).into_token());
+ ) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContextId)> + '_>> {
+ let tokens = self.exp_map.ranges_with_span_exact(span).flat_map(move |(range, ctx)| {
+ self.expanded.value.covering_element(range).into_token().zip(Some(ctx))
+ });
Some(InMacroFile::new(self.expanded.file_id, tokens))
}
@@ -791,11 +793,10 @@ impl ExpansionInfo {
pub fn map_range_down(
&self,
span: Span,
- ) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + '_>> {
- let tokens = self
- .exp_map
- .ranges_with_span(span)
- .flat_map(move |range| self.expanded.value.covering_element(range).into_token());
+ ) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContextId)> + '_>> {
+ let tokens = self.exp_map.ranges_with_span(span).flat_map(move |(range, ctx)| {
+ self.expanded.value.covering_element(range).into_token().zip(Some(ctx))
+ });
Some(InMacroFile::new(self.expanded.file_id, tokens))
}
@@ -845,7 +846,8 @@ impl ExpansionInfo {
self.arg.file_id,
arg_map
.ranges_with_span_exact(span)
- .filter(|range| range.intersect(arg_range).is_some())
+ .filter(|(range, _)| range.intersect(arg_range).is_some())
+ .map(TupleExt::head)
.collect(),
)
}