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