use rowan::TextRange;
use crate::{Diagnostic, DiagnosticCode, FileId};
pub struct LowerScope {
pub file_id: FileId,
pub current_knot: Option<String>,
pub current_stitch: Option<String>,
}
impl LowerScope {
pub fn new(file_id: FileId) -> Self {
Self {
file_id,
current_knot: None,
current_stitch: None,
}
}
pub fn prov(
&self,
class: crate::provenance::NodeClass,
syntax: &brink_syntax::SyntaxNode,
) -> crate::Provenance {
crate::hir::ink_provenance(self.file_id, class, syntax)
}
}
pub struct Diagnosed {
_private: (),
}
impl Diagnosed {
#[cfg(test)]
pub fn test_token() -> Self {
Self { _private: () }
}
}
pub type Lowered<T> = Result<T, Diagnosed>;
pub trait LowerSink {
fn diagnose(&mut self, range: TextRange, code: DiagnosticCode) -> Diagnosed;
}
pub struct EffectSink {
file_id: FileId,
pub diagnostics: Vec<Diagnostic>,
}
impl EffectSink {
pub fn new(file_id: FileId) -> Self {
Self {
file_id,
diagnostics: Vec::new(),
}
}
pub fn finish(self) -> Vec<Diagnostic> {
self.diagnostics
}
pub fn diagnose_with_message(
&mut self,
range: TextRange,
message: String,
code: DiagnosticCode,
) {
self.diagnostics.push(Diagnostic {
file: self.file_id,
range,
message,
code,
});
}
}
impl LowerSink for EffectSink {
fn diagnose(&mut self, range: TextRange, code: DiagnosticCode) -> Diagnosed {
self.diagnostics.push(Diagnostic {
file: self.file_id,
range,
message: code.title().to_string(),
code,
});
Diagnosed { _private: () }
}
}