Skip to content

Commit f1cb5ed

Browse files
committed
fix: Properly cache files in Semantics when ascending macros
1 parent 2f8dd64 commit f1cb5ed

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

crates/hir/src/semantics.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
mod source_to_def;
44

5-
use std::{cell::RefCell, fmt};
5+
use std::{cell::RefCell, fmt, iter};
66

77
use base_db::{FileId, FileRange};
88
use either::Either;
@@ -749,8 +749,8 @@ impl<'db> SemanticsImpl<'db> {
749749

750750
fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange {
751751
let root = self.parse_or_expand(src.file_id).unwrap();
752-
let node = src.value.to_node(&root);
753-
src.with_value(&node).original_file_range(self.db.upcast())
752+
let node = src.map(|it| it.to_node(&root));
753+
node.as_ref().original_file_range(self.db.upcast())
754754
}
755755

756756
fn token_ancestors_with_macros(
@@ -765,7 +765,17 @@ impl<'db> SemanticsImpl<'db> {
765765
node: SyntaxNode,
766766
) -> impl Iterator<Item = SyntaxNode> + Clone + '_ {
767767
let node = self.find_file(&node);
768-
node.ancestors_with_macros(self.db.upcast()).map(|it| it.value)
768+
let db = self.db.upcast();
769+
iter::successors(Some(node.cloned()), move |&InFile { file_id, ref value }| {
770+
match value.parent() {
771+
Some(parent) => Some(InFile::new(file_id, parent)),
772+
None => {
773+
self.cache(value.clone(), file_id);
774+
file_id.call_node(db)
775+
}
776+
}
777+
})
778+
.map(|it| it.value)
769779
}
770780

771781
fn ancestors_at_offset_with_macros(

crates/hir_expand/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,7 @@ impl<'a> InFile<&'a SyntaxNode> {
636636
) -> impl Iterator<Item = InFile<SyntaxNode>> + Clone + '_ {
637637
iter::successors(Some(self.cloned()), move |node| match node.value.parent() {
638638
Some(parent) => Some(node.with_value(parent)),
639-
None => {
640-
let parent_node = node.file_id.call_node(db)?;
641-
Some(parent_node)
642-
}
639+
None => node.file_id.call_node(db),
643640
})
644641
}
645642

0 commit comments

Comments
 (0)