aboutsummaryrefslogtreecommitdiff
path: root/libeditor/src
diff options
context:
space:
mode:
Diffstat (limited to 'libeditor/src')
-rw-r--r--libeditor/src/lib.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/libeditor/src/lib.rs b/libeditor/src/lib.rs
index ebc063ed2..5ebb49139 100644
--- a/libeditor/src/lib.rs
+++ b/libeditor/src/lib.rs
@@ -20,6 +20,12 @@ pub struct HighlightedRange {
20} 20}
21 21
22#[derive(Debug)] 22#[derive(Debug)]
23pub struct Diagnostic {
24 pub range: TextRange,
25 pub msg: String,
26}
27
28#[derive(Debug)]
23pub struct Symbol { 29pub struct Symbol {
24 // pub parent: ???, 30 // pub parent: ???,
25 pub name: String, 31 pub name: String,
@@ -69,6 +75,25 @@ impl File {
69 res 75 res
70 } 76 }
71 77
78 pub fn diagnostics(&self) -> Vec<Diagnostic> {
79 let syntax = self.inner.syntax();
80 let mut res = Vec::new();
81
82 for node in walk::preorder(syntax.as_ref()) {
83 if node.kind() == ERROR {
84 res.push(Diagnostic {
85 range: node.range(),
86 msg: "Syntax Error".to_string(),
87 });
88 }
89 }
90 res.extend(self.inner.errors().into_iter().map(|err| Diagnostic {
91 range: TextRange::offset_len(err.offset, 1.into()),
92 msg: err.msg,
93 }));
94 res
95 }
96
72 pub fn syntax_tree(&self) -> String { 97 pub fn syntax_tree(&self) -> String {
73 ::libsyntax2::utils::dump_tree(&self.inner.syntax()) 98 ::libsyntax2::utils::dump_tree(&self.inner.syntax())
74 } 99 }