aboutsummaryrefslogtreecommitdiff
path: root/libeditor/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-09 19:27:44 +0100
committerAleksey Kladov <[email protected]>2018-08-09 19:27:44 +0100
commit4a900fd6815d3ea722b5e664aee9eac8bb9cb14f (patch)
tree48dddd52ed4ed5e9cf28504d2c3b8d8a1dd8c27e /libeditor/src/lib.rs
parentafa94d4f37b9a0a1e723edffcc79c3d48799bad1 (diff)
Split diagnostics
Diffstat (limited to 'libeditor/src/lib.rs')
-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 }