aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/lib.rs12
-rw-r--r--crates/ra_syntax/src/syntax_node.rs7
2 files changed, 13 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 2eb3fcd57..534c206a6 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -35,7 +35,7 @@ use std::{fmt::Write, sync::Arc};
35 35
36use ra_text_edit::AtomTextEdit; 36use ra_text_edit::AtomTextEdit;
37 37
38use crate::syntax_node::{GreenNode, SyntaxNodeWrapper}; 38use crate::syntax_node::GreenNode;
39 39
40pub use crate::{ 40pub use crate::{
41 ast::{AstNode, AstToken}, 41 ast::{AstNode, AstToken},
@@ -43,8 +43,8 @@ pub use crate::{
43 ptr::{AstPtr, SyntaxNodePtr}, 43 ptr::{AstPtr, SyntaxNodePtr},
44 syntax_error::{Location, SyntaxError, SyntaxErrorKind}, 44 syntax_error::{Location, SyntaxError, SyntaxErrorKind},
45 syntax_node::{ 45 syntax_node::{
46 Direction, InsertPosition, SyntaxElement, SyntaxNode, SyntaxToken, SyntaxTreeBuilder, 46 Direction, InsertPosition, SyntaxElement, SyntaxNode, SyntaxNodeWrapper, SyntaxToken,
47 TreeArc, WalkEvent, 47 SyntaxTreeBuilder, TreeArc, WalkEvent,
48 }, 48 },
49 syntax_text::SyntaxText, 49 syntax_text::SyntaxText,
50}; 50};
@@ -91,6 +91,12 @@ impl<T: SyntaxNodeWrapper> Parse<T> {
91 } 91 }
92} 92}
93 93
94impl<T: AstNode> Parse<T> {
95 pub fn to_syntax(this: Self) -> Parse<SyntaxNode> {
96 Parse { tree: this.tree().syntax().to_owned(), errors: this.errors }
97 }
98}
99
94impl Parse<SourceFile> { 100impl Parse<SourceFile> {
95 pub fn debug_dump(&self) -> String { 101 pub fn debug_dump(&self) -> String {
96 let mut buf = self.tree.syntax().debug_dump(); 102 let mut buf = self.tree.syntax().debug_dump();
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs
index a1f9a59b6..e57813a94 100644
--- a/crates/ra_syntax/src/syntax_node.rs
+++ b/crates/ra_syntax/src/syntax_node.rs
@@ -18,7 +18,8 @@ use rowan::{GreenNodeBuilder, TransparentNewType};
18 18
19use crate::{ 19use crate::{
20 syntax_error::{SyntaxError, SyntaxErrorKind}, 20 syntax_error::{SyntaxError, SyntaxErrorKind},
21 AstNode, SmolStr, SourceFile, SyntaxKind, SyntaxNodePtr, SyntaxText, TextRange, TextUnit, 21 AstNode, Parse, SmolStr, SourceFile, SyntaxKind, SyntaxNodePtr, SyntaxText, TextRange,
22 TextUnit,
22}; 23};
23 24
24pub use rowan::WalkEvent; 25pub use rowan::WalkEvent;
@@ -594,13 +595,13 @@ impl SyntaxTreeBuilder {
594 (green, self.errors) 595 (green, self.errors)
595 } 596 }
596 597
597 pub fn finish(self) -> (TreeArc<SyntaxNode>, Vec<SyntaxError>) { 598 pub fn finish(self) -> Parse<SyntaxNode> {
598 let (green, errors) = self.finish_raw(); 599 let (green, errors) = self.finish_raw();
599 let node = SyntaxNode::new(green); 600 let node = SyntaxNode::new(green);
600 if cfg!(debug_assertions) { 601 if cfg!(debug_assertions) {
601 crate::validation::validate_block_structure(&node); 602 crate::validation::validate_block_structure(&node);
602 } 603 }
603 (node, errors) 604 Parse::new(node, errors)
604 } 605 }
605 606
606 pub fn token(&mut self, kind: SyntaxKind, text: SmolStr) { 607 pub fn token(&mut self, kind: SyntaxKind, text: SmolStr) {