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

View file

@ -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;