diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide_api/src/status.rs | 8 | ||||
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 52 | ||||
-rw-r--r-- | crates/ra_mbe/src/tests.rs | 30 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_node.rs | 7 |
7 files changed, 64 insertions, 63 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 040c782e6..da9f3e32d 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -2,7 +2,7 @@ use std::sync::Arc; | |||
2 | 2 | ||
3 | use parking_lot::Mutex; | 3 | use parking_lot::Mutex; |
4 | use ra_db::{salsa, SourceDatabase}; | 4 | use ra_db::{salsa, SourceDatabase}; |
5 | use ra_syntax::{ast, SmolStr, SyntaxNode, TreeArc}; | 5 | use ra_syntax::{ast, Parse, SmolStr, SyntaxNode, TreeArc}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | adt::{EnumData, StructData}, | 8 | adt::{EnumData, StructData}, |
@@ -69,7 +69,7 @@ pub trait AstDatabase: InternDatabase { | |||
69 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>; | 69 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>; |
70 | 70 | ||
71 | #[salsa::invoke(crate::ids::HirFileId::parse_macro_query)] | 71 | #[salsa::invoke(crate::ids::HirFileId::parse_macro_query)] |
72 | fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<TreeArc<SyntaxNode>>; | 72 | fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<Parse<SyntaxNode>>; |
73 | 73 | ||
74 | #[salsa::invoke(crate::ids::macro_def_query)] | 74 | #[salsa::invoke(crate::ids::macro_def_query)] |
75 | fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; | 75 | fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 80e9cccd6..83f5c3f39 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -6,7 +6,7 @@ use std::{ | |||
6 | use mbe::MacroRules; | 6 | use mbe::MacroRules; |
7 | use ra_db::{salsa, FileId}; | 7 | use ra_db::{salsa, FileId}; |
8 | use ra_prof::profile; | 8 | use ra_prof::profile; |
9 | use ra_syntax::{ast, AstNode, SyntaxNode, TreeArc}; | 9 | use ra_syntax::{ast, AstNode, Parse, SyntaxNode, TreeArc}; |
10 | 10 | ||
11 | use crate::{AstDatabase, AstId, DefDatabase, FileAstId, InternDatabase, Module, Source}; | 11 | use crate::{AstDatabase, AstId, DefDatabase, FileAstId, InternDatabase, Module, Source}; |
12 | 12 | ||
@@ -61,14 +61,16 @@ impl HirFileId { | |||
61 | ) -> Option<TreeArc<SyntaxNode>> { | 61 | ) -> Option<TreeArc<SyntaxNode>> { |
62 | match file_id.0 { | 62 | match file_id.0 { |
63 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree().syntax().to_owned()), | 63 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree().syntax().to_owned()), |
64 | HirFileIdRepr::Macro(macro_file) => db.parse_macro(macro_file), | 64 | HirFileIdRepr::Macro(macro_file) => { |
65 | db.parse_macro(macro_file).map(|it| it.tree().to_owned()) | ||
66 | } | ||
65 | } | 67 | } |
66 | } | 68 | } |
67 | 69 | ||
68 | pub(crate) fn parse_macro_query( | 70 | pub(crate) fn parse_macro_query( |
69 | db: &impl AstDatabase, | 71 | db: &impl AstDatabase, |
70 | macro_file: MacroFile, | 72 | macro_file: MacroFile, |
71 | ) -> Option<TreeArc<SyntaxNode>> { | 73 | ) -> Option<Parse<SyntaxNode>> { |
72 | let _p = profile("parse_macro_query"); | 74 | let _p = profile("parse_macro_query"); |
73 | let macro_call_id = macro_file.macro_call_id; | 75 | let macro_call_id = macro_file.macro_call_id; |
74 | let tt = db | 76 | let tt = db |
@@ -85,10 +87,8 @@ impl HirFileId { | |||
85 | }) | 87 | }) |
86 | .ok()?; | 88 | .ok()?; |
87 | match macro_file.macro_file_kind { | 89 | match macro_file.macro_file_kind { |
88 | MacroFileKind::Items => Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned()), | 90 | MacroFileKind::Items => Some(Parse::to_syntax(mbe::token_tree_to_ast_item_list(&tt))), |
89 | MacroFileKind::Expr => { | 91 | MacroFileKind::Expr => mbe::token_tree_to_expr(&tt).ok().map(Parse::to_syntax), |
90 | mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned()) | ||
91 | } | ||
92 | } | 92 | } |
93 | } | 93 | } |
94 | } | 94 | } |
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index d71c89b43..a31e15245 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs | |||
@@ -9,7 +9,7 @@ use ra_db::{ | |||
9 | FileTextQuery, SourceRootId, | 9 | FileTextQuery, SourceRootId, |
10 | }; | 10 | }; |
11 | use ra_prof::{memory_usage, Bytes}; | 11 | use ra_prof::{memory_usage, Bytes}; |
12 | use ra_syntax::{ast, AstNode, Parse, SyntaxNode, TreeArc}; | 12 | use ra_syntax::{ast, AstNode, Parse, SyntaxNode}; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | db::RootDatabase, | 15 | db::RootDatabase, |
@@ -96,15 +96,15 @@ impl FromIterator<TableEntry<FileId, Parse<ast::SourceFile>>> for SyntaxTreeStat | |||
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | impl FromIterator<TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>> for SyntaxTreeStats { | 99 | impl FromIterator<TableEntry<MacroFile, Option<Parse<SyntaxNode>>>> for SyntaxTreeStats { |
100 | fn from_iter<T>(iter: T) -> SyntaxTreeStats | 100 | fn from_iter<T>(iter: T) -> SyntaxTreeStats |
101 | where | 101 | where |
102 | T: IntoIterator<Item = TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>>, | 102 | T: IntoIterator<Item = TableEntry<MacroFile, Option<Parse<SyntaxNode>>>>, |
103 | { | 103 | { |
104 | let mut res = SyntaxTreeStats::default(); | 104 | let mut res = SyntaxTreeStats::default(); |
105 | for entry in iter { | 105 | for entry in iter { |
106 | res.total += 1; | 106 | res.total += 1; |
107 | if let Some(tree) = entry.value.and_then(|it| it) { | 107 | if let Some(tree) = entry.value.and_then(|it| it).map(|it| it.tree().to_owned()) { |
108 | res.retained += 1; | 108 | res.retained += 1; |
109 | res.retained_size += tree.memory_size_of_subtree(); | 109 | res.retained_size += tree.memory_size_of_subtree(); |
110 | } | 110 | } |
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 7560d215a..bfc351f81 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -2,8 +2,8 @@ use crate::subtree_source::SubtreeTokenSource; | |||
2 | use crate::ExpandError; | 2 | use crate::ExpandError; |
3 | use ra_parser::{ParseError, TreeSink}; | 3 | use ra_parser::{ParseError, TreeSink}; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | ast, AstNode, SmolStr, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxNode, SyntaxTreeBuilder, | 5 | ast, AstNode, Parse, SmolStr, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxNode, |
6 | TextRange, TextUnit, TreeArc, T, | 6 | SyntaxTreeBuilder, TextRange, TextUnit, T, |
7 | }; | 7 | }; |
8 | use tt::buffer::{Cursor, TokenBuffer}; | 8 | use tt::buffer::{Cursor, TokenBuffer}; |
9 | 9 | ||
@@ -45,7 +45,7 @@ pub fn syntax_node_to_token_tree(node: &SyntaxNode) -> Option<(tt::Subtree, Toke | |||
45 | // | 45 | // |
46 | // | 46 | // |
47 | 47 | ||
48 | fn token_tree_to_syntax_node<F>(tt: &tt::Subtree, f: F) -> Result<TreeArc<SyntaxNode>, ExpandError> | 48 | fn token_tree_to_syntax_node<F>(tt: &tt::Subtree, f: F) -> Result<Parse<SyntaxNode>, ExpandError> |
49 | where | 49 | where |
50 | F: Fn(&mut dyn ra_parser::TokenSource, &mut dyn ra_parser::TreeSink), | 50 | F: Fn(&mut dyn ra_parser::TokenSource, &mut dyn ra_parser::TreeSink), |
51 | { | 51 | { |
@@ -58,50 +58,44 @@ where | |||
58 | return Err(ExpandError::ConversionError); | 58 | return Err(ExpandError::ConversionError); |
59 | } | 59 | } |
60 | //FIXME: would be cool to report errors | 60 | //FIXME: would be cool to report errors |
61 | let (tree, _errors) = tree_sink.inner.finish(); | 61 | let parse = tree_sink.inner.finish(); |
62 | Ok(tree) | 62 | Ok(parse) |
63 | } | 63 | } |
64 | 64 | ||
65 | /// Parses the token tree (result of macro expansion) to an expression | 65 | /// Parses the token tree (result of macro expansion) to an expression |
66 | pub fn token_tree_to_expr(tt: &tt::Subtree) -> Result<TreeArc<ast::Expr>, ExpandError> { | 66 | pub fn token_tree_to_expr(tt: &tt::Subtree) -> Result<Parse<ast::Expr>, ExpandError> { |
67 | let syntax = token_tree_to_syntax_node(tt, ra_parser::parse_expr)?; | 67 | let parse = token_tree_to_syntax_node(tt, ra_parser::parse_expr)?; |
68 | ast::Expr::cast(&syntax) | 68 | parse.cast().ok_or_else(|| crate::ExpandError::ConversionError) |
69 | .map(|m| m.to_owned()) | ||
70 | .ok_or_else(|| crate::ExpandError::ConversionError) | ||
71 | } | 69 | } |
72 | 70 | ||
73 | /// Parses the token tree (result of macro expansion) to a Pattern | 71 | /// Parses the token tree (result of macro expansion) to a Pattern |
74 | pub fn token_tree_to_pat(tt: &tt::Subtree) -> Result<TreeArc<ast::Pat>, ExpandError> { | 72 | pub fn token_tree_to_pat(tt: &tt::Subtree) -> Result<Parse<ast::Pat>, ExpandError> { |
75 | let syntax = token_tree_to_syntax_node(tt, ra_parser::parse_pat)?; | 73 | let parse = token_tree_to_syntax_node(tt, ra_parser::parse_pat)?; |
76 | ast::Pat::cast(&syntax).map(|m| m.to_owned()).ok_or_else(|| ExpandError::ConversionError) | 74 | parse.cast().ok_or_else(|| crate::ExpandError::ConversionError) |
77 | } | 75 | } |
78 | 76 | ||
79 | /// Parses the token tree (result of macro expansion) to a Type | 77 | /// Parses the token tree (result of macro expansion) to a Type |
80 | pub fn token_tree_to_ty(tt: &tt::Subtree) -> Result<TreeArc<ast::TypeRef>, ExpandError> { | 78 | pub fn token_tree_to_ty(tt: &tt::Subtree) -> Result<Parse<ast::TypeRef>, ExpandError> { |
81 | let syntax = token_tree_to_syntax_node(tt, ra_parser::parse_ty)?; | 79 | let parse = token_tree_to_syntax_node(tt, ra_parser::parse_ty)?; |
82 | ast::TypeRef::cast(&syntax).map(|m| m.to_owned()).ok_or_else(|| ExpandError::ConversionError) | 80 | parse.cast().ok_or_else(|| crate::ExpandError::ConversionError) |
83 | } | 81 | } |
84 | 82 | ||
85 | /// Parses the token tree (result of macro expansion) as a sequence of stmts | 83 | /// Parses the token tree (result of macro expansion) as a sequence of stmts |
86 | pub fn token_tree_to_macro_stmts( | 84 | pub fn token_tree_to_macro_stmts(tt: &tt::Subtree) -> Result<Parse<ast::MacroStmts>, ExpandError> { |
87 | tt: &tt::Subtree, | 85 | let parse = token_tree_to_syntax_node(tt, ra_parser::parse_macro_stmts)?; |
88 | ) -> Result<TreeArc<ast::MacroStmts>, ExpandError> { | 86 | parse.cast().ok_or_else(|| crate::ExpandError::ConversionError) |
89 | let syntax = token_tree_to_syntax_node(tt, ra_parser::parse_macro_stmts)?; | ||
90 | ast::MacroStmts::cast(&syntax).map(|m| m.to_owned()).ok_or_else(|| ExpandError::ConversionError) | ||
91 | } | 87 | } |
92 | 88 | ||
93 | /// Parses the token tree (result of macro expansion) as a sequence of items | 89 | /// Parses the token tree (result of macro expansion) as a sequence of items |
94 | pub fn token_tree_to_macro_items( | 90 | pub fn token_tree_to_macro_items(tt: &tt::Subtree) -> Result<Parse<ast::MacroItems>, ExpandError> { |
95 | tt: &tt::Subtree, | 91 | let parse = token_tree_to_syntax_node(tt, ra_parser::parse_macro_items)?; |
96 | ) -> Result<TreeArc<ast::MacroItems>, ExpandError> { | 92 | parse.cast().ok_or_else(|| crate::ExpandError::ConversionError) |
97 | let syntax = token_tree_to_syntax_node(tt, ra_parser::parse_macro_items)?; | ||
98 | ast::MacroItems::cast(&syntax).map(|m| m.to_owned()).ok_or_else(|| ExpandError::ConversionError) | ||
99 | } | 93 | } |
100 | 94 | ||
101 | /// Parses the token tree (result of macro expansion) as a sequence of items | 95 | /// Parses the token tree (result of macro expansion) as a sequence of items |
102 | pub fn token_tree_to_ast_item_list(tt: &tt::Subtree) -> TreeArc<ast::SourceFile> { | 96 | pub fn token_tree_to_ast_item_list(tt: &tt::Subtree) -> Parse<ast::SourceFile> { |
103 | let syntax = token_tree_to_syntax_node(tt, ra_parser::parse).unwrap(); | 97 | let parse = token_tree_to_syntax_node(tt, ra_parser::parse).unwrap(); |
104 | ast::SourceFile::cast(&syntax).unwrap().to_owned() | 98 | parse.cast().unwrap() |
105 | } | 99 | } |
106 | 100 | ||
107 | impl TokenMap { | 101 | impl TokenMap { |
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index 5a1494fee..419b2c099 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs | |||
@@ -72,7 +72,7 @@ pub(crate) fn expand_to_items( | |||
72 | invocation: &str, | 72 | invocation: &str, |
73 | ) -> ra_syntax::TreeArc<ast::MacroItems> { | 73 | ) -> ra_syntax::TreeArc<ast::MacroItems> { |
74 | let expanded = expand(rules, invocation); | 74 | let expanded = expand(rules, invocation); |
75 | token_tree_to_macro_items(&expanded).unwrap() | 75 | token_tree_to_macro_items(&expanded).unwrap().tree().to_owned() |
76 | } | 76 | } |
77 | 77 | ||
78 | #[allow(unused)] | 78 | #[allow(unused)] |
@@ -81,7 +81,7 @@ pub(crate) fn expand_to_stmts( | |||
81 | invocation: &str, | 81 | invocation: &str, |
82 | ) -> ra_syntax::TreeArc<ast::MacroStmts> { | 82 | ) -> ra_syntax::TreeArc<ast::MacroStmts> { |
83 | let expanded = expand(rules, invocation); | 83 | let expanded = expand(rules, invocation); |
84 | token_tree_to_macro_stmts(&expanded).unwrap() | 84 | token_tree_to_macro_stmts(&expanded).unwrap().tree().to_owned() |
85 | } | 85 | } |
86 | 86 | ||
87 | pub(crate) fn expand_to_expr( | 87 | pub(crate) fn expand_to_expr( |
@@ -89,7 +89,7 @@ pub(crate) fn expand_to_expr( | |||
89 | invocation: &str, | 89 | invocation: &str, |
90 | ) -> ra_syntax::TreeArc<ast::Expr> { | 90 | ) -> ra_syntax::TreeArc<ast::Expr> { |
91 | let expanded = expand(rules, invocation); | 91 | let expanded = expand(rules, invocation); |
92 | token_tree_to_expr(&expanded).unwrap() | 92 | token_tree_to_expr(&expanded).unwrap().tree().to_owned() |
93 | } | 93 | } |
94 | 94 | ||
95 | pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree { | 95 | pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree { |
@@ -164,22 +164,22 @@ pub(crate) fn assert_expansion( | |||
164 | 164 | ||
165 | let (expanded_tree, expected_tree) = match kind { | 165 | let (expanded_tree, expected_tree) = match kind { |
166 | MacroKind::Items => { | 166 | MacroKind::Items => { |
167 | let expanded_tree = token_tree_to_macro_items(&expanded); | 167 | let expanded_tree = token_tree_to_macro_items(&expanded).unwrap().tree().to_owned(); |
168 | let expected_tree = token_tree_to_macro_items(&expected); | 168 | let expected_tree = token_tree_to_macro_items(&expected).unwrap().tree().to_owned(); |
169 | 169 | ||
170 | ( | 170 | ( |
171 | debug_dump_ignore_spaces(expanded_tree.unwrap().syntax()).trim().to_string(), | 171 | debug_dump_ignore_spaces(expanded_tree.syntax()).trim().to_string(), |
172 | debug_dump_ignore_spaces(expected_tree.unwrap().syntax()).trim().to_string(), | 172 | debug_dump_ignore_spaces(expected_tree.syntax()).trim().to_string(), |
173 | ) | 173 | ) |
174 | } | 174 | } |
175 | 175 | ||
176 | MacroKind::Stmts => { | 176 | MacroKind::Stmts => { |
177 | let expanded_tree = token_tree_to_macro_stmts(&expanded); | 177 | let expanded_tree = token_tree_to_macro_stmts(&expanded).unwrap().tree().to_owned(); |
178 | let expected_tree = token_tree_to_macro_stmts(&expected); | 178 | let expected_tree = token_tree_to_macro_stmts(&expected).unwrap().tree().to_owned(); |
179 | 179 | ||
180 | ( | 180 | ( |
181 | debug_dump_ignore_spaces(expanded_tree.unwrap().syntax()).trim().to_string(), | 181 | debug_dump_ignore_spaces(expanded_tree.syntax()).trim().to_string(), |
182 | debug_dump_ignore_spaces(expected_tree.unwrap().syntax()).trim().to_string(), | 182 | debug_dump_ignore_spaces(expected_tree.syntax()).trim().to_string(), |
183 | ) | 183 | ) |
184 | } | 184 | } |
185 | }; | 185 | }; |
@@ -419,9 +419,9 @@ fn test_expand_to_item_list() { | |||
419 | ", | 419 | ", |
420 | ); | 420 | ); |
421 | let expansion = expand(&rules, "structs!(Foo, Bar);"); | 421 | let expansion = expand(&rules, "structs!(Foo, Bar);"); |
422 | let tree = token_tree_to_macro_items(&expansion); | 422 | let tree = token_tree_to_macro_items(&expansion).unwrap().tree().to_owned(); |
423 | assert_eq!( | 423 | assert_eq!( |
424 | tree.unwrap().syntax().debug_dump().trim(), | 424 | tree.syntax().debug_dump().trim(), |
425 | r#" | 425 | r#" |
426 | MACRO_ITEMS@[0; 40) | 426 | MACRO_ITEMS@[0; 40) |
427 | STRUCT_DEF@[0; 20) | 427 | STRUCT_DEF@[0; 20) |
@@ -537,10 +537,10 @@ fn test_tt_to_stmts() { | |||
537 | ); | 537 | ); |
538 | 538 | ||
539 | let expanded = expand(&rules, "foo!{}"); | 539 | let expanded = expand(&rules, "foo!{}"); |
540 | let stmts = token_tree_to_macro_stmts(&expanded); | 540 | let stmts = token_tree_to_macro_stmts(&expanded).unwrap().tree().to_owned(); |
541 | 541 | ||
542 | assert_eq!( | 542 | assert_eq!( |
543 | stmts.unwrap().syntax().debug_dump().trim(), | 543 | stmts.syntax().debug_dump().trim(), |
544 | r#"MACRO_STMTS@[0; 15) | 544 | r#"MACRO_STMTS@[0; 15) |
545 | LET_STMT@[0; 7) | 545 | LET_STMT@[0; 7) |
546 | LET_KW@[0; 3) "let" | 546 | LET_KW@[0; 3) "let" |
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 | ||
36 | use ra_text_edit::AtomTextEdit; | 36 | use ra_text_edit::AtomTextEdit; |
37 | 37 | ||
38 | use crate::syntax_node::{GreenNode, SyntaxNodeWrapper}; | 38 | use crate::syntax_node::GreenNode; |
39 | 39 | ||
40 | pub use crate::{ | 40 | pub 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 | ||
94 | impl<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 | |||
94 | impl Parse<SourceFile> { | 100 | impl 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 | ||
19 | use crate::{ | 19 | use 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 | ||
24 | pub use rowan::WalkEvent; | 25 | pub 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) { |