pub struct MultiFileJsonFormatter<'a> { /* private fields */ }Expand description
Formats diagnostics as JSON for machine consumption.
Maps FileIds to their source information, enabling correct file path and line/column output for diagnostics spanning one or more files.
§Example
ⓘ
use gruel_compiler::{MultiFileJsonFormatter, SourceInfo, FileId};
let sources = vec![
(FileId::new(1), SourceInfo::new(&source1, "main.gruel")),
(FileId::new(2), SourceInfo::new(&source2, "utils.gruel")),
];
let formatter = MultiFileJsonFormatter::new(sources);
let json = formatter.format_error(&error).to_json();Implementations§
Source§impl<'a> MultiFileJsonFormatter<'a>
impl<'a> MultiFileJsonFormatter<'a>
Sourcepub fn new(sources: impl IntoIterator<Item = (FileId, SourceInfo<'a>)>) -> Self
pub fn new(sources: impl IntoIterator<Item = (FileId, SourceInfo<'a>)>) -> Self
Create a new multi-file JSON diagnostic formatter.
Sourcepub fn format_error(&self, error: &CompileError) -> JsonDiagnostic
pub fn format_error(&self, error: &CompileError) -> JsonDiagnostic
Format a compile error as JSON.
Sourcepub fn format_warning(&self, warning: &CompileWarning) -> JsonDiagnostic
pub fn format_warning(&self, warning: &CompileWarning) -> JsonDiagnostic
Format a compile warning as JSON.
Sourcepub fn format_errors(&self, errors: &CompileErrors) -> String
pub fn format_errors(&self, errors: &CompileErrors) -> String
Format multiple errors as a JSON array string.
Sourcepub fn format_warnings(&self, warnings: &[CompileWarning]) -> String
pub fn format_warnings(&self, warnings: &[CompileWarning]) -> String
Format multiple warnings as a JSON array string.
Auto Trait Implementations§
impl<'a> Freeze for MultiFileJsonFormatter<'a>
impl<'a> RefUnwindSafe for MultiFileJsonFormatter<'a>
impl<'a> Send for MultiFileJsonFormatter<'a>
impl<'a> Sync for MultiFileJsonFormatter<'a>
impl<'a> Unpin for MultiFileJsonFormatter<'a>
impl<'a> UnwindSafe for MultiFileJsonFormatter<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more