From c7b1be6be345f97d6c4fd9ff3c51a94fb817fa56 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 22:03:55 +0300 Subject: Owned --- crates/libeditor/src/extend_selection.rs | 2 +- crates/libsyntax2/src/ast/mod.rs | 2 +- crates/libsyntax2/src/yellow/syntax.rs | 9 ++++++++- crates/libsyntax2/tests/test/main.rs | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/libeditor/src/extend_selection.rs b/crates/libeditor/src/extend_selection.rs index cb6edb576..171e40692 100644 --- a/crates/libeditor/src/extend_selection.rs +++ b/crates/libeditor/src/extend_selection.rs @@ -6,7 +6,7 @@ use libsyntax2::{ pub fn extend_selection(file: &ParsedFile, range: TextRange) -> Option { let syntax = file.syntax(); - extend(syntax.as_ref(), range) + extend(syntax.borrowed(), range) } pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option { diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index 46509b5ec..5b9a07db4 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs @@ -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 { self.syntax().root.syntax_root().errors.clone() diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs index 87e4a159d..8f1b1d79a 100644 --- a/crates/libsyntax2/src/yellow/syntax.rs +++ b/crates/libsyntax2/src/yellow/syntax.rs @@ -51,13 +51,20 @@ impl SyntaxNode { } impl SyntaxNode { - pub fn as_ref<'a>(&'a self) -> SyntaxNode> { + 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() } diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index d35935c64..7e5dc32d9 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs @@ -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()) }) } -- cgit v1.2.3