zkat / miette

Fancy extension for std::error::Error with pretty, detailed diagnostic printing.
https://docs.rs/miette
Apache License 2.0
2.01k stars 114 forks source link

how can i read source_back when call with_source_code before #406

Open hardfist opened 1 month ago

hardfist commented 1 month ago

it's sometimes useful to get source_code as string back if we need to convert miette report to other diagnostic info like vscode lsp format, but it seems impossible to get it back, so it seems we need to wrap our own diagnostic to save source_code, but I'm not sure it's a good practice

struct MyDiagnostic {
   inner: Arc<miette::Report>,
   source_code: Arc<src>
}
zkat commented 1 month ago

You should be able to downcast any Report into a dyn Diagnostic, and then call .source_code() on it, to get the source code, if available.