From c7b1be6be345f97d6c4fd9ff3c51a94fb817fa56 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 22:03:55 +0300 Subject: [PATCH] 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(-) diff --git a/crates/libeditor/src/extend_selection.rs b/crates/libeditor/src/extend_selection.rs index cb6edb5769..171e406921 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 46509b5ec6..5b9a07db4d 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 87e4a159de..8f1b1d79ac 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 d35935c646..7e5dc32d92 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()) }) }