miette icon indicating copy to clipboard operation
miette copied to clipboard

how can i read source_back when call with_source_code before

Open hardfist opened this issue 1 year ago • 1 comments

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>
}

hardfist avatar Sep 26 '24 08:09 hardfist

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.

zkat avatar Sep 26 '24 16:09 zkat