mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Error builder
This commit is contained in:
parent
50132db4c6
commit
8671a892c5
1 changed files with 28 additions and 1 deletions
|
@ -5,6 +5,7 @@ pub trait Sink {
|
||||||
fn leaf(&mut self, kind: SyntaxKind, len: TextUnit);
|
fn leaf(&mut self, kind: SyntaxKind, len: TextUnit);
|
||||||
fn start_internal(&mut self, kind: SyntaxKind);
|
fn start_internal(&mut self, kind: SyntaxKind);
|
||||||
fn finish_internal(&mut self);
|
fn finish_internal(&mut self);
|
||||||
|
fn error(&mut self) -> ErrorBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,6 +53,10 @@ impl Sink for FileBuilder {
|
||||||
self.add_len(id);
|
self.add_len(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn error(&mut self) -> ErrorBuilder {
|
||||||
|
ErrorBuilder::new(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileBuilder {
|
impl FileBuilder {
|
||||||
|
@ -133,3 +138,25 @@ fn grow(left: &mut TextRange, right: TextRange) {
|
||||||
assert_eq!(left.end(), right.start());
|
assert_eq!(left.end(), right.start());
|
||||||
*left = TextRange::from_to(left.start(), right.end())
|
*left = TextRange::from_to(left.start(), right.end())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ErrorBuilder<'f> {
|
||||||
|
message: Option<String>,
|
||||||
|
builder: &'f mut FileBuilder
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'f> ErrorBuilder<'f> {
|
||||||
|
fn new(builder: &'f mut FileBuilder) -> Self {
|
||||||
|
ErrorBuilder { message: None, builder }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn message<M: Into<String>>(mut self, m: M) -> Self {
|
||||||
|
self.message = Some(m.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(self) {
|
||||||
|
let message = self.message.expect("Error message not set");
|
||||||
|
let node = self.builder.current_id();
|
||||||
|
self.builder.errors.push(SyntaxErrorData { node, message })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue