From 05990d217ec4f1c667caafc0e4d4cb10d82f25c8 Mon Sep 17 00:00:00 2001 From: Eduardo Sandalo Porto Date: Wed, 7 Aug 2024 16:31:32 -0300 Subject: [PATCH] Report diagnostic origin --- Cargo.lock | 2 +- src/core/diagnostics.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adc69fb..31d93d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,7 +136,7 @@ dependencies = [ [[package]] name = "bend-lang" version = "0.2.36" -source = "git+https://github.com/HigherOrderCO/Bend.git?branch=lsp-experiments#811e5110140afd5a4077c778eb00a2183cd89902" +source = "git+https://github.com/HigherOrderCO/Bend.git?branch=lsp-experiments#f9198f4b9f015a483291e6a8027e673ee856e159" dependencies = [ "TSPL", "clap", diff --git a/src/core/diagnostics.rs b/src/core/diagnostics.rs index e173ef5..0dcec5b 100644 --- a/src/core/diagnostics.rs +++ b/src/core/diagnostics.rs @@ -25,15 +25,18 @@ pub fn check(doc: &Document) -> Diagnostics { pub fn lsp_diagnostics(diagnostics: &Diagnostics) -> Vec { diagnostics .diagnostics - .values() - .flatten() - .filter_map(treat_diagnostic) + // Iter<(DiagnosticOrigin, Vec)> + .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 { +fn treat_diagnostic(origin: &DiagnosticOrigin, diag: &Diagnostic) -> Option { 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),