diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2022-07-23 00:50:59 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2022-07-23 00:50:59 +0200 |
| commit | cb6703fe069063a14df6c4e37ab2ae02367a08c7 (patch) | |
| tree | c35e36d453b0800e827cafc35e4538fc22bd54b1 | |
| parent | 84a6fac37ad61ff512993ee64b47deff9a52c560 (diff) | |
| download | rust-cb6703fe069063a14df6c4e37ab2ae02367a08c7.tar.gz rust-cb6703fe069063a14df6c4e37ab2ae02367a08c7.zip | |
internal: Don't parse files unnecessarily in scope_for_offset
| -rw-r--r-- | Cargo.lock | 4 | ||||
| -rw-r--r-- | crates/hir/src/source_analyzer.rs | 4 | ||||
| -rw-r--r-- | crates/syntax/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/syntax/src/ptr.rs | 6 |
4 files changed, 10 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock index a960012c8cf..7223844471c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1318,9 +1318,9 @@ checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" [[package]] name = "rowan" -version = "0.15.5" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce1f383129e417a6265b16ed78e6e9307748f0863b2ba75f78ff14717db5b017" +checksum = "e88acf7b001007e9e8c989fe7449f6601d909e5dd2c56399fc158977ad6c56e8" dependencies = [ "countme", "hashbrown", diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 984a464ed16..e89f8a54298 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -650,9 +650,7 @@ fn scope_for_offset( .filter_map(|(id, scope)| { let InFile { file_id, value } = source_map.expr_syntax(*id).ok()?; if from_file == file_id { - let root = db.parse_or_expand(file_id)?; - let node = value.to_node(&root); - return Some((node.syntax().text_range(), scope)); + return Some((value.text_range(), scope)); } // FIXME handle attribute expansion diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index 1ff3170a74f..a56c9dec401 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml @@ -13,7 +13,7 @@ doctest = false [dependencies] cov-mark = "2.0.0-pre.1" itertools = "0.10.3" -rowan = "0.15.5" +rowan = "0.15.8" rustc_lexer = { version = "725.0.0", package = "rustc-ap-rustc_lexer" } rustc-hash = "1.1.0" once_cell = "1.12.0" diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs index bd96e35cc6e..a886972fff9 100644 --- a/crates/syntax/src/ptr.rs +++ b/crates/syntax/src/ptr.rs @@ -14,6 +14,8 @@ use std::{ marker::PhantomData, }; +use rowan::TextRange; + use crate::{syntax_node::RustLanguage, AstNode, SyntaxNode}; /// A "pointer" to a [`SyntaxNode`], via location in the source code. @@ -60,6 +62,10 @@ impl<N: AstNode> AstPtr<N> { self.raw.clone() } + pub fn text_range(&self) -> TextRange { + self.raw.text_range() + } + pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> { if !U::can_cast(self.raw.kind()) { return None; |
