internal: Don't parse files unnecessarily in scope_for_offset

This commit is contained in:
Lukas Wirth 2022-07-23 00:50:59 +02:00
parent 84a6fac37a
commit cb6703fe06
4 changed files with 10 additions and 6 deletions

4
Cargo.lock generated
View file

@ -1318,9 +1318,9 @@ checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
[[package]] [[package]]
name = "rowan" name = "rowan"
version = "0.15.5" version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce1f383129e417a6265b16ed78e6e9307748f0863b2ba75f78ff14717db5b017" checksum = "e88acf7b001007e9e8c989fe7449f6601d909e5dd2c56399fc158977ad6c56e8"
dependencies = [ dependencies = [
"countme", "countme",
"hashbrown", "hashbrown",

View file

@ -650,9 +650,7 @@ fn scope_for_offset(
.filter_map(|(id, scope)| { .filter_map(|(id, scope)| {
let InFile { file_id, value } = source_map.expr_syntax(*id).ok()?; let InFile { file_id, value } = source_map.expr_syntax(*id).ok()?;
if from_file == file_id { if from_file == file_id {
let root = db.parse_or_expand(file_id)?; return Some((value.text_range(), scope));
let node = value.to_node(&root);
return Some((node.syntax().text_range(), scope));
} }
// FIXME handle attribute expansion // FIXME handle attribute expansion

View file

@ -13,7 +13,7 @@ doctest = false
[dependencies] [dependencies]
cov-mark = "2.0.0-pre.1" cov-mark = "2.0.0-pre.1"
itertools = "0.10.3" itertools = "0.10.3"
rowan = "0.15.5" rowan = "0.15.8"
rustc_lexer = { version = "725.0.0", package = "rustc-ap-rustc_lexer" } rustc_lexer = { version = "725.0.0", package = "rustc-ap-rustc_lexer" }
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
once_cell = "1.12.0" once_cell = "1.12.0"

View file

@ -14,6 +14,8 @@ use std::{
marker::PhantomData, marker::PhantomData,
}; };
use rowan::TextRange;
use crate::{syntax_node::RustLanguage, AstNode, SyntaxNode}; use crate::{syntax_node::RustLanguage, AstNode, SyntaxNode};
/// A "pointer" to a [`SyntaxNode`], via location in the source code. /// A "pointer" to a [`SyntaxNode`], via location in the source code.
@ -60,6 +62,10 @@ impl<N: AstNode> AstPtr<N> {
self.raw.clone() self.raw.clone()
} }
pub fn text_range(&self) -> TextRange {
self.raw.text_range()
}
pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> { pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> {
if !U::can_cast(self.raw.kind()) { if !U::can_cast(self.raw.kind()) {
return None; return None;