bias_miette/handlers/
debug.rs1use std::fmt;
2
3use crate::protocol::Diagnostic;
4
5#[derive(Debug, Clone)]
11pub struct DebugReportHandler;
12
13impl DebugReportHandler {
14 pub const fn new() -> Self {
17 Self
18 }
19}
20
21impl Default for DebugReportHandler {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl DebugReportHandler {
28 pub fn render_report(
32 &self,
33 f: &mut fmt::Formatter<'_>,
34 diagnostic: &(dyn Diagnostic),
35 ) -> fmt::Result {
36 let mut diag = f.debug_struct("Diagnostic");
37 diag.field("message", &format!("{}", diagnostic));
38 if let Some(code) = diagnostic.code() {
39 diag.field("code", &code.to_string());
40 }
41 if let Some(severity) = diagnostic.severity() {
42 diag.field("severity", &format!("{:?}", severity));
43 }
44 if let Some(url) = diagnostic.url() {
45 diag.field("url", &url.to_string());
46 }
47 if let Some(help) = diagnostic.help() {
48 diag.field("help", &help.to_string());
49 }
50 if let Some(labels) = diagnostic.labels() {
51 let labels: Vec<_> = labels.collect();
52 diag.field("labels", &format!("{:?}", labels));
53 }
54 diag.finish()?;
55 writeln!(f)
56 }
57}