pub struct MultiFileFormatter<'a> { /* private fields */ }Expand description
A diagnostic formatter that supports diagnostics spanning one or more source files.
Renders errors and warnings as human-readable text with annotated source snippets. For multi-file compilation, errors that reference multiple files will show each file’s snippet separately.
§Example
use gruel_compiler::{MultiFileFormatter, SourceInfo, FileId};
// Create source infos for each file
let sources = vec![
(FileId::new(1), SourceInfo::new(&source1, "main.gruel")),
(FileId::new(2), SourceInfo::new(&source2, "utils.gruel")),
];
let formatter = MultiFileFormatter::new(sources);
let error_output = formatter.format_error(&error);
eprintln!("{}", error_output);Implementations§
Source§impl<'a> MultiFileFormatter<'a>
impl<'a> MultiFileFormatter<'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 formatter from an iterator of (FileId, SourceInfo) pairs.
By default, uses automatic color detection based on whether stderr is a terminal.
Sourcepub fn with_color_choice(
sources: impl IntoIterator<Item = (FileId, SourceInfo<'a>)>,
color_choice: ColorChoice,
) -> Self
pub fn with_color_choice( sources: impl IntoIterator<Item = (FileId, SourceInfo<'a>)>, color_choice: ColorChoice, ) -> Self
Create a new multi-file formatter with explicit color choice.
Sourcepub fn format_error(&self, error: &CompileError) -> String
pub fn format_error(&self, error: &CompileError) -> String
Format a compilation error into a string.
The error is formatted with its error code, e.g.:
error[E0206]: type mismatch: expected i32, found bool
If the error or its labels reference multiple files, each file’s snippet is shown separately.
Internal compiler errors (ICEs) receive special formatting with bug report instructions.
Sourcepub fn format_errors(&self, errors: &CompileErrors) -> String
pub fn format_errors(&self, errors: &CompileErrors) -> String
Format multiple compilation errors into a string.
Each error is formatted on its own line(s). A summary line is added at the end if there are multiple errors showing the total count.
Sourcepub fn format_warnings(&self, warnings: &[CompileWarning]) -> String
pub fn format_warnings(&self, warnings: &[CompileWarning]) -> String
Format all warnings, adding line numbers when multiple variables share the same name.
Sourcepub fn format_warning(&self, warning: &CompileWarning) -> String
pub fn format_warning(&self, warning: &CompileWarning) -> String
Format a single warning into a string.
Auto Trait Implementations§
impl<'a> Freeze for MultiFileFormatter<'a>
impl<'a> RefUnwindSafe for MultiFileFormatter<'a>
impl<'a> Send for MultiFileFormatter<'a>
impl<'a> Sync for MultiFileFormatter<'a>
impl<'a> Unpin for MultiFileFormatter<'a>
impl<'a> UnwindSafe for MultiFileFormatter<'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
§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>
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>
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