Skip to content

Commit

Permalink
Report diagnostic origin
Browse files Browse the repository at this point in the history
  • Loading branch information
edusporto committed Aug 7, 2024
1 parent 847411f commit 05990d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/core/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ pub fn check(doc: &Document) -> Diagnostics {
pub fn lsp_diagnostics(diagnostics: &Diagnostics) -> Vec<lsp::Diagnostic> {
diagnostics
.diagnostics
.values()
.flatten()
.filter_map(treat_diagnostic)
// Iter<(DiagnosticOrigin, Vec<Diagnostic>)>
.iter()
// -> Iter<(DiagnosticOrigin, Diagnostic)>
.flat_map(|(key, vals)| vals.iter().map(move |val| (key, val)))
// Ignore unwanted diagnostics
.filter_map(|(origin, diagnostic)| treat_diagnostic(origin, diagnostic))
.collect()
}

fn treat_diagnostic(diag: &Diagnostic) -> Option<lsp::Diagnostic> {
fn treat_diagnostic(origin: &DiagnosticOrigin, diag: &Diagnostic) -> Option<lsp::Diagnostic> {
Some(lsp::Diagnostic {
message: diag.message.clone(),
message: format!("{}", diag.display_with_origin(origin)),
severity: match diag.severity {
Severity::Allow => Some(lsp::DiagnosticSeverity::HINT),
Severity::Warning => Some(lsp::DiagnosticSeverity::WARNING),
Expand Down

0 comments on commit 05990d2

Please sign in to comment.