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

View File

@ -46,7 +46,7 @@ pub fn ast(&self) -> File {
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()

View File

@ -51,13 +51,20 @@ pub(crate) fn new_owned(root: SyntaxRoot) -> Self {
}
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()
}

View File

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