mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Owned
This commit is contained in:
parent
d3c90ded2b
commit
c7b1be6be3
4 changed files with 11 additions and 4 deletions
|
@ -6,7 +6,7 @@ use libsyntax2::{
|
||||||
|
|
||||||
pub fn extend_selection(file: &ParsedFile, range: TextRange) -> Option<TextRange> {
|
pub fn extend_selection(file: &ParsedFile, range: TextRange) -> Option<TextRange> {
|
||||||
let syntax = file.syntax();
|
let syntax = file.syntax();
|
||||||
extend(syntax.as_ref(), range)
|
extend(syntax.borrowed(), range)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> {
|
pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> {
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl ParsedFile {
|
||||||
File::cast(self.syntax()).unwrap()
|
File::cast(self.syntax()).unwrap()
|
||||||
}
|
}
|
||||||
pub fn syntax(&self) -> SyntaxNodeRef {
|
pub fn syntax(&self) -> SyntaxNodeRef {
|
||||||
self.root.as_ref()
|
self.root.borrowed()
|
||||||
}
|
}
|
||||||
pub fn errors(&self) -> Vec<SyntaxError> {
|
pub fn errors(&self) -> Vec<SyntaxError> {
|
||||||
self.syntax().root.syntax_root().errors.clone()
|
self.syntax().root.syntax_root().errors.clone()
|
||||||
|
|
|
@ -51,13 +51,20 @@ impl SyntaxNode<OwnedRoot> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: TreeRoot> SyntaxNode<R> {
|
impl<R: TreeRoot> SyntaxNode<R> {
|
||||||
pub fn as_ref<'a>(&'a self) -> SyntaxNode<RefRoot<'a>> {
|
pub fn borrowed<'a>(&'a self) -> SyntaxNodeRef<'a> {
|
||||||
SyntaxNode {
|
SyntaxNode {
|
||||||
root: self.root.borrowed(),
|
root: self.root.borrowed(),
|
||||||
red: self.red,
|
red: self.red,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn owned<'a>(&'a self) -> SyntaxNode {
|
||||||
|
SyntaxNode {
|
||||||
|
root: self.root.owned(),
|
||||||
|
red: self.red,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn kind(&self) -> SyntaxKind {
|
pub fn kind(&self) -> SyntaxKind {
|
||||||
self.red().green().kind()
|
self.red().green().kind()
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn lexer_tests() {
|
||||||
fn parser_tests() {
|
fn parser_tests() {
|
||||||
dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
|
dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
|
||||||
let file = libsyntax2::parse(text);
|
let file = libsyntax2::parse(text);
|
||||||
libsyntax2::utils::dump_tree(file.as_ref())
|
libsyntax2::utils::dump_tree(file.borrowed())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue