Skip to content

Commit 0b131bc

Browse files
committed
Auto merge of #12849 - Veykril:no-parse, r=Veykril
internal: Don't parse files unnecessarily in scope_for_offset
2 parents fbb1337 + cb6703f commit 0b131bc

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir/src/source_analyzer.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,7 @@ fn scope_for_offset(
650650
.filter_map(|(id, scope)| {
651651
let InFile { file_id, value } = source_map.expr_syntax(*id).ok()?;
652652
if from_file == file_id {
653-
let root = db.parse_or_expand(file_id)?;
654-
let node = value.to_node(&root);
655-
return Some((node.syntax().text_range(), scope));
653+
return Some((value.text_range(), scope));
656654
}
657655

658656
// FIXME handle attribute expansion

crates/syntax/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ doctest = false
1313
[dependencies]
1414
cov-mark = "2.0.0-pre.1"
1515
itertools = "0.10.3"
16-
rowan = "0.15.5"
16+
rowan = "0.15.8"
1717
rustc_lexer = { version = "725.0.0", package = "rustc-ap-rustc_lexer" }
1818
rustc-hash = "1.1.0"
1919
once_cell = "1.12.0"

crates/syntax/src/ptr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use std::{
1414
marker::PhantomData,
1515
};
1616

17+
use rowan::TextRange;
18+
1719
use crate::{syntax_node::RustLanguage, AstNode, SyntaxNode};
1820

1921
/// A "pointer" to a [`SyntaxNode`], via location in the source code.
@@ -60,6 +62,10 @@ impl<N: AstNode> AstPtr<N> {
6062
self.raw.clone()
6163
}
6264

65+
pub fn text_range(&self) -> TextRange {
66+
self.raw.text_range()
67+
}
68+
6369
pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> {
6470
if !U::can_cast(self.raw.kind()) {
6571
return None;

0 commit comments

Comments
 (0)