Skip to main content

plc_diagnostics/
reporter.rs

1use plc_source::source_location::CodeSpan;
2
3use crate::diagnostics::Severity;
4
5pub mod clang;
6pub mod codespan;
7pub mod null;
8
9/// the DiagnosticReporter decides on the format and where to report the diagnostic to.
10/// possible implementations could print to either std-out, std-err or a file, etc.
11pub trait DiagnosticReporter {
12    /// reports the given diagnostic
13    fn report(&mut self, diagnostics: &[ResolvedDiagnostics]);
14    /// register the given path & src and returns an ID to indicate
15    /// a relationship the given src (diagnostics for this src need
16    /// to use this id)
17    fn register(&mut self, path: String, src: String) -> usize;
18
19    fn buffer(&self) -> Option<String> {
20        None
21    }
22}
23
24#[derive(Clone, Debug, PartialEq, Eq)]
25pub struct ResolvedLocation {
26    pub file_handle: usize,
27    pub span: CodeSpan,
28}
29
30impl ResolvedLocation {
31    pub(crate) fn is_internal(&self) -> bool {
32        self.span == CodeSpan::None
33    }
34}
35
36#[derive(Clone, Debug, PartialEq, Eq)]
37pub struct ResolvedDiagnostics {
38    pub code: String,
39    pub message: String,
40    pub severity: Severity,
41    pub main_location: ResolvedLocation,
42    pub additional_locations: Option<Vec<ResolvedLocation>>,
43}