Expand description
Error reporting and diagnostics for BHC.
This crate provides rich error reporting with source code snippets, suggestions, and structured diagnostic output in the style of Rust/Cargo.
§Features
- Cargo-style terminal output with colors and underlines
- Machine-readable JSON diagnostic format
- Error code explanations via
--explain - Multi-line span support with context
§Example
ⓘ
use bhc_diagnostics::{Diagnostic, SourceMap, CargoRenderer};
let mut sm = SourceMap::new();
sm.add_file("test.hs".into(), "foo = x + 1".into());
let diag = Diagnostic::error("undefined variable")
.with_code("E0003")
.with_label(span, "not found in scope");
let renderer = CargoRenderer::new(&sm);
renderer.render_all(&[diag]);Re-exports§
pub use explain::all_error_codes;pub use explain::format_explanation;pub use explain::get_explanation;pub use explain::print_explanation;pub use json::diagnostic_to_json;pub use json::diagnostics_to_json;pub use json::to_json_lines;pub use json::to_json_string;pub use json::JsonApplicability;pub use json::JsonDiagnostic;pub use json::JsonSeverity;pub use json::JsonSpan;pub use json::JsonSuggestion;pub use lsp::publish_diagnostics;pub use lsp::to_code_actions;pub use lsp::to_hover;pub use lsp::to_lsp_diagnostic;pub use lsp::to_lsp_diagnostics;pub use lsp::LspCodeAction;pub use lsp::LspDiagnostic;pub use lsp::LspHover;pub use lsp::LspRange;pub use lsp::LspSeverity;pub use lsp::LspTextEdit;pub use lsp::PublishDiagnosticsParams;pub use render::colors;pub use render::CargoRenderer;pub use render::RenderConfig;
Modules§
- explain
- Error code explanations.
- json
- JSON diagnostic output format.
- lsp
- Language Server Protocol (LSP) integration for BHC diagnostics.
- render
- Cargo-style diagnostic rendering.
Structs§
- Diagnostic
- A diagnostic message with source locations and suggestions.
- Diagnostic
Handler - A handler for collecting and emitting diagnostics.
- Diagnostic
Renderer - Render diagnostics to a writer.
- Full
Span - A span with an associated file ID for cross-file spans.
- Label
- A labeled span for diagnostics.
- Source
Map - A source map for looking up files and locations.
- Span
- A span of source code, represented as a half-open byte range [lo, hi).
- Suggestion
- A suggested fix for a diagnostic.
Enums§
- Applicability
- How applicable a suggestion is.
- Severity
- The severity level of a diagnostic.
Traits§
- Into
Diagnostic - Trait for types that can produce diagnostics.