From 4a900fd6815d3ea722b5e664aee9eac8bb9cb14f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Aug 2018 21:27:44 +0300 Subject: Split diagnostics --- libeditor/src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libeditor') 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 @@ -19,6 +19,12 @@ pub struct HighlightedRange { pub tag: &'static str, } +#[derive(Debug)] +pub struct Diagnostic { + pub range: TextRange, + pub msg: String, +} + #[derive(Debug)] pub struct Symbol { // pub parent: ???, @@ -69,6 +75,25 @@ impl File { res } + pub fn diagnostics(&self) -> Vec { + let syntax = self.inner.syntax(); + let mut res = Vec::new(); + + for node in walk::preorder(syntax.as_ref()) { + if node.kind() == ERROR { + res.push(Diagnostic { + range: node.range(), + msg: "Syntax Error".to_string(), + }); + } + } + res.extend(self.inner.errors().into_iter().map(|err| Diagnostic { + range: TextRange::offset_len(err.offset, 1.into()), + msg: err.msg, + })); + res + } + pub fn syntax_tree(&self) -> String { ::libsyntax2::utils::dump_tree(&self.inner.syntax()) } -- cgit v1.2.3