This commit is contained in:
Aleksey Kladov 2018-08-17 22:03:55 +03:00
parent d3c90ded2b
commit c7b1be6be3
4 changed files with 11 additions and 4 deletions

View file

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

View file

@ -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()

View file

@ -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()
} }

View file

@ -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())
}) })
} }