From bdc079c2bc2aeb3cf4f8b162301a6b2b5c93cec0 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 1 Mar 2024 23:37:11 -0500 Subject: [PATCH] Support LSP diagnostic tags (#9780) --- book/src/themes.md | 2 ++ helix-lsp/src/client.rs | 6 ++++++ helix-term/src/ui/editor.rs | 15 ++++++++++++++- theme.toml | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/book/src/themes.md b/book/src/themes.md index f040dfb192f2..04d6a69b3914 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -333,5 +333,7 @@ These scopes are used for theming the editor interface: | `diagnostic.info` | Diagnostics info (editing area) | | `diagnostic.warning` | Diagnostics warning (editing area) | | `diagnostic.error` | Diagnostics error (editing area) | +| `diagnostic.unnecessary` | Diagnostics with unnecessary tag (editing area) | +| `diagnostic.deprecated` | Diagnostics with deprecated tag (editing area) | [editor-section]: ./configuration.md#editor-section diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 8d03d7992578..a7b3989dd49d 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -631,6 +631,12 @@ impl Client { }), publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities { version_support: Some(true), + tag_support: Some(lsp::TagSupport { + value_set: vec![ + lsp::DiagnosticTag::UNNECESSARY, + lsp::DiagnosticTag::DEPRECATED, + ], + }), ..Default::default() }), inlay_hint: Some(lsp::InlayHintClientCapabilities { diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index dffaeea03a66..f3bba5d1c755 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -360,7 +360,7 @@ impl EditorView { doc: &Document, theme: &Theme, ) -> [Vec<(usize, std::ops::Range)>; 5] { - use helix_core::diagnostic::Severity; + use helix_core::diagnostic::{DiagnosticTag, Severity}; let get_scope_of = |scope| { theme .find_scope_index_exact(scope) @@ -380,6 +380,10 @@ impl EditorView { let error = get_scope_of("diagnostic.error"); let r#default = get_scope_of("diagnostic"); // this is a bit redundant but should be fine + // Diagnostic tags + let unnecessary = theme.find_scope_index_exact("diagnostic.unnecessary"); + let deprecated = theme.find_scope_index_exact("diagnostic.deprecated"); + let mut default_vec: Vec<(usize, std::ops::Range)> = Vec::new(); let mut info_vec = Vec::new(); let mut hint_vec = Vec::new(); @@ -396,6 +400,15 @@ impl EditorView { _ => (&mut default_vec, r#default), }; + let scope = diagnostic + .tags + .first() + .and_then(|tag| match tag { + DiagnosticTag::Unnecessary => unnecessary, + DiagnosticTag::Deprecated => deprecated, + }) + .unwrap_or(scope); + // If any diagnostic overlaps ranges with the prior diagnostic, // merge the two together. Otherwise push a new span. match vec.last_mut() { diff --git a/theme.toml b/theme.toml index dd1a5d889ac1..8a5bfd72d299 100644 --- a/theme.toml +++ b/theme.toml @@ -80,6 +80,8 @@ label = "honey" "diagnostic.info" = { underline = { color = "delta", style = "curl" } } "diagnostic.warning" = { underline = { color = "lightning", style = "curl" } } "diagnostic.error" = { underline = { color = "apricot", style = "curl" } } +"diagnostic.unnecessary" = { modifiers = ["dim"] } +"diagnostic.deprecated" = { modifiers = ["crossed_out"] } warning = "lightning" error = "apricot"