Skip to content

Commit

Permalink
Auto merge of rust-lang#12849 - Veykril:no-parse, r=Veykril
Browse files Browse the repository at this point in the history
internal: Don't parse files unnecessarily in scope_for_offset
  • Loading branch information
bors committed Jul 22, 2022
2 parents fbb1337 + cb6703f commit 0b131bc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/hir/src/source_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions crates/syntax/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0b131bc

Please sign in to comment.