From 206be2b3480a3b77dc3f87f57e832edeffda96a5 Mon Sep 17 00:00:00 2001 From: Mikal Sande Date: Mon, 26 May 2025 10:04:13 +0200 Subject: [PATCH] Make sure GoPlsAdapter produces output that can be rendered as Markdown (#30911) Closes [#30695](https://github.com/zed-industries/zed/issues/30695) Adds `diagnostic_message_to_markdown()` to GoLspAdapter to ensure that Go diagnostic messages are considered Markdown formatted and leading whitespace is removed to get the Markdown to display properly. Before: image After: image Release Notes: - Fixed display of Go diagnostics, it should be displayed as Markdown not as escaped string. --- crates/languages/src/go.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs index bbe0285fc5a265df840f3f6ab6c4cd2994db6932..f4f6950facd947f10051f53b2d3e1f1ae99c9778 100644 --- a/crates/languages/src/go.rs +++ b/crates/languages/src/go.rs @@ -374,6 +374,12 @@ impl super::LspAdapter for GoLspAdapter { filter_range, }) } + + fn diagnostic_message_to_markdown(&self, message: &str) -> Option { + static REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"(?m)\n\s*").expect("Failed to create REGEX")); + Some(REGEX.replace_all(message, "\n\n").to_string()) + } } fn parse_version_output(output: &Output) -> Result<&str> {