diff options
author | Aleksey Kladov <[email protected]> | 2018-08-09 19:27:44 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-09 19:27:44 +0100 |
commit | 4a900fd6815d3ea722b5e664aee9eac8bb9cb14f (patch) | |
tree | 48dddd52ed4ed5e9cf28504d2c3b8d8a1dd8c27e | |
parent | afa94d4f37b9a0a1e723edffcc79c3d48799bad1 (diff) |
Split diagnostics
-rw-r--r-- | libeditor/src/lib.rs | 25 | ||||
-rw-r--r-- | src/ast/mod.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/utils.rs | 4 | ||||
-rw-r--r-- | src/yellow/builder.rs | 2 | ||||
-rw-r--r-- | src/yellow/mod.rs | 3 | ||||
-rw-r--r-- | src/yellow/syntax.rs | 6 |
7 files changed, 38 insertions, 10 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)] |
23 | pub struct Diagnostic { | ||
24 | pub range: TextRange, | ||
25 | pub msg: String, | ||
26 | } | ||
27 | |||
28 | #[derive(Debug)] | ||
23 | pub struct Symbol { | 29 | pub 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 | } |
diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 317ed4f45..eeb7ae6f6 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs | |||
@@ -2,7 +2,7 @@ mod generated; | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | use { | 4 | use { |
5 | SyntaxNode, SyntaxRoot, TreeRoot, | 5 | SyntaxNode, SyntaxRoot, TreeRoot, SyntaxError, |
6 | SyntaxKind::*, | 6 | SyntaxKind::*, |
7 | }; | 7 | }; |
8 | pub use self::generated::*; | 8 | pub use self::generated::*; |
@@ -19,6 +19,10 @@ impl File<Arc<SyntaxRoot>> { | |||
19 | } | 19 | } |
20 | 20 | ||
21 | impl<R: TreeRoot> File<R> { | 21 | impl<R: TreeRoot> File<R> { |
22 | pub fn errors(&self) -> Vec<SyntaxError> { | ||
23 | self.syntax().root.errors.clone() | ||
24 | } | ||
25 | |||
22 | pub fn functions<'a>(&'a self) -> impl Iterator<Item = Function<R>> + 'a { | 26 | pub fn functions<'a>(&'a self) -> impl Iterator<Item = Function<R>> + 'a { |
23 | self.syntax() | 27 | self.syntax() |
24 | .children() | 28 | .children() |
diff --git a/src/lib.rs b/src/lib.rs index d1e690bb2..ca33618a0 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
@@ -45,7 +45,7 @@ pub use { | |||
45 | lexer::{tokenize, Token}, | 45 | lexer::{tokenize, Token}, |
46 | syntax_kinds::SyntaxKind, | 46 | syntax_kinds::SyntaxKind, |
47 | text_unit::{TextRange, TextUnit}, | 47 | text_unit::{TextRange, TextUnit}, |
48 | yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot}, | 48 | yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot, SyntaxError}, |
49 | }; | 49 | }; |
50 | 50 | ||
51 | 51 | ||
diff --git a/src/utils.rs b/src/utils.rs index a23a57423..1fbb872a5 100644 --- a/src/utils.rs +++ b/src/utils.rs | |||
@@ -29,7 +29,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String { | |||
29 | let off = node.range().end(); | 29 | let off = node.range().end(); |
30 | while err_pos < errors.len() && errors[err_pos].offset <= off { | 30 | while err_pos < errors.len() && errors[err_pos].offset <= off { |
31 | indent!(); | 31 | indent!(); |
32 | writeln!(buf, "err: `{}`", errors[err_pos].message).unwrap(); | 32 | writeln!(buf, "err: `{}`", errors[err_pos].msg).unwrap(); |
33 | err_pos += 1; | 33 | err_pos += 1; |
34 | } | 34 | } |
35 | } | 35 | } |
@@ -41,7 +41,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String { | |||
41 | 41 | ||
42 | assert_eq!(level, 0); | 42 | assert_eq!(level, 0); |
43 | for err in errors[err_pos..].iter() { | 43 | for err in errors[err_pos..].iter() { |
44 | writeln!(buf, "err: `{}`", err.message).unwrap(); | 44 | writeln!(buf, "err: `{}`", err.msg).unwrap(); |
45 | } | 45 | } |
46 | 46 | ||
47 | return buf; | 47 | return buf; |
diff --git a/src/yellow/builder.rs b/src/yellow/builder.rs index 878f3ba39..5e94e5055 100644 --- a/src/yellow/builder.rs +++ b/src/yellow/builder.rs | |||
@@ -51,7 +51,7 @@ impl<'a> Sink<'a> for GreenBuilder<'a> { | |||
51 | 51 | ||
52 | fn error(&mut self, message: String) { | 52 | fn error(&mut self, message: String) { |
53 | self.errors.push(SyntaxError { | 53 | self.errors.push(SyntaxError { |
54 | message, | 54 | msg: message, |
55 | offset: self.pos, | 55 | offset: self.pos, |
56 | }) | 56 | }) |
57 | } | 57 | } |
diff --git a/src/yellow/mod.rs b/src/yellow/mod.rs index 1b5d4e4df..6129ecb99 100644 --- a/src/yellow/mod.rs +++ b/src/yellow/mod.rs | |||
@@ -3,10 +3,9 @@ mod green; | |||
3 | mod red; | 3 | mod red; |
4 | mod syntax; | 4 | mod syntax; |
5 | 5 | ||
6 | pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot}; | 6 | pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot, SyntaxError}; |
7 | pub(crate) use self::{ | 7 | pub(crate) use self::{ |
8 | builder::GreenBuilder, | 8 | builder::GreenBuilder, |
9 | green::GreenNode, | 9 | green::GreenNode, |
10 | red::RedNode, | 10 | red::RedNode, |
11 | syntax::SyntaxError, | ||
12 | }; | 11 | }; |
diff --git a/src/yellow/syntax.rs b/src/yellow/syntax.rs index 07607ec2d..2ba9281fc 100644 --- a/src/yellow/syntax.rs +++ b/src/yellow/syntax.rs | |||
@@ -46,9 +46,9 @@ impl SyntaxRoot { | |||
46 | } | 46 | } |
47 | 47 | ||
48 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] | 48 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] |
49 | pub(crate) struct SyntaxError { | 49 | pub struct SyntaxError { |
50 | pub(crate) message: String, | 50 | pub msg: String, |
51 | pub(crate) offset: TextUnit, | 51 | pub offset: TextUnit, |
52 | } | 52 | } |
53 | 53 | ||
54 | impl SyntaxNode<Arc<SyntaxRoot>> { | 54 | impl SyntaxNode<Arc<SyntaxRoot>> { |