Split diagnostics
This commit is contained in:
parent
afa94d4f37
commit
4a900fd681
@ -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<Diagnostic> {
|
||||
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())
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ mod generated;
|
||||
|
||||
use std::sync::Arc;
|
||||
use {
|
||||
SyntaxNode, SyntaxRoot, TreeRoot,
|
||||
SyntaxNode, SyntaxRoot, TreeRoot, SyntaxError,
|
||||
SyntaxKind::*,
|
||||
};
|
||||
pub use self::generated::*;
|
||||
@ -19,6 +19,10 @@ impl File<Arc<SyntaxRoot>> {
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> File<R> {
|
||||
pub fn errors(&self) -> Vec<SyntaxError> {
|
||||
self.syntax().root.errors.clone()
|
||||
}
|
||||
|
||||
pub fn functions<'a>(&'a self) -> impl Iterator<Item = Function<R>> + 'a {
|
||||
self.syntax()
|
||||
.children()
|
||||
|
@ -45,7 +45,7 @@ pub use {
|
||||
lexer::{tokenize, Token},
|
||||
syntax_kinds::SyntaxKind,
|
||||
text_unit::{TextRange, TextUnit},
|
||||
yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot},
|
||||
yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot, SyntaxError},
|
||||
};
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String {
|
||||
let off = node.range().end();
|
||||
while err_pos < errors.len() && errors[err_pos].offset <= off {
|
||||
indent!();
|
||||
writeln!(buf, "err: `{}`", errors[err_pos].message).unwrap();
|
||||
writeln!(buf, "err: `{}`", errors[err_pos].msg).unwrap();
|
||||
err_pos += 1;
|
||||
}
|
||||
}
|
||||
@ -41,7 +41,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String {
|
||||
|
||||
assert_eq!(level, 0);
|
||||
for err in errors[err_pos..].iter() {
|
||||
writeln!(buf, "err: `{}`", err.message).unwrap();
|
||||
writeln!(buf, "err: `{}`", err.msg).unwrap();
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
@ -51,7 +51,7 @@ impl<'a> Sink<'a> for GreenBuilder<'a> {
|
||||
|
||||
fn error(&mut self, message: String) {
|
||||
self.errors.push(SyntaxError {
|
||||
message,
|
||||
msg: message,
|
||||
offset: self.pos,
|
||||
})
|
||||
}
|
||||
|
@ -3,10 +3,9 @@ mod green;
|
||||
mod red;
|
||||
mod syntax;
|
||||
|
||||
pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot};
|
||||
pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot, SyntaxError};
|
||||
pub(crate) use self::{
|
||||
builder::GreenBuilder,
|
||||
green::GreenNode,
|
||||
red::RedNode,
|
||||
syntax::SyntaxError,
|
||||
};
|
||||
|
@ -46,9 +46,9 @@ impl SyntaxRoot {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||
pub(crate) struct SyntaxError {
|
||||
pub(crate) message: String,
|
||||
pub(crate) offset: TextUnit,
|
||||
pub struct SyntaxError {
|
||||
pub msg: String,
|
||||
pub offset: TextUnit,
|
||||
}
|
||||
|
||||
impl SyntaxNode<Arc<SyntaxRoot>> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user