mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
fix: Properly cache files in Semantics when ascending macros
This commit is contained in:
parent
2f8dd64830
commit
f1cb5ed9b0
2 changed files with 15 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mod source_to_def;
|
mod source_to_def;
|
||||||
|
|
||||||
use std::{cell::RefCell, fmt};
|
use std::{cell::RefCell, fmt, iter};
|
||||||
|
|
||||||
use base_db::{FileId, FileRange};
|
use base_db::{FileId, FileRange};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
|
@ -749,8 +749,8 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
|
|
||||||
fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange {
|
fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange {
|
||||||
let root = self.parse_or_expand(src.file_id).unwrap();
|
let root = self.parse_or_expand(src.file_id).unwrap();
|
||||||
let node = src.value.to_node(&root);
|
let node = src.map(|it| it.to_node(&root));
|
||||||
src.with_value(&node).original_file_range(self.db.upcast())
|
node.as_ref().original_file_range(self.db.upcast())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn token_ancestors_with_macros(
|
fn token_ancestors_with_macros(
|
||||||
|
@ -765,7 +765,17 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
node: SyntaxNode,
|
node: SyntaxNode,
|
||||||
) -> impl Iterator<Item = SyntaxNode> + Clone + '_ {
|
) -> impl Iterator<Item = SyntaxNode> + Clone + '_ {
|
||||||
let node = self.find_file(&node);
|
let node = self.find_file(&node);
|
||||||
node.ancestors_with_macros(self.db.upcast()).map(|it| it.value)
|
let db = self.db.upcast();
|
||||||
|
iter::successors(Some(node.cloned()), move |&InFile { file_id, ref value }| {
|
||||||
|
match value.parent() {
|
||||||
|
Some(parent) => Some(InFile::new(file_id, parent)),
|
||||||
|
None => {
|
||||||
|
self.cache(value.clone(), file_id);
|
||||||
|
file_id.call_node(db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(|it| it.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ancestors_at_offset_with_macros(
|
fn ancestors_at_offset_with_macros(
|
||||||
|
|
|
@ -636,10 +636,7 @@ impl<'a> InFile<&'a SyntaxNode> {
|
||||||
) -> impl Iterator<Item = InFile<SyntaxNode>> + Clone + '_ {
|
) -> impl Iterator<Item = InFile<SyntaxNode>> + Clone + '_ {
|
||||||
iter::successors(Some(self.cloned()), move |node| match node.value.parent() {
|
iter::successors(Some(self.cloned()), move |node| match node.value.parent() {
|
||||||
Some(parent) => Some(node.with_value(parent)),
|
Some(parent) => Some(node.with_value(parent)),
|
||||||
None => {
|
None => node.file_id.call_node(db),
|
||||||
let parent_node = node.file_id.call_node(db)?;
|
|
||||||
Some(parent_node)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue