diff options
Diffstat (limited to 'crates/ra_syntax/src/utils.rs')
-rw-r--r-- | crates/ra_syntax/src/utils.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 5bbdf80bb..0a2b6afbc 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs | |||
@@ -1,10 +1,13 @@ | |||
1 | use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent}; | 1 | use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent, AstNode}; |
2 | use std::fmt::Write; | 2 | use std::fmt::Write; |
3 | use std::str; | 3 | use std::str; |
4 | 4 | ||
5 | /// Parse a file and create a string representation of the resulting parse tree. | 5 | /// Parse a file and create a string representation of the resulting parse tree. |
6 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | 6 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { |
7 | let mut errors: Vec<_> = syntax.root_data().to_vec(); | 7 | let mut errors: Vec<_> = match syntax.ancestors().find_map(SourceFileNode::cast) { |
8 | Some(file) => file.owned().errors(), | ||
9 | None => syntax.root_data().to_vec(), | ||
10 | }; | ||
8 | errors.sort_by_key(|e| e.offset()); | 11 | errors.sort_by_key(|e| e.offset()); |
9 | let mut err_pos = 0; | 12 | let mut err_pos = 0; |
10 | let mut level = 0; | 13 | let mut level = 0; |