Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
lsp: Add client support for LSP 3.18 markdown diagnostic messages (#61030)
Shuhei Kadowaki12ef40c31659
diff --git a/Cargo.lock b/Cargo.lockindex 7436afc0f34..fb21a5b0ee6 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -10357,7 +10357,7 @@ dependencies = [[[package]]name = "lsp-types"version = "0.95.1"-source = "git+https://github.com/zed-industries/lsp-types?rev=f4dfa89a21ca35cd929b70354b1583fabae325f8#f4dfa89a21ca35cd929b70354b1583fabae325f8"+source = "git+https://github.com/zed-industries/lsp-types?rev=f1783e63a7f4eb4397bf51d4148b4895a1f7ab16#f1783e63a7f4eb4397bf51d4148b4895a1f7ab16"dependencies = ["bitflags 1.3.2","serde",diff --git a/Cargo.toml b/Cargo.tomlindex 641ad6b98c9..78f7945e303 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -672,7 +672,7 @@ linkify = "0.10.0"livekit = { version = "0.7.32", features = ["tokio", "rustls-tls-native-roots"] }log = { version = "0.4.16", features = ["kv_unstable_serde", "serde"] }lru = "0.16"-lsp-types = { git = "https://github.com/zed-industries/lsp-types", rev = "f4dfa89a21ca35cd929b70354b1583fabae325f8" }+lsp-types = { git = "https://github.com/zed-industries/lsp-types", rev = "f1783e63a7f4eb4397bf51d4148b4895a1f7ab16" }mach2 = "0.5"markup5ever_rcdom = "0.39"metal = "0.33"diff --git a/crates/agent_ui/src/diagnostics.rs b/crates/agent_ui/src/diagnostics.rsindex 75c21d68b75..e49b629b532 100644--- a/crates/agent_ui/src/diagnostics.rs+++ b/crates/agent_ui/src/diagnostics.rs@@ -241,7 +241,7 @@ fn collect_diagnostic(write!(text, " {}: ", ty).unwrap();let padding = text.len() - marker_start;- let message = util::truncate(&entry.diagnostic.message, MAX_MESSAGE_LENGTH)+ let message = util::truncate(entry.diagnostic.message.as_str(), MAX_MESSAGE_LENGTH).replace('\n', format!("\n//{:padding$}", "").as_str());writeln!(text, "{message}").unwrap();diff --git a/crates/benchmarks/benches/edit_file_tool.rs b/crates/benchmarks/benches/edit_file_tool.rsindex a00add54ee3..2adf7cd8ad6 100644--- a/crates/benchmarks/benches/edit_file_tool.rs+++ b/crates/benchmarks/benches/edit_file_tool.rs@@ -253,7 +253,7 @@ async fn setup_editor_and_tool(cx: &mut TestAppContext, file_text: String) -> Hadiagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "bench diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("bench diagnostic"),..Default::default()}],});diff --git a/crates/collab/tests/integration/editor_tests.rs b/crates/collab/tests/integration/editor_tests.rsindex 32ab7baba39..eabfd103734 100644--- a/crates/collab/tests/integration/editor_tests.rs+++ b/crates/collab/tests/integration/editor_tests.rs@@ -3454,7 +3454,7 @@ async fn test_lsp_pull_diagnostics(severity: Some(lsp::DiagnosticSeverity::ERROR,),- message,+ message: lsp::DiagnosticMessage::from(message),..lsp::Diagnostic::default()}],},@@ -3523,9 +3523,10 @@ async fn test_lsp_pull_diagnostics(},},severity: Some(lsp::DiagnosticSeverity::WARNING),- message:+ message: lsp::DiagnosticMessage::from(expected_workspace_pull_diagnostics_main_message.to_string(),+ ),..lsp::Diagnostic::default()}],},@@ -3552,9 +3553,10 @@ async fn test_lsp_pull_diagnostics(},},severity: Some(lsp::DiagnosticSeverity::WARNING),- message:+ message: lsp::DiagnosticMessage::from(expected_workspace_pull_diagnostics_lib_message.to_string(),+ ),..lsp::Diagnostic::default()}],},@@ -3691,7 +3693,9 @@ async fn test_lsp_pull_diagnostics(},},severity: Some(lsp::DiagnosticSeverity::INFORMATION),- message: expected_push_diagnostic_main_message.to_string(),+ message: lsp::DiagnosticMessage::from(+ expected_push_diagnostic_main_message.to_string(),+ ),..lsp::Diagnostic::default()}],version: None,@@ -3712,7 +3716,9 @@ async fn test_lsp_pull_diagnostics(},},severity: Some(lsp::DiagnosticSeverity::INFORMATION),- message: expected_push_diagnostic_lib_message.to_string(),+ message: lsp::DiagnosticMessage::from(+ expected_push_diagnostic_lib_message.to_string(),+ ),..lsp::Diagnostic::default()}],version: None,@@ -3749,9 +3755,10 @@ async fn test_lsp_pull_diagnostics(},},severity: Some(lsp::DiagnosticSeverity::ERROR),- message:+ message: lsp::DiagnosticMessage::from(expected_workspace_pull_diagnostics_main_message.to_string(),+ ),..lsp::Diagnostic::default()}],},@@ -3928,8 +3935,9 @@ async fn test_lsp_pull_diagnostics(},},severity: Some(lsp::DiagnosticSeverity::ERROR),- message: expected_workspace_pull_diagnostics_lib_message- .to_string(),+ message: lsp::DiagnosticMessage::from(+ expected_workspace_pull_diagnostics_lib_message.to_string(),+ ),..lsp::Diagnostic::default()}],},diff --git a/crates/collab/tests/integration/integration_tests.rs b/crates/collab/tests/integration/integration_tests.rsindex 77e6872d01f..eccf080e859 100644--- a/crates/collab/tests/integration/integration_tests.rs+++ b/crates/collab/tests/integration/integration_tests.rs@@ -19,8 +19,8 @@ use gpui::{UpdateGlobal, px, size,};use language::{- Diagnostic, DiagnosticEntry, DiagnosticSourceKind, FakeLspAdapter, Language, LanguageConfig,- LanguageMatcher, LineEnding, OffsetRangeExt, Point, Rope,+ Diagnostic, DiagnosticEntry, DiagnosticMessage, DiagnosticSourceKind, FakeLspAdapter, Language,+ LanguageConfig, LanguageMatcher, LineEnding, OffsetRangeExt, Point, Rope,language_settings::{Formatter, FormatterList},rust_lang, tree_sitter_rust, tree_sitter_typescript,};@@ -4237,7 +4237,7 @@ async fn test_collaborating_with_diagnostics(diagnostics: vec![lsp::Diagnostic {severity: Some(lsp::DiagnosticSeverity::WARNING),range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 7)),- message: "message 0".to_string(),+ message: lsp::DiagnosticMessage::from("message 0"),..Default::default()}],},@@ -4257,7 +4257,7 @@ async fn test_collaborating_with_diagnostics(diagnostics: vec![lsp::Diagnostic {severity: Some(lsp::DiagnosticSeverity::ERROR),range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 7)),- message: "message 1".to_string(),+ message: lsp::DiagnosticMessage::from("message 1"),..Default::default()}],},@@ -4324,6 +4324,14 @@ async fn test_collaborating_with_diagnostics();// Simulate a language server reporting more errors for a file.+ let markdown_message = lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "\n**message 1**\n".to_string(),+ };+ let plain_text_message = lsp::MarkupContent {+ kind: lsp::MarkupKind::PlainText,+ value: "\nmessage 2\n".to_string(),+ };fake_language_server.notify::<lsp::notification::PublishDiagnostics>(lsp::PublishDiagnosticsParams {uri: lsp::Uri::from_file_path(path!("/a/a.rs")).unwrap(),@@ -4332,13 +4340,13 @@ async fn test_collaborating_with_diagnostics(lsp::Diagnostic {severity: Some(lsp::DiagnosticSeverity::ERROR),range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 7)),- message: "message 1".to_string(),+ message: lsp::DiagnosticMessage::from(markdown_message.clone()),..Default::default()},lsp::Diagnostic {severity: Some(lsp::DiagnosticSeverity::WARNING),range: lsp::Range::new(lsp::Position::new(0, 10), lsp::Position::new(0, 13)),- message: "message 2".to_string(),+ message: lsp::DiagnosticMessage::from(plain_text_message.clone()),..Default::default()},],@@ -4399,7 +4407,7 @@ async fn test_collaborating_with_diagnostics(Point::new(0, 4)..Point::new(0, 7),Diagnostic {group_id: 2,- message: "message 1".to_string(),+ message: DiagnosticMessage::from_lsp_markup(&markdown_message),severity: lsp::DiagnosticSeverity::ERROR,is_primary: true,source_kind: DiagnosticSourceKind::Pushed,@@ -4411,7 +4419,7 @@ async fn test_collaborating_with_diagnostics(Diagnostic {group_id: 3,severity: lsp::DiagnosticSeverity::WARNING,- message: "message 2".to_string(),+ message: DiagnosticMessage::from_lsp_markup(&plain_text_message),is_primary: true,source_kind: DiagnosticSourceKind::Pushed,..Diagnostic::default()@@ -4541,7 +4549,7 @@ async fn test_collaborating_with_lsp_progress_updates_and_diagnostics_ordering(severity: Some(lsp::DiagnosticSeverity::WARNING),source: Some("the-disk-based-diagnostics-source".into()),range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 0)),- message: "message one".to_string(),+ message: lsp::DiagnosticMessage::from("message one"),..Default::default()}],},diff --git a/crates/diagnostics/src/buffer_diagnostics.rs b/crates/diagnostics/src/buffer_diagnostics.rsindex 4558ce07076..40f93a9b259 100644--- a/crates/diagnostics/src/buffer_diagnostics.rs+++ b/crates/diagnostics/src/buffer_diagnostics.rs@@ -615,10 +615,13 @@ impl BufferDiagnosticsEditor {.iter().zip(diagnostics.iter()).all(|(existing, new)| {- existing.diagnostic.message == new.diagnostic.message- && existing.diagnostic.severity == new.diagnostic.severity+ existing.diagnostic.severity == new.diagnostic.severity&& existing.diagnostic.is_primary == new.diagnostic.is_primary&& existing.range.to_offset(snapshot) == new.range.to_offset(snapshot)+ && existing+ .diagnostic+ .message+ .rendered_eq(&new.diagnostic.message)})}diff --git a/crates/diagnostics/src/diagnostic_renderer.rs b/crates/diagnostics/src/diagnostic_renderer.rsindex f44e6a4ee51..682f5b56172 100644--- a/crates/diagnostics/src/diagnostic_renderer.rs+++ b/crates/diagnostics/src/diagnostic_renderer.rs@@ -45,7 +45,7 @@ impl DiagnosticRenderer {for (ix, entry) in diagnostic_group.iter().enumerate() {if entry.range.start.row.abs_diff(primary.range.start.row) >= 5 {markdown.push_str("\n- hint: [");- markdown.push_str(&Markdown::escape(&entry.diagnostic.message));+ markdown.push_str(&Markdown::escape(entry.diagnostic.message.as_str()));markdown.push_str(&format!("](file://#diagnostic-{buffer_id}-{group_id}-{ix})\n",))@@ -56,7 +56,7 @@ impl DiagnosticRenderer {initial_range: primary.range.clone(),severity: primary.diagnostic.severity,diagnostics_editor: diagnostics_editor.clone(),- copy_message: primary.diagnostic.message.clone().into(),+ copy_message: primary.diagnostic.message.as_shared_string().clone(),markdown: cx.new(|cx| {Markdown::new(markdown.into(), language_registry.clone(), None, cx)}),@@ -73,7 +73,7 @@ impl DiagnosticRenderer {initial_range: entry.range.clone(),severity: entry.diagnostic.severity,diagnostics_editor: diagnostics_editor.clone(),- copy_message: entry.diagnostic.message.clone().into(),+ copy_message: entry.diagnostic.message.as_shared_string().clone(),markdown: cx.new(|cx| {Markdown::new(markdown.into(), language_registry.clone(), None, cx)}),@@ -87,10 +87,10 @@ impl DiagnosticRenderer {fn markdown(diagnostic: &Diagnostic) -> String {let mut markdown = String::new();- if let Some(md) = &diagnostic.markdown {- markdown.push_str(md);+ if let Some(message_markdown) = diagnostic.message.markdown() {+ markdown.push_str(message_markdown);} else {- markdown.push_str(&Markdown::escape(&diagnostic.message));+ markdown.push_str(&Markdown::escape(diagnostic.message.as_str()));};markdown}@@ -100,7 +100,15 @@ fn append_source_and_code(markdown: &mut String, diagnostic: &Diagnostic) {if diagnostic.source.is_none() && diagnostic.code.is_none() {return;}- markdown.push_str(" (");+ let is_lsp_markdown = diagnostic+ .message+ .lsp_markup()+ .is_some_and(|(kind, _)| kind == &lsp::MarkupKind::Markdown);+ if is_lsp_markdown {+ markdown.push_str("\n\n(");+ } else {+ markdown.push_str(" (");+ }if let Some(source) = diagnostic.source.as_ref() {markdown.push_str(&Markdown::escape(source));}@@ -330,3 +338,31 @@ impl DiagnosticBlock {window.focus(&editor.focus_handle(cx), cx);}}++#[cfg(test)]+mod tests {+ use super::*;+ use language::DiagnosticMessage;+ use pretty_assertions::assert_eq;++ #[test]+ fn test_adapter_markdown_keeps_source_and_code_inline() {+ let diagnostic = Diagnostic {+ message: DiagnosticMessage::plain_with_adapter_markdown(+ "mismatched types\nexpected `usize`, found `char`",+ Some("mismatched types\n\nexpected `usize`, found `char`".into()),+ ),+ source: Some("rust-analyzer".to_string()),+ code: Some(lsp::NumberOrString::String("E0308".to_string())),+ ..Diagnostic::default()+ };++ let mut markdown = DiagnosticRenderer::markdown(&diagnostic);+ append_source_and_code(&mut markdown, &diagnostic);++ assert_eq!(+ markdown,+ "mismatched types\n\nexpected `usize`, found `char` (rust\\-analyzer E0308)"+ );+ }+}diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rsindex 6b1e91b680e..6534602aa73 100644--- a/crates/diagnostics/src/diagnostics.rs+++ b/crates/diagnostics/src/diagnostics.rs@@ -478,10 +478,13 @@ impl ProjectDiagnosticsEditor {return false;}existing.iter().zip(new.iter()).all(|(existing, new)| {- existing.diagnostic.message == new.diagnostic.message- && existing.diagnostic.severity == new.diagnostic.severity+ existing.diagnostic.severity == new.diagnostic.severity&& existing.diagnostic.is_primary == new.diagnostic.is_primary&& existing.range.to_offset(snapshot) == new.range.to_offset(snapshot)+ && existing+ .diagnostic+ .message+ .rendered_eq(&new.diagnostic.message)})}diff --git a/crates/diagnostics/src/diagnostics_tests.rs b/crates/diagnostics/src/diagnostics_tests.rsindex 7bac26fac70..47d96d87917 100644--- a/crates/diagnostics/src/diagnostics_tests.rs+++ b/crates/diagnostics/src/diagnostics_tests.rs@@ -83,7 +83,9 @@ async fn test_diagnostics(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(7, 6),lsp::Position::new(7, 7)),severity:Some(lsp::DiagnosticSeverity::ERROR),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location::new(uri.clone(), lsp::Range::new(lsp::Position::new(2,8),lsp::Position::new(2,9))),message: "move occurs because `y` has type `Vec<char>`, which does not implement the `Copy` trait".to_string()@@ -98,7 +100,9 @@ async fn test_diagnostics(cx: &mut TestAppContext) {lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(8, 6),lsp::Position::new(8, 7)),severity:Some(lsp::DiagnosticSeverity::ERROR),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location::new(uri.clone(), lsp::Range::new(lsp::Position::new(1,8),lsp::Position::new(1,9))),message: "move occurs because `x` has type `Vec<char>`, which does not implement the `Copy` trait".to_string()@@ -180,7 +184,9 @@ async fn test_diagnostics(cx: &mut TestAppContext) {lsp::Position::new(0, 15),),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "mismatched types expected `usize`, found `char`".to_string(),+ message: lsp::DiagnosticMessage::from(+ "mismatched types expected `usize`, found `char`",+ ),..Default::default()}],version: None,@@ -259,7 +265,9 @@ async fn test_diagnostics(cx: &mut TestAppContext) {lsp::Position::new(0, 15),),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "mismatched types expected `usize`, found `char`".to_string(),+ message: lsp::DiagnosticMessage::from(+ "mismatched types expected `usize`, found `char`",+ ),..Default::default()},lsp::Diagnostic {@@ -268,7 +276,7 @@ async fn test_diagnostics(cx: &mut TestAppContext) {lsp::Position::new(1, 15),),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "unresolved name `c`".to_string(),+ message: lsp::DiagnosticMessage::from("unresolved name `c`"),..Default::default()},],@@ -370,7 +378,7 @@ async fn test_diagnostics_with_folds(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(4, 0), lsp::Position::new(4, 4)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "no method `tset`".to_string(),+ message: lsp::DiagnosticMessage::from("no method `tset`"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location::new(lsp::Uri::from_file_path(path!("/test/main.js")).unwrap(),@@ -480,7 +488,7 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "error 1".to_string(),+ message: lsp::DiagnosticMessage::from("error 1"),..Default::default()}],version: None,@@ -524,7 +532,7 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(1, 0), lsp::Position::new(1, 1)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "warning 1".to_string(),+ message: lsp::DiagnosticMessage::from("warning 1"),..Default::default()}],version: None,@@ -567,7 +575,7 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(2, 0), lsp::Position::new(2, 1)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "warning 2".to_string(),+ message: lsp::DiagnosticMessage::from("warning 2"),..Default::default()}],version: None,@@ -623,7 +631,7 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(3, 0), lsp::Position::new(3, 1)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "warning 2".to_string(),+ message: lsp::DiagnosticMessage::from("warning 2"),..Default::default()}],version: None,@@ -1004,7 +1012,7 @@ async fn active_diagnostics_dismiss_after_invalidation(cx: &mut TestAppContext)}"});- let message = "Something's wrong!";+ let message = "`Something's wrong!`";cx.update(|_, cx| {lsp_store.update(cx, |lsp_store, cx| {lsp_store@@ -1019,7 +1027,7 @@ async fn active_diagnostics_dismiss_after_invalidation(cx: &mut TestAppContext)lsp::Position::new(0, 12),),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: message.to_string(),+ message: lsp::DiagnosticMessage::from(message.to_string()),..Default::default()}],},@@ -1046,6 +1054,49 @@ async fn active_diagnostics_dismiss_after_invalidation(cx: &mut TestAppContext)}"});+ cx.update(|_, cx| {+ lsp_store.update(cx, |lsp_store, cx| {+ lsp_store+ .update_diagnostics(+ LanguageServerId(0),+ lsp::PublishDiagnosticsParams {+ uri: lsp::Uri::from_file_path(path!("/root/file")).unwrap(),+ version: None,+ diagnostics: vec![lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 11),+ lsp::Position::new(0, 12),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::from(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: message.to_string(),+ }),+ ..Default::default()+ }],+ },+ None,+ DiagnosticSourceKind::Pushed,+ &[],+ cx,+ )+ .unwrap()+ });+ });+ cx.run_until_parked();+ cx.update_editor(|editor, _, _| {+ assert_eq!(+ editor.active_diagnostic_message(),+ None,+ "changing only the diagnostic's Markdown rendering should invalidate the active group"+ );+ });++ cx.update_editor(|editor, window, cx| {+ editor.go_to_diagnostic(&GoToDiagnostic::default(), window, cx);+ assert_eq!(editor.active_diagnostic_message(), Some(message));+ });+cx.update(|_, cx| {lsp_store.update(cx, |lsp_store, cx| {lsp_store@@ -1275,7 +1326,9 @@ async fn test_diagnostics_with_links(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 8), lsp::Position::new(0, 12)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "we've had problems with <https://link.one>, and <https://link.two> is broken".to_string(),+ message: lsp::DiagnosticMessage::from(+ "we've had problems with <https://link.one>, and <https://link.two> is broken",+ ),..Default::default()}],},@@ -1294,6 +1347,284 @@ async fn test_diagnostics_with_links(cx: &mut TestAppContext) {cx.update_editor(|editor, _, _| assert!(editor.hover_state.diagnostic_popover.is_some()))}+#[gpui::test]+async fn test_markup_content_diagnostic_messages_render_as_markdown(cx: &mut TestAppContext) {+ init_test(cx);++ let mut cx = EditorTestContext::new(cx).await;++ cx.set_state(indoc! {"+ fn func(abˇc def: i32) -> u32 {+ }+ "});+ let lsp_store =+ cx.update_editor(|editor, _, cx| editor.project().unwrap().read(cx).lsp_store());++ cx.update(|_, cx| {+ lsp_store.update(cx, |lsp_store, cx| {+ lsp_store.update_diagnostics(+ LanguageServerId(0),+ lsp::PublishDiagnosticsParams {+ uri: lsp::Uri::from_file_path(path!("/root/file")).unwrap(),+ version: None,+ diagnostics: vec![+ lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 8),+ lsp::Position::new(0, 12),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "`abc` is **not** defined".to_string(),+ }),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 17),+ lsp::Position::new(0, 20),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::from("`i32` is **not** a type"),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 21),+ lsp::Position::new(0, 24),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ source: Some("rustc".to_string()),+ code: Some(lsp::NumberOrString::String("E0425".to_string())),+ message: lsp::DiagnosticMessage::from(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "```rust\nlet x = unknown;\n```".to_string(),+ }),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 25),+ lsp::Position::new(0, 28),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind: lsp::MarkupKind::PlainText,+ value: "`u32` is **not** a type".to_string(),+ }),+ ..Default::default()+ },+ ],+ },+ None,+ DiagnosticSourceKind::Pushed,+ &[],+ cx,+ )+ })+ })+ .unwrap();+ cx.run_until_parked();++ cx.update_editor(|editor, window, cx| {+ editor::hover_popover::hover(editor, &Default::default(), window, cx)+ });+ cx.run_until_parked();+ cx.update_editor(|editor, _, _| assert!(editor.hover_state.diagnostic_popover.is_some()));++ let buffer_id = cx.update_buffer(|buffer, _| buffer.remote_id());+ cx.update_editor(|editor, window, cx| {+ let snapshot = editor.snapshot(window, cx);++ // Markdown MarkupContent is rendered as the markdown the server sent,+ // while PlainText MarkupContent and plain string messages are escaped.+ let group = snapshot+ .buffer_snapshot()+ .diagnostic_group(buffer_id, 0)+ .collect::<Vec<_>>();+ let blocks = diagnostic_renderer::DiagnosticRenderer::diagnostic_blocks_for_group(+ group, buffer_id, None, None, cx,+ );+ assert_eq!(+ blocks[0].markdown.read(cx).source(),+ "`abc` is **not** defined"+ );++ let group = snapshot+ .buffer_snapshot()+ .diagnostic_group(buffer_id, 1)+ .collect::<Vec<_>>();+ let blocks = diagnostic_renderer::DiagnosticRenderer::diagnostic_blocks_for_group(+ group, buffer_id, None, None, cx,+ );+ assert_eq!(+ blocks[0].markdown.read(cx).source(),+ markdown::Markdown::escape("`i32` is **not** a type").as_ref(),+ );++ let group = snapshot+ .buffer_snapshot()+ .diagnostic_group(buffer_id, 2)+ .collect::<Vec<_>>();+ let blocks = diagnostic_renderer::DiagnosticRenderer::diagnostic_blocks_for_group(+ group, buffer_id, None, None, cx,+ );+ assert_eq!(+ blocks[0].markdown.read(cx).source(),+ "```rust\nlet x = unknown;\n```\n\n(rustc E0425)"+ );++ let group = snapshot+ .buffer_snapshot()+ .diagnostic_group(buffer_id, 3)+ .collect::<Vec<_>>();+ let blocks = diagnostic_renderer::DiagnosticRenderer::diagnostic_blocks_for_group(+ group, buffer_id, None, None, cx,+ );+ assert_eq!(+ blocks[0].markdown.read(cx).source(),+ markdown::Markdown::escape("`u32` is **not** a type").as_ref(),+ );+ });+}++#[gpui::test]+async fn test_diagnostics_views_update_when_only_markdown_changes(cx: &mut TestAppContext) {+ init_test(cx);++ let fs = FakeFs::new(cx.executor());+ fs.insert_tree(path!("/test"), json!({ "main.rs": "x\n" }))+ .await;++ let project = Project::test(fs, [path!("/test").as_ref()], cx).await;+ let lsp_store = project.read_with(cx, |project, _| project.lsp_store());+ let window = cx.add_window(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));+ let cx = &mut VisualTestContext::from_window(window.into(), cx);+ let workspace = window+ .read_with(cx, |multi_workspace, _| multi_workspace.workspace().clone())+ .unwrap();+ let project_path = project::ProjectPath {+ worktree_id: project.read_with(cx, |project, cx| {+ project.worktrees(cx).next().unwrap().read(cx).id()+ }),+ path: rel_path("main.rs").into(),+ };+ let buffer = project+ .update(cx, |project, cx| {+ project.open_buffer(project_path.clone(), cx)+ })+ .await+ .unwrap();+ let uri = lsp::Uri::from_file_path(path!("/test/main.rs")).unwrap();+ let language_server_id = LanguageServerId(0);++ lsp_store+ .update(cx, |lsp_store, cx| {+ lsp_store.update_diagnostics(+ language_server_id,+ lsp::PublishDiagnosticsParams {+ uri: uri.clone(),+ version: None,+ diagnostics: vec![lsp::Diagnostic {+ range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::from("`x`"),+ ..Default::default()+ }],+ },+ None,+ DiagnosticSourceKind::Pushed,+ &[],+ cx,+ )+ })+ .unwrap();++ let project_diagnostics = window.build_entity(cx, |window, cx| {+ ProjectDiagnosticsEditor::new(true, project.clone(), workspace.downgrade(), window, cx)+ });+ let project_editor =+ project_diagnostics.update(cx, |diagnostics, _| diagnostics.editor.clone());+ let buffer_diagnostics = window.build_entity(cx, |window, cx| {+ BufferDiagnosticsEditor::new(+ project_path,+ project.clone(),+ Some(buffer),+ true,+ window,+ cx,+ )+ });+ let buffer_editor =+ buffer_diagnostics.update(cx, |diagnostics, _| diagnostics.editor().clone());++ project_diagnostics+ .next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)+ .await;+ cx.executor()+ .advance_clock(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10));+ cx.run_until_parked();++ let expected_content = indoc! {"+ § main.rs+ § -----+ x § `x`"};+ assert_eq!(+ editor_content_with_blocks(&project_editor, cx),+ expected_content+ );+ assert_eq!(+ editor_content_with_blocks(&buffer_editor, cx),+ expected_content+ );++ lsp_store+ .update(cx, |lsp_store, cx| {+ lsp_store.update_diagnostics(+ language_server_id,+ lsp::PublishDiagnosticsParams {+ uri,+ version: None,+ diagnostics: vec![lsp::Diagnostic {+ range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::from(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "`x`".to_string(),+ }),+ ..Default::default()+ }],+ },+ None,+ DiagnosticSourceKind::Pushed,+ &[],+ cx,+ )+ })+ .unwrap();++ project_diagnostics+ .next_notification(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10), cx)+ .await;+ cx.executor()+ .advance_clock(DIAGNOSTICS_UPDATE_DEBOUNCE + Duration::from_millis(10));+ cx.run_until_parked();++ let expected_content = indoc! {"+ § main.rs+ § -----+ x § x"};+ assert_eq!(+ editor_content_with_blocks(&project_editor, cx),+ expected_content+ );+ assert_eq!(+ editor_content_with_blocks(&buffer_editor, cx),+ expected_content+ );+}+#[gpui::test]async fn test_hover_diagnostic_and_info_popovers(cx: &mut gpui::TestAppContext) {init_test(cx);@@ -1328,7 +1659,7 @@ async fn test_hover_diagnostic_and_info_popovers(cx: &mut gpui::TestAppContext)diagnostics: vec![lsp::Diagnostic {range,severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "A test diagnostic message.".to_string(),+ message: lsp::DiagnosticMessage::from("A test diagnostic message."),..Default::default()}],},@@ -1420,7 +1751,9 @@ async fn test_diagnostics_with_code(cx: &mut TestAppContext) {severity: Some(lsp::DiagnosticSeverity::WARNING),code: Some(lsp::NumberOrString::String("no-unused-vars".to_string())),source: Some("eslint".to_string()),- message: "'x' is assigned a value but never used".to_string(),+ message: lsp::DiagnosticMessage::from(+ "'x' is assigned a value but never used",+ ),..Default::default()},lsp::Diagnostic {@@ -1431,7 +1764,9 @@ async fn test_diagnostics_with_code(cx: &mut TestAppContext) {severity: Some(lsp::DiagnosticSeverity::WARNING),code: Some(lsp::NumberOrString::String("no-unused-vars".to_string())),source: Some("eslint".to_string()),- message: "'y' is assigned a value but never used".to_string(),+ message: lsp::DiagnosticMessage::from(+ "'y' is assigned a value but never used",+ ),..Default::default()},],@@ -1657,7 +1992,9 @@ async fn test_buffer_diagnostics(cx: &mut TestAppContext) {lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(5, 6), lsp::Position::new(5, 7)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location::new(uri.clone(), lsp::Range::new(lsp::Position::new(2, 8), lsp::Position::new(2, 9))),@@ -1673,7 +2010,9 @@ async fn test_buffer_diagnostics(cx: &mut TestAppContext) {lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(6, 6), lsp::Position::new(6, 7)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location::new(uri.clone(), lsp::Range::new(lsp::Position::new(1, 8), lsp::Position::new(1, 9))),@@ -1699,13 +2038,15 @@ async fn test_buffer_diagnostics(cx: &mut TestAppContext) {lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(1, 8), lsp::Position::new(1, 14)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "unused variable: `unused`".to_string(),+ message: lsp::DiagnosticMessage::from("unused variable: `unused`"),..Default::default()},lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(2, 4), lsp::Position::new(2, 22)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "cannot find function `undefined_function` in this scope".to_string(),+ message: lsp::DiagnosticMessage::from(+ "cannot find function `undefined_function` in this scope",+ ),..Default::default()}],@@ -1810,7 +2151,9 @@ async fn test_buffer_diagnostics_without_warnings(cx: &mut TestAppContext) {lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(5, 6), lsp::Position::new(5, 7)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location::new(uri.clone(), lsp::Range::new(lsp::Position::new(2, 8), lsp::Position::new(2, 9))),@@ -1826,7 +2169,9 @@ async fn test_buffer_diagnostics_without_warnings(cx: &mut TestAppContext) {lsp::Diagnostic{range: lsp::Range::new(lsp::Position::new(6, 6), lsp::Position::new(6, 7)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location::new(uri.clone(), lsp::Range::new(lsp::Position::new(1, 8), lsp::Position::new(1, 9))),@@ -1945,7 +2290,9 @@ async fn test_buffer_diagnostics_multiple_servers(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(5, 6), lsp::Position::new(5, 7)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: None,..Default::default()}],@@ -1966,7 +2313,9 @@ async fn test_buffer_diagnostics_multiple_servers(cx: &mut TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(6, 6), lsp::Position::new(6, 7)),severity: Some(lsp::DiagnosticSeverity::WARNING),- message: "use of moved value\nvalue used here after move".to_string(),+ message: lsp::DiagnosticMessage::from(+ "use of moved value\nvalue used here after move",+ ),related_information: None,..Default::default()}],@@ -2145,7 +2494,7 @@ fn random_lsp_diagnostic(lsp::Diagnostic {range,severity,- message,+ message: lsp::DiagnosticMessage::from(message),related_information,data: None,..Default::default()diff --git a/crates/diagnostics/src/items.rs b/crates/diagnostics/src/items.rsindex 724d58e3fc6..cc1bf283be7 100644--- a/crates/diagnostics/src/items.rs+++ b/crates/diagnostics/src/items.rs@@ -62,8 +62,9 @@ impl Render for DiagnosticIndicator {let status = if let Some(diagnostic) = &self.current_diagnostic {let message = diagnostic.message+ .as_str().split_once('\n')- .map_or(&*diagnostic.message, |(first, _)| first);+ .map_or(diagnostic.message.as_str(), |(first, _)| first);let diagnostics_already_active = self.any_active_diagnostics(cx);let tooltip = if !diagnostics_already_active {"Expand Diagnostics"diff --git a/crates/edit_prediction/src/edit_prediction_tests.rs b/crates/edit_prediction/src/edit_prediction_tests.rsindex ddd23aeb646..3d4212c9647 100644--- a/crates/edit_prediction/src/edit_prediction_tests.rs+++ b/crates/edit_prediction/src/edit_prediction_tests.rs@@ -2368,9 +2368,9 @@ fn test_active_buffer_diagnostics_fetching(cx: &mut TestAppContext) {_ => DiagnosticSeverity::HINT,},message: match index {- 0 => "first warning".to_string(),- 1 => "second error".to_string(),- _ => "third hint".to_string(),+ 0 => "first warning".into(),+ 1 => "second error".into(),+ _ => "third hint".into(),},group_id: index + 1,is_primary: true,@@ -2451,7 +2451,7 @@ fn test_active_buffer_diagnostics_fetching(cx: &mut TestAppContext) {text::PointUtf16::new(0, 0)..text::PointUtf16::new(0, 3),Diagnostic {severity: DiagnosticSeverity::ERROR,- message: "row zero".to_string(),+ message: "row zero".into(),group_id: 1,is_primary: true,source_kind: language::DiagnosticSourceKind::Pushed,@@ -2462,7 +2462,7 @@ fn test_active_buffer_diagnostics_fetching(cx: &mut TestAppContext) {text::PointUtf16::new(2, 0)..text::PointUtf16::new(2, 5),Diagnostic {severity: DiagnosticSeverity::WARNING,- message: "row two".to_string(),+ message: "row two".into(),group_id: 2,is_primary: true,source_kind: language::DiagnosticSourceKind::Pushed,@@ -2473,7 +2473,7 @@ fn test_active_buffer_diagnostics_fetching(cx: &mut TestAppContext) {text::PointUtf16::new(4, 0)..text::PointUtf16::new(4, 4),Diagnostic {severity: DiagnosticSeverity::INFORMATION,- message: "row four".to_string(),+ message: "row four".into(),group_id: 3,is_primary: true,source_kind: language::DiagnosticSourceKind::Pushed,@@ -2537,7 +2537,7 @@ fn test_active_buffer_diagnostics_collection_limits(cx: &mut TestAppContext) {text::PointUtf16::new(row, 0)..text::PointUtf16::new(row, 4),Diagnostic {severity: DiagnosticSeverity::ERROR,- message: format!("row {row}"),+ message: format!("row {row}").into(),group_id: row as usize,is_primary: true,source_kind: language::DiagnosticSourceKind::Pushed,@@ -2580,7 +2580,7 @@ fn test_active_buffer_diagnostics_collection_limits(cx: &mut TestAppContext) {text::PointUtf16::new(150, 0)..text::PointUtf16::new(150, 4),Diagnostic {severity: DiagnosticSeverity::ERROR,- message: long_message.clone(),+ message: long_message.clone().into(),group_id: 1,is_primary: true,source_kind: language::DiagnosticSourceKind::Pushed,diff --git a/crates/edit_prediction/src/zeta.rs b/crates/edit_prediction/src/zeta.rsindex 54b324253ad..78dcd9eb601 100644--- a/crates/edit_prediction/src/zeta.rs+++ b/crates/edit_prediction/src/zeta.rs@@ -734,7 +734,7 @@ pub(crate) fn active_buffer_diagnostics((severity,zeta_prompt::clamp_text_to_token_count(- &entry.diagnostic.message,+ entry.diagnostic.message.as_str(),MAX_ACTIVE_BUFFER_DIAGNOSTIC_MESSAGE_TOKENS_TO_COLLECT,).to_string(),diff --git a/crates/editor/src/diagnostics.rs b/crates/editor/src/diagnostics.rsindex 3e988781eb7..34f42c68f60 100644--- a/crates/editor/src/diagnostics.rs+++ b/crates/editor/src/diagnostics.rs@@ -55,7 +55,7 @@ pub(super) struct InlineDiagnostic {#[derive(Debug, PartialEq, Eq)]pub(super) struct ActiveDiagnosticGroup {active_range: Range<Anchor>,- active_message: String,+ active_message: language::DiagnosticMessage,group_id: usize,blocks: HashSet<CustomBlockId>,}@@ -369,7 +369,10 @@ impl Editor {entry.diagnostic.is_primary&& !entry.range.is_empty()&& entry.range.start == primary_range_start- && entry.diagnostic.message == active_diagnostics.active_message+ && entry+ .diagnostic+ .message+ .rendered_eq(&active_diagnostics.active_message)});if !is_valid {@@ -495,11 +498,16 @@ impl Editor {let message = diagnostic_entry.diagnostic.message+ .as_str().split_once('\n').map(|(line, _)| line).map(SharedString::new).unwrap_or_else(|| {- SharedString::new(&*diagnostic_entry.diagnostic.message)+ diagnostic_entry+ .diagnostic+ .message+ .as_shared_string()+ .clone()});let start_anchor = snapshot.anchor_before(diagnostic_entry.range.start);let (Ok(i) | Err(i)) = inline_diagnostics@@ -654,7 +662,7 @@ mod tests {lsp::Position::new(0, 15),),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "cannot find value `def`".to_string(),+ message: lsp::DiagnosticMessage::from("cannot find value `def`"),..Default::default()}],},diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rsindex db389cfecab..c7e9761ba8b 100644--- a/crates/editor/src/hover_popover.rs+++ b/crates/editor/src/hover_popover.rs@@ -1453,7 +1453,12 @@ impl DiagnosticPopover {),).child(div().absolute().top_1().right_1().child({- let message = self.local_diagnostic.diagnostic.message.clone();+ let message = self+ .local_diagnostic+ .diagnostic+ .message+ .as_shared_string()+ .clone();CopyButton::new("copy-diagnostic", message).tooltip_label("Copy Diagnostic")})).custom_scrollbars(diff --git a/crates/inspector_ui/src/div_inspector.rs b/crates/inspector_ui/src/div_inspector.rsindex d80a15623c9..78c76ee3e52 100644--- a/crates/inspector_ui/src/div_inspector.rs+++ b/crates/inspector_ui/src/div_inspector.rs@@ -445,7 +445,7 @@ impl DivInspector {DiagnosticEntry::new(range,Diagnostic {- message: "unrecognized".to_string(),+ message: "unrecognized".into(),severity: DiagnosticSeverity::WARNING,is_primary: true,group_id: ix,diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rsindex 6c9b914200f..c974ecde15d 100644--- a/crates/language/src/buffer.rs+++ b/crates/language/src/buffer.rs@@ -5184,16 +5184,33 @@ impl BufferSnapshot {search_range: Range<T>,reversed: bool,) -> impl 'a + Iterator<Item = &'a DiagnosticEntry<Anchor>>+ where+ T: 'a + Clone + ToOffset,+ {+ self.diagnostic_entries_in_range_with_server_id(search_range, reversed)+ .map(|(_, entry)| entry)+ }++ /// Returns the stored entries that intersect the given range along with the+ /// language server that produced each diagnostic.+ pub fn diagnostic_entries_in_range_with_server_id<'a, T>(+ &'a self,+ search_range: Range<T>,+ reversed: bool,+ ) -> impl 'a + Iterator<Item = (LanguageServerId, &'a DiagnosticEntry<Anchor>)>whereT: 'a + Clone + ToOffset,{let mut iterators: Vec<_> = self.diagnostics.iter()- .map(|(_, collection)| {- collection- .entries_in_range::<T>(search_range.clone(), self, true, reversed)- .peekable()+ .map(|(server_id, collection)| {+ (+ *server_id,+ collection+ .entries_in_range::<T>(search_range.clone(), self, true, reversed)+ .peekable(),+ )}).collect();@@ -5201,7 +5218,7 @@ impl BufferSnapshot {let (next_ix, _) = iterators.iter_mut().enumerate()- .flat_map(|(ix, iter)| Some((ix, iter.peek()?)))+ .flat_map(|(ix, (_, iter))| Some((ix, iter.peek()?))).min_by(|(_, a), (_, b)| {let cmp = a.range@@ -5213,7 +5230,9 @@ impl BufferSnapshot {.then(a.diagnostic.group_id.cmp(&b.diagnostic.group_id));if reversed { cmp.reverse() } else { cmp }})?;- iterators[next_ix].next()+ let (server_id, iterator) = iterators.get_mut(next_ix)?;+ let server_id = *server_id;+ iterator.next().map(|entry| (server_id, entry))})}diff --git a/crates/language/src/buffer_tests.rs b/crates/language/src/buffer_tests.rsindex f5b08929066..15e38f2479f 100644--- a/crates/language/src/buffer_tests.rs+++ b/crates/language/src/buffer_tests.rs@@ -4118,7 +4118,7 @@ fn test_random_collaboration(cx: &mut App, mut rng: StdRng) {DiagnosticEntry::new(range,Diagnostic {- message: post_inc(&mut next_diagnostic_id).to_string(),+ message: post_inc(&mut next_diagnostic_id).to_string().into(),..Default::default()},)diff --git a/crates/language/src/diagnostic.rs b/crates/language/src/diagnostic.rsindex 236d4cc7294..e689231a394 100644--- a/crates/language/src/diagnostic.rs+++ b/crates/language/src/diagnostic.rs@@ -1,9 +1,240 @@use gpui::SharedString;-use lsp::{DiagnosticSeverity, NumberOrString};-use serde::{Deserialize, Serialize};+use lsp::{DiagnosticSeverity, MarkupContent, MarkupKind, NumberOrString};+use serde::{Deserialize, Deserializer, Serialize, Serializer};use serde_json::Value;use std::ops::Range;+/// A diagnostic's display text together with the information needed to render it and+/// round-trip server-provided markup.+///+/// The text is shared so large Markdown messages do not need separate owned copies for+/// display and LSP requests.+#[derive(Clone, Debug, PartialEq, Eq)]+pub struct DiagnosticMessage {+ text: SharedString,+ rendering: DiagnosticMessageRendering,+}++#[derive(Clone, Debug, PartialEq, Eq)]+enum DiagnosticMessageRendering {+ Plain,+ AdapterMarkdown(SharedString),+ LspMarkup {+ kind: MarkupKind,+ /// Kept only when trimming changes the display text.+ untrimmed: Option<SharedString>,+ },+}++impl DiagnosticMessage {+ pub fn plain(text: impl Into<SharedString>) -> Self {+ Self {+ text: text.into(),+ rendering: DiagnosticMessageRendering::Plain,+ }+ }++ pub fn plain_with_adapter_markdown(+ text: impl Into<SharedString>,+ markdown: Option<SharedString>,+ ) -> Self {+ let text = text.into();+ let rendering = markdown.map_or(DiagnosticMessageRendering::Plain, |markdown| {+ DiagnosticMessageRendering::AdapterMarkdown(if markdown == text {+ text.clone()+ } else {+ markdown+ })+ });+ Self { text, rendering }+ }++ pub fn from_lsp_markup(markup: &MarkupContent) -> Self {+ let trimmed = markup.value.trim();+ let (text, untrimmed) = if trimmed == markup.value {+ (SharedString::from(markup.value.as_str()), None)+ } else {+ (+ SharedString::from(trimmed),+ Some(SharedString::from(markup.value.as_str())),+ )+ };+ Self {+ text,+ rendering: DiagnosticMessageRendering::LspMarkup {+ kind: markup.kind.clone(),+ untrimmed,+ },+ }+ }++ pub fn as_str(&self) -> &str {+ &self.text+ }++ pub fn as_shared_string(&self) -> &SharedString {+ &self.text+ }++ pub fn markdown(&self) -> Option<&str> {+ match &self.rendering {+ DiagnosticMessageRendering::Plain => None,+ DiagnosticMessageRendering::AdapterMarkdown(markdown) => Some(markdown),+ DiagnosticMessageRendering::LspMarkup {+ kind: MarkupKind::Markdown,+ untrimmed,+ } => Some(untrimmed.as_ref().unwrap_or(&self.text)),+ DiagnosticMessageRendering::LspMarkup {+ kind: MarkupKind::PlainText,+ ..+ } => None,+ }+ }++ pub fn lsp_markup(&self) -> Option<(&MarkupKind, &str)> {+ match &self.rendering {+ DiagnosticMessageRendering::LspMarkup { kind, untrimmed } => {+ Some((kind, untrimmed.as_ref().unwrap_or(&self.text)))+ }+ DiagnosticMessageRendering::Plain | DiagnosticMessageRendering::AdapterMarkdown(_) => {+ None+ }+ }+ }++ pub fn has_lsp_markup(&self) -> bool {+ self.lsp_markup().is_some()+ }++ pub fn rendered_eq(&self, other: &Self) -> bool {+ self.text == other.text && self.markdown() == other.markdown()+ }++ pub fn to_lsp_message(&self) -> lsp::DiagnosticMessage {+ if let Some((kind, value)) = self.lsp_markup() {+ lsp::DiagnosticMessage::MarkupContent(MarkupContent {+ kind: kind.clone(),+ value: value.to_string(),+ })+ } else {+ lsp::DiagnosticMessage::String(self.text.to_string())+ }+ }+}++impl Default for DiagnosticMessage {+ fn default() -> Self {+ Self::plain(SharedString::default())+ }+}++impl AsRef<str> for DiagnosticMessage {+ fn as_ref(&self) -> &str {+ self.as_str()+ }+}++impl std::fmt::Display for DiagnosticMessage {+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ formatter.write_str(self.as_str())+ }+}++impl From<String> for DiagnosticMessage {+ fn from(text: String) -> Self {+ Self::plain(SharedString::from(text))+ }+}++impl From<&str> for DiagnosticMessage {+ fn from(text: &str) -> Self {+ Self::plain(SharedString::from(text))+ }+}++impl From<SharedString> for DiagnosticMessage {+ fn from(text: SharedString) -> Self {+ Self::plain(text)+ }+}++#[derive(Serialize)]+struct SerializedDiagnosticMessage<'a> {+ message: &'a str,+ markdown: Option<&'a str>,+ lsp_markup: Option<SerializedMarkupContent<'a>>,+}++#[derive(Serialize)]+struct SerializedMarkupContent<'a> {+ kind: &'a MarkupKind,+ value: &'a str,+}++impl Serialize for DiagnosticMessage {+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>+ where+ S: Serializer,+ {+ let lsp_markup = match &self.rendering {+ DiagnosticMessageRendering::LspMarkup { kind, untrimmed } => {+ Some(SerializedMarkupContent {+ kind,+ value: untrimmed.as_ref().unwrap_or(&self.text),+ })+ }+ DiagnosticMessageRendering::Plain | DiagnosticMessageRendering::AdapterMarkdown(_) => {+ None+ }+ };+ SerializedDiagnosticMessage {+ message: self.as_str(),+ markdown: self.markdown(),+ lsp_markup,+ }+ .serialize(serializer)+ }+}++#[derive(Deserialize)]+struct DeserializedDiagnosticMessage {+ message: SharedString,+ #[serde(default)]+ markdown: Option<SharedString>,+ #[serde(default)]+ lsp_markup: Option<DeserializedMarkupContent>,+}++#[derive(Deserialize)]+struct DeserializedMarkupContent {+ kind: MarkupKind,+ value: SharedString,+}++impl<'de> Deserialize<'de> for DiagnosticMessage {+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>+ where+ D: Deserializer<'de>,+ {+ let serialized = DeserializedDiagnosticMessage::deserialize(deserializer)?;+ if let Some(markup) = serialized.lsp_markup {+ let untrimmed = (markup.value != serialized.message).then_some(markup.value);+ Ok(Self {+ text: serialized.message,+ rendering: DiagnosticMessageRendering::LspMarkup {+ kind: markup.kind,+ untrimmed,+ },+ })+ } else {+ Ok(Self::plain_with_adapter_markdown(+ serialized.message,+ serialized.markdown,+ ))+ }+ }+}+/// A diagnostic associated with a certain range of a buffer.#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]pub struct Diagnostic {@@ -17,9 +248,8 @@ pub struct Diagnostic {/// Whether this diagnostic is a hint, warning, or error.pub severity: DiagnosticSeverity,/// The human-readable message associated with this diagnostic.- pub message: String,- /// The human-readable message (in markdown format)- pub markdown: Option<String>,+ #[serde(flatten)]+ pub message: DiagnosticMessage,/// An id that identifies the group to which this diagnostic belongs.////// When a language server produces a diagnostic with@@ -105,7 +335,6 @@ impl Default for Diagnostic {code_description: None,severity: DiagnosticSeverity::ERROR,message: Default::default(),- markdown: None,group_id: 0,is_primary: false,is_disk_based: false,@@ -116,3 +345,88 @@ impl Default for Diagnostic {}}}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_adapter_markdown_round_trips_as_plain_text() {+ let message =+ DiagnosticMessage::plain_with_adapter_markdown("message", Some("message".into()));++ assert_eq!(message.markdown(), Some("message"));+ assert!(!message.has_lsp_markup());+ assert_eq!(+ message.to_lsp_message(),+ lsp::DiagnosticMessage::String("message".to_string())+ );+ }++ #[test]+ fn test_diagnostic_message_reuses_server_markup_text() {+ let message = DiagnosticMessage::from_lsp_markup(&MarkupContent {+ kind: MarkupKind::Markdown,+ value: "**message**".to_string(),+ });++ assert!(matches!(+ &message.rendering,+ DiagnosticMessageRendering::LspMarkup {+ untrimmed: None,+ ..+ }+ ));+ assert_eq!(message.markdown(), Some("**message**"));+ }++ #[test]+ fn test_diagnostic_message_preserves_lsp_markup() {+ let markdown = MarkupContent {+ kind: MarkupKind::Markdown,+ value: "\n**message**\n".to_string(),+ };+ let message = DiagnosticMessage::from_lsp_markup(&markdown);+ assert_eq!(message.as_str(), "**message**");+ assert_eq!(message.markdown(), Some("\n**message**\n"));+ assert!(message.has_lsp_markup());+ assert_eq!(+ message.to_lsp_message(),+ lsp::DiagnosticMessage::MarkupContent(markdown)+ );++ let plain_text = MarkupContent {+ kind: MarkupKind::PlainText,+ value: " plain text ".to_string(),+ };+ let message = DiagnosticMessage::from_lsp_markup(&plain_text);+ assert_eq!(message.as_str(), "plain text");+ assert_eq!(message.markdown(), None);+ assert_eq!(+ message.to_lsp_message(),+ lsp::DiagnosticMessage::MarkupContent(plain_text)+ );+ }++ #[test]+ fn test_diagnostic_message_serialization_remains_flat() {+ let message = DiagnosticMessage::from_lsp_markup(&MarkupContent {+ kind: MarkupKind::Markdown,+ value: "\n**message**\n".to_string(),+ });+ let diagnostic = Diagnostic {+ message,+ ..Diagnostic::default()+ };++ let serialized = serde_json::to_value(&diagnostic).expect("serialize diagnostic");+ assert_eq!(serialized["message"], "**message**");+ assert_eq!(serialized["markdown"], "\n**message**\n");+ assert_eq!(serialized["lsp_markup"]["kind"], "markdown");+ assert_eq!(serialized["lsp_markup"]["value"], "\n**message**\n");++ let deserialized: Diagnostic =+ serde_json::from_value(serialized).expect("deserialize diagnostic");+ assert_eq!(deserialized, diagnostic);+ }+}diff --git a/crates/language/src/diagnostic_set.rs b/crates/language/src/diagnostic_set.rsindex 04618fb1a43..70dea04e047 100644--- a/crates/language/src/diagnostic_set.rs+++ b/crates/language/src/diagnostic_set.rs@@ -178,7 +178,7 @@ impl DiagnosticEntry<PointUtf16> {code: self.diagnostic.code.clone(),severity: Some(self.diagnostic.severity),source: self.diagnostic.source.clone(),- message: self.diagnostic.message.clone(),+ message: self.diagnostic.message.to_lsp_message(),data: self.diagnostic.data.clone(),related_information,..Default::default()diff --git a/crates/language/src/language.rs b/crates/language/src/language.rsindex fadca37b97b..82580344479 100644--- a/crates/language/src/language.rs+++ b/crates/language/src/language.rs@@ -26,6 +26,8 @@ mod toolchain;#[cfg(test)]pub mod buffer_tests;+#[cfg(test)]+mod proto_diagnostics_tests;pub use crate::language_settings::{AutoIndentMode, EditPredictionPromptFormat, EditPredictionsMode, IndentGuideSettings,@@ -100,7 +102,9 @@ use util::rel_path::RelPath;pub use available_languages::AvailableLanguage;pub use buffer::Operation;pub use buffer::*;-pub use diagnostic::{Diagnostic, DiagnosticSourceKind, RelatedInformation, RelatedLocation};+pub use diagnostic::{+ Diagnostic, DiagnosticMessage, DiagnosticSourceKind, RelatedInformation, RelatedLocation,+};pub use diagnostic_set::{DiagnosticEntry, DiagnosticEntryRef, DiagnosticGroup};pub use file_content::{ByteContent, DecodedText, FILE_ANALYSIS_BYTES, analyze_byte_content, decode_text, encode_text,diff --git a/crates/language/src/proto.rs b/crates/language/src/proto.rsindex a6d3bfb389e..a9e5e5bf23e 100644--- a/crates/language/src/proto.rs+++ b/crates/language/src/proto.rs@@ -1,6 +1,9 @@//! Handles conversions of `language` items to and from the [`rpc`] protocol.-use crate::{CursorShape, Diagnostic, DiagnosticSourceKind, diagnostic_set::DiagnosticEntry};+use crate::{+ CursorShape, Diagnostic, DiagnosticMessage, DiagnosticSourceKind,+ diagnostic_set::DiagnosticEntry,+};use anyhow::{Context as _, Result};use clock::ReplicaId;use gpui::SharedString;@@ -210,41 +213,51 @@ pub fn serialize_diagnostics<'a>() -> Vec<proto::Diagnostic> {diagnostics.into_iter()- .map(|entry| proto::Diagnostic {- source: entry.diagnostic.source.clone(),- source_kind: match entry.diagnostic.source_kind {- DiagnosticSourceKind::Pulled => proto::diagnostic::SourceKind::Pulled,- DiagnosticSourceKind::Pushed => proto::diagnostic::SourceKind::Pushed,- DiagnosticSourceKind::Other => proto::diagnostic::SourceKind::Other,- } as i32,- start: Some(serialize_anchor(&entry.range.start)),- end: Some(serialize_anchor(&entry.range.end)),- message: entry.diagnostic.message.clone(),- markdown: entry.diagnostic.markdown.clone(),- severity: match entry.diagnostic.severity {- DiagnosticSeverity::ERROR => proto::diagnostic::Severity::Error,- DiagnosticSeverity::WARNING => proto::diagnostic::Severity::Warning,- DiagnosticSeverity::INFORMATION => proto::diagnostic::Severity::Information,- DiagnosticSeverity::HINT => proto::diagnostic::Severity::Hint,- _ => proto::diagnostic::Severity::None,- } as i32,- group_id: entry.diagnostic.group_id as u64,- is_primary: entry.diagnostic.is_primary,- underline: entry.diagnostic.underline,- code: entry.diagnostic.code.as_ref().map(|s| s.to_string()),- code_description: entry- .diagnostic- .code_description- .as_ref()- .map(|s| s.to_string()),- is_disk_based: entry.diagnostic.is_disk_based,- is_unnecessary: entry.diagnostic.is_unnecessary,- data: entry.diagnostic.data.as_ref().map(|data| data.to_string()),- registration_id: entry- .diagnostic- .registration_id- .as_ref()- .map(ToString::to_string),+ .map(|entry| {+ let lsp_markup = entry.diagnostic.message.lsp_markup();+ proto::Diagnostic {+ source: entry.diagnostic.source.clone(),+ source_kind: match entry.diagnostic.source_kind {+ DiagnosticSourceKind::Pulled => proto::diagnostic::SourceKind::Pulled,+ DiagnosticSourceKind::Pushed => proto::diagnostic::SourceKind::Pushed,+ DiagnosticSourceKind::Other => proto::diagnostic::SourceKind::Other,+ } as i32,+ start: Some(serialize_anchor(&entry.range.start)),+ end: Some(serialize_anchor(&entry.range.end)),+ message: entry.diagnostic.message.to_string(),+ markdown: match lsp_markup {+ Some(_) => None,+ None => entry.diagnostic.message.markdown().map(ToOwned::to_owned),+ },+ markup_message_kind: lsp_markup.map(|(kind, _)| serialize_markup_kind(kind) as i32),+ untrimmed_markup_message: lsp_markup.and_then(|(_, value)| {+ (value != entry.diagnostic.message.as_str()).then(|| value.to_string())+ }),+ severity: match entry.diagnostic.severity {+ DiagnosticSeverity::ERROR => proto::diagnostic::Severity::Error,+ DiagnosticSeverity::WARNING => proto::diagnostic::Severity::Warning,+ DiagnosticSeverity::INFORMATION => proto::diagnostic::Severity::Information,+ DiagnosticSeverity::HINT => proto::diagnostic::Severity::Hint,+ _ => proto::diagnostic::Severity::None,+ } as i32,+ group_id: entry.diagnostic.group_id as u64,+ is_primary: entry.diagnostic.is_primary,+ underline: entry.diagnostic.underline,+ code: entry.diagnostic.code.as_ref().map(|s| s.to_string()),+ code_description: entry+ .diagnostic+ .code_description+ .as_ref()+ .map(|s| s.to_string()),+ is_disk_based: entry.diagnostic.is_disk_based,+ is_unnecessary: entry.diagnostic.is_unnecessary,+ data: entry.diagnostic.data.as_ref().map(|data| data.to_string()),+ registration_id: entry+ .diagnostic+ .registration_id+ .as_ref()+ .map(ToString::to_string),+ }}).collect()}@@ -432,6 +445,20 @@ pub fn deserialize_selection(selection: proto::Selection) -> Option<Selection<An})}+pub fn serialize_markup_kind(kind: &lsp::MarkupKind) -> proto::MarkupKind {+ match kind {+ lsp::MarkupKind::PlainText => proto::MarkupKind::PlainText,+ lsp::MarkupKind::Markdown => proto::MarkupKind::Markdown,+ }+}++pub fn deserialize_markup_kind(kind: i32) -> Option<lsp::MarkupKind> {+ match proto::MarkupKind::try_from(kind).ok()? {+ proto::MarkupKind::PlainText => Some(lsp::MarkupKind::PlainText),+ proto::MarkupKind::Markdown => Some(lsp::MarkupKind::Markdown),+ }+}+/// Deserializes a list of diagnostics from the RPC representation.pub fn deserialize_diagnostics(diagnostics: Vec<proto::Diagnostic>,@@ -444,6 +471,21 @@ pub fn deserialize_diagnostics(} else {None};+ let message = match diagnostic+ .markup_message_kind+ .and_then(deserialize_markup_kind)+ {+ Some(kind) => DiagnosticMessage::from_lsp_markup(&lsp::MarkupContent {+ kind,+ value: diagnostic+ .untrimmed_markup_message+ .unwrap_or(diagnostic.message),+ }),+ None => DiagnosticMessage::plain_with_adapter_markdown(+ diagnostic.message,+ diagnostic.markdown.map(SharedString::from),+ ),+ };Some(DiagnosticEntry::new(deserialize_anchor(diagnostic.start?)?..deserialize_anchor(diagnostic.end?)?,Diagnostic {@@ -457,8 +499,7 @@ pub fn deserialize_diagnostics(proto::diagnostic::Severity::Hint => DiagnosticSeverity::HINT,proto::diagnostic::Severity::None => return None,},- message: diagnostic.message,- markdown: diagnostic.markdown,+ message,group_id: diagnostic.group_id as usize,code: diagnostic.code.map(lsp::NumberOrString::from_string),code_description: diagnosticdiff --git a/crates/language/src/proto_diagnostics_tests.rs b/crates/language/src/proto_diagnostics_tests.rsnew file mode 100644index 00000000000..e2de5e6e9ff--- /dev/null+++ b/crates/language/src/proto_diagnostics_tests.rs@@ -0,0 +1,103 @@+use crate::{+ Diagnostic, DiagnosticMessage,+ diagnostic_set::DiagnosticEntry,+ proto::{deserialize_diagnostics, serialize_diagnostics},+};+use pretty_assertions::assert_eq;+use rpc::proto;+use text::{Anchor, BufferId};++#[test]+fn test_markup_diagnostics_round_trip() {+ let untrimmed_entry = markup_entry(lsp::MarkupKind::Markdown, "\n**message**\n");+ let trimmed_entry = markup_entry(lsp::MarkupKind::Markdown, "**message**");+ let plain_text_entry = markup_entry(lsp::MarkupKind::PlainText, " plain ");++ let serialized = serialize_diagnostics([&untrimmed_entry, &trimmed_entry, &plain_text_entry]);+ assert_eq!(serialized[0].message, "**message**");+ assert_eq!(serialized[0].markdown, None);+ assert_eq!(+ serialized[0].markup_message_kind,+ Some(proto::MarkupKind::Markdown as i32)+ );+ assert_eq!(+ serialized[0].untrimmed_markup_message,+ Some("\n**message**\n".to_string())+ );+ assert_eq!(serialized[1].message, "**message**");+ assert_eq!(serialized[1].untrimmed_markup_message, None);+ assert_eq!(+ serialized[1].markup_message_kind,+ Some(proto::MarkupKind::Markdown as i32)+ );+ assert_eq!(serialized[2].message, "plain");+ assert_eq!(serialized[2].markdown, None);+ assert_eq!(+ serialized[2].markup_message_kind,+ Some(proto::MarkupKind::PlainText as i32)+ );+ assert_eq!(+ serialized[2].untrimmed_markup_message,+ Some(" plain ".to_string())+ );++ let deserialized = deserialize_diagnostics(serialized);+ assert_eq!(+ deserialized.as_ref(),+ [untrimmed_entry, trimmed_entry, plain_text_entry]+ );+}++#[test]+fn test_plain_and_adapter_markdown_diagnostics_round_trip() {+ let plain_entry = entry(DiagnosticMessage::plain("plain message"));+ let adapter_entry = entry(DiagnosticMessage::plain_with_adapter_markdown(+ "message",+ Some("**message**".into()),+ ));++ let serialized = serialize_diagnostics([&plain_entry, &adapter_entry]);+ assert_eq!(serialized[0].message, "plain message");+ assert_eq!(serialized[0].markdown, None);+ assert_eq!(serialized[0].markup_message_kind, None);+ assert_eq!(serialized[0].untrimmed_markup_message, None);+ assert_eq!(serialized[1].message, "message");+ assert_eq!(serialized[1].markdown, Some("**message**".to_string()));+ assert_eq!(serialized[1].markup_message_kind, None);+ assert_eq!(serialized[1].untrimmed_markup_message, None);++ let deserialized = deserialize_diagnostics(serialized);+ assert_eq!(deserialized.as_ref(), [plain_entry, adapter_entry]);+}++#[test]+fn test_unknown_markup_kind_degrades_to_plain_message() {+ let entry = markup_entry(lsp::MarkupKind::Markdown, "**message**");+ let mut serialized = serialize_diagnostics([&entry]);+ serialized[0].markup_message_kind = Some(42);++ let deserialized = deserialize_diagnostics(serialized);+ assert_eq!(deserialized.len(), 1);+ assert_eq!(+ deserialized[0].diagnostic.message,+ DiagnosticMessage::plain("**message**")+ );+}++fn markup_entry(kind: lsp::MarkupKind, value: &str) -> DiagnosticEntry<Anchor> {+ entry(DiagnosticMessage::from_lsp_markup(&lsp::MarkupContent {+ kind,+ value: value.to_string(),+ }))+}++fn entry(message: DiagnosticMessage) -> DiagnosticEntry<Anchor> {+ let buffer_id = BufferId::new(1).unwrap();+ DiagnosticEntry::new(+ Anchor::min_max_range_for_buffer(buffer_id),+ Diagnostic {+ message,+ ..Diagnostic::default()+ },+ )+}diff --git a/crates/languages/src/rust.rs b/crates/languages/src/rust.rsindex b0693f7107a..5bb3089c79a 100644--- a/crates/languages/src/rust.rs+++ b/crates/languages/src/rust.rs@@ -326,7 +326,10 @@ impl LspAdapter for RustLspAdapter {.iter_mut().flatten().map(|info| &mut info.message)- .chain([&mut diagnostic.message])+ .chain(match &mut diagnostic.message {+ lsp::DiagnosticMessage::String(message) => Some(message),+ lsp::DiagnosticMessage::MarkupContent(_) => None,+ }){if let Cow::Owned(sanitized) = REGEX.replace_all(message, "`$1`") {*message = sanitized;@@ -1481,42 +1484,75 @@ mod tests {#[gpui::test]async fn test_process_rust_diagnostics() {+ let markdown_message = lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "consider importing this struct: `use b::c;\n`".to_string(),+ };+ let plain_text_message = lsp::MarkupContent {+ kind: lsp::MarkupKind::PlainText,+ value: "consider importing this struct: `use b::c;\n`".to_string(),+ };let mut params = lsp::PublishDiagnosticsParams {uri: lsp::Uri::from_file_path(path!("/a")).unwrap(),version: None,diagnostics: vec![// no newlineslsp::Diagnostic {- message: "use of moved value `a`".to_string(),+ message: lsp::DiagnosticMessage::from("use of moved value `a`"),..Default::default()},// newline at the end of a code spanlsp::Diagnostic {- message: "consider importing this struct: `use b::c;\n`".to_string(),+ message: lsp::DiagnosticMessage::from(+ "consider importing this struct: `use b::c;\n`",+ ),..Default::default()},// code span starting right after a newlinelsp::Diagnostic {- message: "cannot borrow `self.d` as mutable\n`self` is a `&` reference"- .to_string(),+ message: lsp::DiagnosticMessage::from(+ "cannot borrow `self.d` as mutable\n`self` is a `&` reference".to_string(),+ ),+ ..Default::default()+ },+ lsp::Diagnostic {+ message: lsp::DiagnosticMessage::from(markdown_message.clone()),+ ..Default::default()+ },+ lsp::Diagnostic {+ message: lsp::DiagnosticMessage::from(plain_text_message.clone()),..Default::default()},],};RustLspAdapter.process_diagnostics(&mut params, LanguageServerId(0));- assert_eq!(params.diagnostics[0].message, "use of moved value `a`");+ assert_eq!(+ params.diagnostics[0].message,+ lsp::DiagnosticMessage::from("use of moved value `a`")+ );// remove trailing newline from code spanassert_eq!(params.diagnostics[1].message,- "consider importing this struct: `use b::c;`"+ lsp::DiagnosticMessage::from("consider importing this struct: `use b::c;`"));// do not remove newline before the start of code spanassert_eq!(params.diagnostics[2].message,- "cannot borrow `self.d` as mutable\n`self` is a `&` reference"+ lsp::DiagnosticMessage::from(+ "cannot borrow `self.d` as mutable\n`self` is a `&` reference"+ )+ );++ assert_eq!(+ params.diagnostics[3].message,+ lsp::DiagnosticMessage::from(markdown_message)+ );+ assert_eq!(+ params.diagnostics[4].message,+ lsp::DiagnosticMessage::from(plain_text_message));}diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rsindex f31e9fce8b3..6f7820763d9 100644--- a/crates/lsp/src/lsp.rs+++ b/crates/lsp/src/lsp.rs@@ -1020,6 +1020,7 @@ impl LanguageServer {diagnostic: pull_diagnostics.then_some(DiagnosticClientCapabilities {dynamic_registration: Some(true),related_document_support: Some(true),+ markup_message_support: Some(true),}),color_provider: Some(DocumentColorClientCapabilities {dynamic_registration: Some(true),diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rsindex 6370991cb68..5635996ff88 100644--- a/crates/project/src/lsp_command.rs+++ b/crates/project/src/lsp_command.rs@@ -21,8 +21,8 @@ use language::{language_settings::{InlayHintKind, LanguageSettings},lsp_to_symbol_kind, point_from_lsp, point_to_lsp,proto::{- deserialize_anchor, deserialize_anchor_range, deserialize_version, serialize_anchor,- serialize_anchor_range, serialize_version,+ deserialize_anchor, deserialize_anchor_range, deserialize_markup_kind, deserialize_version,+ serialize_anchor, serialize_anchor_range, serialize_markup_kind, serialize_version,},range_from_lsp, range_to_lsp,};@@ -2952,11 +2952,21 @@ impl LspCommand for GetCodeActions {let text_document = make_text_document_identifier(path)?;let snapshot = buffer.snapshot();let mut relevant_diagnostics = Vec::new();- for entry in snapshot.diagnostic_entries_in_range(self.range.clone(), false) {+ let target_server_id = language_server.server_id();+ for (source_server_id, entry) in+ snapshot.diagnostic_entries_in_range_with_server_id(self.range.clone(), false)+ {+ let downgrade_markup =+ source_server_id != target_server_id && entry.diagnostic.message.has_lsp_markup();let entry = entry.clone().map_coordinates(|range| {range.start.to_point_utf16(&snapshot)..range.end.to_point_utf16(&snapshot)});- relevant_diagnostics.push(entry.to_lsp_diagnostic_stub(&text_document.uri)?);+ let mut diagnostic = entry.to_lsp_diagnostic_stub(&text_document.uri)?;+ if downgrade_markup {+ diagnostic.message =+ lsp::DiagnosticMessage::from(entry.diagnostic.message.as_str());+ }+ relevant_diagnostics.push(diagnostic);}let only = if let Some(requested) = &self.kinds {@@ -4496,6 +4506,17 @@ impl GetDocumentDiagnostics {}).collect::<Vec<_>>();+ let message = match diagnostic+ .markup_message_kind+ .and_then(deserialize_markup_kind)+ {+ Some(kind) => lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind,+ value: diagnostic.message,+ }),+ None => lsp::DiagnosticMessage::from(diagnostic.message),+ };+Ok(lsp::Diagnostic {range: language::range_to_lsp(range)?,severity: match proto::lsp_diagnostic::Severity::try_from(diagnostic.severity)@@ -4518,14 +4539,20 @@ impl GetDocumentDiagnostics {}),related_information: Some(related_information),tags: Some(tags),- source: diagnostic.source.clone(),- message: diagnostic.message,+ source: diagnostic.source,+ message,data,})}pub fn serialize_lsp_diagnostic(diagnostic: lsp::Diagnostic) -> Result<proto::LspDiagnostic> {let range = language::range_from_lsp(diagnostic.range);+ let (message, markup_message_kind) = match diagnostic.message {+ lsp::DiagnosticMessage::String(message) => (message, None),+ lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent { kind, value }) => {+ (value, Some(serialize_markup_kind(&kind) as i32))+ }+ };let related_information = diagnostic.related_information.unwrap_or_default()@@ -4589,7 +4616,8 @@ impl GetDocumentDiagnostics {code_description: diagnostic.code_description.and_then(|desc| desc.href.map(|url| url.to_string())),- message: diagnostic.message,+ message,+ markup_message_kind,data: diagnostic.data.as_ref().map(|data| data.to_string()),})}diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rsindex c25f380ef16..42240dd7c5e 100644--- a/crates/project/src/lsp_store.rs+++ b/crates/project/src/lsp_store.rs@@ -76,11 +76,12 @@ use http_client::HttpClient;use itertools::Itertools as _;use language::{Bias, BinaryStatus, Buffer, BufferRow, BufferSnapshot, CachedLspAdapter, Capability, CodeLabel,- CodeLabelExt, Diagnostic, DiagnosticEntry, DiagnosticSet, DiagnosticSourceKind, Diff,- File as _, Language, LanguageAwareStyling, LanguageName, LanguageRegistry, LocalFile,- LspAdapter, LspAdapterDelegate, LspInstaller, ManifestDelegate, ManifestName, ModelineSettings,- OffsetUtf16, Patch, PointUtf16, RelatedInformation, RelatedLocation, TextBufferSnapshot,- ToOffset, ToOffsetUtf16, ToPointUtf16, Toolchain, Transaction, Unclipped,+ CodeLabelExt, Diagnostic, DiagnosticEntry, DiagnosticMessage, DiagnosticSet,+ DiagnosticSourceKind, Diff, File as _, Language, LanguageAwareStyling, LanguageName,+ LanguageRegistry, LocalFile, LspAdapter, LspAdapterDelegate, LspInstaller, ManifestDelegate,+ ManifestName, ModelineSettings, OffsetUtf16, Patch, PointUtf16, RelatedInformation,+ RelatedLocation, TextBufferSnapshot, ToOffset, ToOffsetUtf16, ToPointUtf16, Toolchain,+ Transaction, Unclipped,language_settings::{AllLanguageSettings, FormatOnSave, Formatter, LanguageSettings, LineEndingSetting,all_language_settings,@@ -2828,7 +2829,7 @@ impl LocalLspStore {.then_with(|| b.is_primary.cmp(&a.is_primary)).then_with(|| a.is_disk_based.cmp(&b.is_disk_based)).then_with(|| a.severity.cmp(&b.severity))- .then_with(|| a.message.cmp(&b.message))+ .then_with(|| a.message.as_str().cmp(b.message.as_str()))}let mut diagnostics = Vec::with_capacity(new_diagnostics.len() + reused_diagnostics.len());@@ -12247,6 +12248,20 @@ impl LspStore {primary_diagnostic_group_ids.insert((source, diagnostic.code.clone(), range.clone()), group_id);+ let message = match &diagnostic.message {+ lsp::DiagnosticMessage::String(message) => {+ DiagnosticMessage::plain_with_adapter_markdown(+ message.trim(),+ adapter+ .as_ref()+ .and_then(|adapter| adapter.diagnostic_message_to_markdown(message))+ .map(SharedString::from),+ )+ }+ lsp::DiagnosticMessage::MarkupContent(markup) => {+ DiagnosticMessage::from_lsp_markup(markup)+ }+ };diagnostics.push(DiagnosticEntry {range,related_information: related_information_from_lsp(@@ -12262,10 +12277,7 @@ impl LspStore {.as_ref().and_then(|d| d.href.clone()),severity: diagnostic.severity.unwrap_or(DiagnosticSeverity::ERROR),- markdown: adapter.as_ref().and_then(|adapter| {- adapter.diagnostic_message_to_markdown(&diagnostic.message)- }),- message: diagnostic.message.trim().to_string(),+ message,group_id,is_primary: true,is_disk_based,@@ -12291,10 +12303,16 @@ impl LspStore {.as_ref().and_then(|d| d.href.clone()),severity: DiagnosticSeverity::INFORMATION,- markdown: adapter.as_ref().and_then(|adapter| {- adapter.diagnostic_message_to_markdown(&info.message)- }),- message: info.message.trim().to_string(),+ message: DiagnosticMessage::plain_with_adapter_markdown(+ info.message.trim(),+ adapter+ .as_ref()+ .and_then(|adapter| {+ adapter+ .diagnostic_message_to_markdown(&info.message)+ })+ .map(SharedString::from),+ ),group_id,is_primary: false,is_disk_based,diff --git a/crates/project/src/lsp_store/clangd_ext.rs b/crates/project/src/lsp_store/clangd_ext.rsindex 466d0c6e2a0..7e6ebc30d06 100644--- a/crates/project/src/lsp_store/clangd_ext.rs+++ b/crates/project/src/lsp_store/clangd_ext.rs@@ -30,7 +30,7 @@ impl lsp::notification::Notification for InactiveRegions {pub fn is_inactive_region(diag: &Diagnostic) -> bool {diag.is_unnecessary&& diag.severity == INACTIVE_DIAGNOSTIC_SEVERITY- && diag.message == INACTIVE_REGION_MESSAGE+ && diag.message.as_str() == INACTIVE_REGION_MESSAGE&& diag.source.as_ref()@@ -39,7 +39,7 @@ pub fn is_inactive_region(diag: &Diagnostic) -> bool {pub fn is_lsp_inactive_region(diag: &lsp::Diagnostic) -> bool {diag.severity == Some(INACTIVE_DIAGNOSTIC_SEVERITY)- && diag.message == INACTIVE_REGION_MESSAGE+ && diag.message.as_str() == INACTIVE_REGION_MESSAGE&& diag.source.as_ref()@@ -71,7 +71,7 @@ pub fn register_notifications(range,severity: Some(INACTIVE_DIAGNOSTIC_SEVERITY),source: Some(CLANGD_SERVER_NAME.to_string()),- message: INACTIVE_REGION_MESSAGE.to_string(),+ message: lsp::DiagnosticMessage::from(INACTIVE_REGION_MESSAGE),tags: Some(vec![lsp::DiagnosticTag::UNNECESSARY]),..lsp::Diagnostic::default()})diff --git a/crates/project/tests/integration/lsp_command.rs b/crates/project/tests/integration/lsp_command.rsindex 83fcc116a0f..fbfcb7311a8 100644--- a/crates/project/tests/integration/lsp_command.rs+++ b/crates/project/tests/integration/lsp_command.rs@@ -15,7 +15,7 @@ fn test_serialize_lsp_diagnostic() {severity: Some(DiagnosticSeverity::ERROR),code: Some(lsp::NumberOrString::String("E001".to_string())),source: Some("test-source".to_string()),- message: "Test error message".to_string(),+ message: lsp::DiagnosticMessage::from("Test error message"),related_information: None,tags: Some(vec![DiagnosticTag::DEPRECATED]),code_description: None,@@ -53,6 +53,7 @@ fn test_deserialize_lsp_diagnostic() {tags: vec![],code_description: None,data: None,+ markup_message_kind: None,};let lsp_diagnostic = GetDocumentDiagnostics::deserialize_lsp_diagnostic(proto_diagnostic)@@ -68,7 +69,10 @@ fn test_deserialize_lsp_diagnostic() {Some(lsp::NumberOrString::String("ERR".to_string())));assert_eq!(lsp_diagnostic.source, Some("Prism".to_string()));- assert_eq!(lsp_diagnostic.message, "assigned but unused variable - a");+ assert_eq!(+ lsp_diagnostic.message,+ lsp::DiagnosticMessage::from("assigned but unused variable - a")+ );}#[test]@@ -92,7 +96,7 @@ fn test_related_information() {severity: Some(DiagnosticSeverity::INFORMATION),code: None,source: Some("Prism".to_string()),- message: "assigned but unused variable - a".to_string(),+ message: lsp::DiagnosticMessage::from("assigned but unused variable - a"),related_information: Some(vec![related_info]),tags: None,code_description: None,@@ -108,6 +112,38 @@ fn test_related_information() {assert_eq!(related.message, "Related info message");}+#[test]+fn test_serialize_lsp_diagnostic_markup_message() {+ let message = lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "unused variable `a`\n\nsee [docs](https://example.com)".to_string(),+ });+ let lsp_diagnostic = lsp::Diagnostic {+ range: lsp::Range {+ start: lsp::Position::new(0, 1),+ end: lsp::Position::new(2, 3),+ },+ severity: Some(DiagnosticSeverity::WARNING),+ message: message.clone(),+ ..lsp::Diagnostic::default()+ };++ let proto_diagnostic = GetDocumentDiagnostics::serialize_lsp_diagnostic(lsp_diagnostic)+ .expect("Failed to serialize diagnostic");+ assert_eq!(+ proto_diagnostic.message,+ "unused variable `a`\n\nsee [docs](https://example.com)"+ );+ assert_eq!(+ proto_diagnostic.markup_message_kind,+ Some(proto::MarkupKind::Markdown as i32)+ );++ let lsp_diagnostic = GetDocumentDiagnostics::deserialize_lsp_diagnostic(proto_diagnostic)+ .expect("Failed to deserialize diagnostic");+ assert_eq!(lsp_diagnostic.message, message);+}+#[test]fn test_invalid_ranges() {let proto_diagnostic = proto::LspDiagnostic {@@ -121,6 +157,7 @@ fn test_invalid_ranges() {tags: vec![],code_description: None,data: None,+ markup_message_kind: None,};let result = GetDocumentDiagnostics::deserialize_lsp_diagnostic(proto_diagnostic);diff --git a/crates/project/tests/integration/project_tests.rs b/crates/project/tests/integration/project_tests.rsindex fc8270a61fb..04c7e3fc0d7 100644--- a/crates/project/tests/integration/project_tests.rs+++ b/crates/project/tests/integration/project_tests.rs@@ -39,8 +39,8 @@ use gpui::{};use itertools::Itertools;use language::{- Buffer, BufferEvent, Diagnostic, DiagnosticEntry, DiagnosticEntryRef, DiagnosticSet,- DiagnosticSourceKind, DiskState, FakeLspAdapter, Language, LanguageAwareStyling,+ Buffer, BufferEvent, Diagnostic, DiagnosticEntry, DiagnosticEntryRef, DiagnosticMessage,+ DiagnosticSet, DiagnosticSourceKind, DiskState, FakeLspAdapter, Language, LanguageAwareStyling,LanguageConfig, LanguageMatcher, LanguageName, LineEnding, ManifestName, ManifestProvider,ManifestQuery, OffsetRangeExt, Point, ToPoint, Toolchain, ToolchainList, ToolchainLister,ToolchainMetadata,@@ -2642,7 +2642,7 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 5)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "error 1".to_string(),+ message: lsp::DiagnosticMessage::from("error 1"),..Default::default()}],},@@ -2661,7 +2661,7 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 5)),severity: Some(DiagnosticSeverity::WARNING),- message: "error 2".to_string(),+ message: lsp::DiagnosticMessage::from("error 2"),..Default::default()}],},@@ -2753,7 +2753,7 @@ async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 5)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "unused variable 'b'".to_string(),+ message: lsp::DiagnosticMessage::from("unused variable 'b'"),..Default::default()}],},@@ -2772,7 +2772,7 @@ async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 8), lsp::Position::new(0, 9)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "unknown variable 'c'".to_string(),+ message: lsp::DiagnosticMessage::from("unknown variable 'c'"),..Default::default()}],},@@ -2915,7 +2915,7 @@ async fn test_disk_based_diagnostics_progress(cx: &mut gpui::TestAppContext) {diagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 9), lsp::Position::new(0, 10)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "undefined variable 'A'".to_string(),+ message: lsp::DiagnosticMessage::from("undefined variable 'A'"),..Default::default()}],});@@ -2951,7 +2951,7 @@ async fn test_disk_based_diagnostics_progress(cx: &mut gpui::TestAppContext) {range: Point::new(0, 9)..Point::new(0, 10),diagnostic: &Diagnostic {severity: lsp::DiagnosticSeverity::ERROR,- message: "undefined variable 'A'".to_string(),+ message: "undefined variable 'A'".into(),group_id: 0,is_primary: true,source_kind: DiagnosticSourceKind::Pushed,@@ -3114,7 +3114,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestApdiagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 0)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "the message".to_string(),+ message: lsp::DiagnosticMessage::from("the message"),..Default::default()}],});@@ -3125,7 +3125,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestApbuffer.snapshot().diagnostics_in_range::<_, usize>(0..1, false)- .map(|entry| entry.diagnostic.message.clone())+ .map(|entry| entry.diagnostic.message.to_string()).collect::<Vec<_>>(),["the message".to_string()]);@@ -3156,7 +3156,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestApbuffer.snapshot().diagnostics_in_range::<_, usize>(0..1, false)- .map(|entry| entry.diagnostic.message.clone())+ .map(|entry| entry.diagnostic.message.to_string()).collect::<Vec<_>>(),Vec::<String>::new(),);@@ -3636,14 +3636,14 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 9), lsp::Position::new(0, 10)),severity: Some(DiagnosticSeverity::ERROR),- message: "undefined variable 'A'".to_string(),+ message: lsp::DiagnosticMessage::from("undefined variable 'A'"),source: Some("disk".to_string()),..Default::default()},lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(1, 9), lsp::Position::new(1, 11)),severity: Some(DiagnosticSeverity::ERROR),- message: "undefined variable 'BB'".to_string(),+ message: lsp::DiagnosticMessage::from("undefined variable 'BB'"),source: Some("disk".to_string()),..Default::default()},@@ -3651,7 +3651,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {range: lsp::Range::new(lsp::Position::new(2, 9), lsp::Position::new(2, 12)),severity: Some(DiagnosticSeverity::ERROR),source: Some("disk".to_string()),- message: "undefined variable 'CCC'".to_string(),+ message: lsp::DiagnosticMessage::from("undefined variable 'CCC'"),..Default::default()},],@@ -3671,7 +3671,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {Diagnostic {source: Some("disk".into()),severity: DiagnosticSeverity::ERROR,- message: "undefined variable 'BB'".to_string(),+ message: "undefined variable 'BB'".into(),is_disk_based: true,group_id: 1,is_primary: true,@@ -3684,7 +3684,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {Diagnostic {source: Some("disk".into()),severity: DiagnosticSeverity::ERROR,- message: "undefined variable 'CCC'".to_string(),+ message: "undefined variable 'CCC'".into(),is_disk_based: true,group_id: 2,is_primary: true,@@ -3724,14 +3724,14 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 9), lsp::Position::new(0, 10)),severity: Some(DiagnosticSeverity::ERROR),- message: "undefined variable 'A'".to_string(),+ message: lsp::DiagnosticMessage::from("undefined variable 'A'"),source: Some("disk".to_string()),..Default::default()},lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 9), lsp::Position::new(0, 12)),severity: Some(DiagnosticSeverity::WARNING),- message: "unreachable statement".to_string(),+ message: lsp::DiagnosticMessage::from("unreachable statement"),source: Some("disk".to_string()),..Default::default()},@@ -3751,7 +3751,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {Diagnostic {source: Some("disk".into()),severity: DiagnosticSeverity::WARNING,- message: "unreachable statement".to_string(),+ message: "unreachable statement".into(),is_disk_based: true,group_id: 4,is_primary: true,@@ -3764,7 +3764,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {Diagnostic {source: Some("disk".into()),severity: DiagnosticSeverity::ERROR,- message: "undefined variable 'A'".to_string(),+ message: "undefined variable 'A'".into(),is_disk_based: true,group_id: 3,is_primary: true,@@ -3818,14 +3818,14 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(1, 9), lsp::Position::new(1, 11)),severity: Some(DiagnosticSeverity::ERROR),- message: "undefined variable 'BB'".to_string(),+ message: lsp::DiagnosticMessage::from("undefined variable 'BB'"),source: Some("disk".to_string()),..Default::default()},lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 9), lsp::Position::new(0, 10)),severity: Some(DiagnosticSeverity::WARNING),- message: "undefined variable 'A'".to_string(),+ message: lsp::DiagnosticMessage::from("undefined variable 'A'"),source: Some("disk".to_string()),..Default::default()},@@ -3845,7 +3845,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {Diagnostic {source: Some("disk".into()),severity: DiagnosticSeverity::WARNING,- message: "undefined variable 'A'".to_string(),+ message: "undefined variable 'A'".into(),is_disk_based: true,group_id: 6,is_primary: true,@@ -3858,7 +3858,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {Diagnostic {source: Some("disk".into()),severity: DiagnosticSeverity::ERROR,- message: "undefined variable 'BB'".to_string(),+ message: "undefined variable 'BB'".into(),is_disk_based: true,group_id: 5,is_primary: true,@@ -3871,6 +3871,239 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {});}+#[gpui::test]+async fn test_markup_content_diagnostic_messages(cx: &mut gpui::TestAppContext) {+ init_test(cx);++ let text = "+ fn a() { A }+ fn b() { BB }+ "+ .unindent();++ let fs = FakeFs::new(cx.executor());+ fs.insert_tree(path!("/dir"), json!({ "a.rs": text })).await;++ let project = Project::test(fs, [path!("/dir").as_ref()], cx).await;+ let language_registry = project.read_with(cx, |project, _| project.languages().clone());++ language_registry.add(rust_lang());+ let mut fake_servers = language_registry.register_fake_lsp("Rust", FakeLspAdapter::default());++ let buffer = project+ .update(cx, |project, cx| {+ project.open_local_buffer(path!("/dir/a.rs"), cx)+ })+ .await+ .unwrap();+ let _handle = project.update(cx, |project, cx| {+ project.register_buffer_with_language_servers(&buffer, cx)+ });++ let fake_server = fake_servers.next().await.unwrap();+ fake_server.notify::<lsp::notification::PublishDiagnostics>(lsp::PublishDiagnosticsParams {+ uri: lsp::Uri::from_file_path(path!("/dir/a.rs")).unwrap(),+ version: None,+ diagnostics: vec![+ lsp::Diagnostic {+ range: lsp::Range::new(lsp::Position::new(0, 9), lsp::Position::new(0, 10)),+ severity: Some(DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "undefined variable `A`".to_string(),+ }),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(lsp::Position::new(1, 9), lsp::Position::new(1, 11)),+ severity: Some(DiagnosticSeverity::WARNING),+ message: lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind: lsp::MarkupKind::PlainText,+ value: "undefined variable 'BB'".to_string(),+ }),+ ..Default::default()+ },+ ],+ });++ cx.executor().run_until_parked();+ buffer.update(cx, |buffer, _| {+ assert_eq!(+ buffer+ .snapshot()+ .diagnostics_in_range::<_, Point>(Point::new(0, 0)..Point::new(2, 0), false)+ .collect::<Vec<_>>(),+ &[+ DiagnosticEntry {+ range: Point::new(0, 9)..Point::new(0, 10),+ diagnostic: Diagnostic {+ severity: DiagnosticSeverity::ERROR,+ message: DiagnosticMessage::from_lsp_markup(&lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: "undefined variable `A`".to_string(),+ }),+ group_id: 0,+ is_primary: true,+ source_kind: DiagnosticSourceKind::Pushed,+ ..Diagnostic::default()+ },+ related_information: None,+ },+ DiagnosticEntry {+ range: Point::new(1, 9)..Point::new(1, 11),+ diagnostic: Diagnostic {+ severity: DiagnosticSeverity::WARNING,+ message: DiagnosticMessage::from_lsp_markup(&lsp::MarkupContent {+ kind: lsp::MarkupKind::PlainText,+ value: "undefined variable 'BB'".to_string(),+ }),+ group_id: 1,+ is_primary: true,+ source_kind: DiagnosticSourceKind::Pushed,+ ..Diagnostic::default()+ },+ related_information: None,+ },+ ]+ );+ });+}++#[gpui::test]+async fn test_code_actions_downgrade_cross_server_markup_diagnostics(+ cx: &mut gpui::TestAppContext,+) {+ init_test(cx);++ let fs = FakeFs::new(cx.executor());+ fs.insert_tree(path!("/dir"), json!({ "a.rs": "A\nB\nC\n" }))+ .await;++ let project = Project::test(fs, [path!("/dir").as_ref()], cx).await;+ let language_registry = project.read_with(cx, |project, _| project.languages().clone());+ language_registry.add(rust_lang());++ let capabilities = lsp::ServerCapabilities {+ code_action_provider: Some(lsp::CodeActionProviderCapability::Simple(true)),+ ..Default::default()+ };+ let mut source_servers = language_registry.register_fake_lsp(+ "Rust",+ FakeLspAdapter {+ name: "diagnostic-source",+ capabilities: capabilities.clone(),+ ..Default::default()+ },+ );+ let mut other_servers = language_registry.register_fake_lsp(+ "Rust",+ FakeLspAdapter {+ name: "other-server",+ capabilities,+ ..Default::default()+ },+ );++ let (buffer, _handle) = project+ .update(cx, |project, cx| {+ project.open_local_buffer_with_lsp(path!("/dir/a.rs"), cx)+ })+ .await+ .unwrap();+ let source_server = source_servers.next().await.unwrap();+ let other_server = other_servers.next().await.unwrap();++ let markdown_value = "\n`A` is invalid\n";+ let plain_text_value = " B is invalid ";+ source_server.notify::<lsp::notification::PublishDiagnostics>(lsp::PublishDiagnosticsParams {+ uri: lsp::Uri::from_file_path(path!("/dir/a.rs")).unwrap(),+ version: None,+ diagnostics: vec![+ lsp::Diagnostic {+ range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),+ severity: Some(DiagnosticSeverity::ERROR),+ message: lsp::DiagnosticMessage::from(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: markdown_value.to_string(),+ }),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(lsp::Position::new(1, 0), lsp::Position::new(1, 1)),+ severity: Some(DiagnosticSeverity::WARNING),+ message: lsp::DiagnosticMessage::from(lsp::MarkupContent {+ kind: lsp::MarkupKind::PlainText,+ value: plain_text_value.to_string(),+ }),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(lsp::Position::new(2, 0), lsp::Position::new(2, 1)),+ severity: Some(DiagnosticSeverity::INFORMATION),+ message: lsp::DiagnosticMessage::from("C is invalid"),+ ..Default::default()+ },+ ],+ });+ cx.run_until_parked();++ let mut source_request = source_server+ .set_request_handler::<lsp::request::CodeActionRequest, _, _>(+ move |params, _| async move {+ assert_eq!(+ params+ .context+ .diagnostics+ .into_iter()+ .map(|diagnostic| diagnostic.message)+ .collect::<Vec<_>>(),+ vec![+ lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind: lsp::MarkupKind::Markdown,+ value: markdown_value.to_string(),+ }),+ lsp::DiagnosticMessage::MarkupContent(lsp::MarkupContent {+ kind: lsp::MarkupKind::PlainText,+ value: plain_text_value.to_string(),+ }),+ lsp::DiagnosticMessage::String("C is invalid".to_string()),+ ]+ );+ Ok(None)+ },+ );+ let mut other_request = other_server+ .set_request_handler::<lsp::request::CodeActionRequest, _, _>(|params, _| async move {+ assert_eq!(+ params+ .context+ .diagnostics+ .into_iter()+ .map(|diagnostic| diagnostic.message)+ .collect::<Vec<_>>(),+ vec![+ lsp::DiagnosticMessage::String("`A` is invalid".to_string()),+ lsp::DiagnosticMessage::String("B is invalid".to_string()),+ lsp::DiagnosticMessage::String("C is invalid".to_string()),+ ]+ );+ Ok(None)+ });++ let code_actions = project.update(cx, |project, cx| {+ project.code_actions(&buffer, 0..buffer.read(cx).len(), None, cx)+ });+ source_request+ .next()+ .await+ .expect("the diagnostic source should receive a code action request");+ other_request+ .next()+ .await+ .expect("the other server should receive a code action request");+ assert!(code_actions.await.unwrap().unwrap().is_empty());+}+#[gpui::test]async fn test_empty_diagnostic_ranges(cx: &mut gpui::TestAppContext) {init_test(cx);@@ -3905,7 +4138,7 @@ async fn test_empty_diagnostic_ranges(cx: &mut gpui::TestAppContext) {Unclipped(PointUtf16::new(0, 10))..Unclipped(PointUtf16::new(0, 10)),Diagnostic {severity: DiagnosticSeverity::ERROR,- message: "syntax error 1".to_string(),+ message: "syntax error 1".into(),source_kind: DiagnosticSourceKind::Pushed,..Diagnostic::default()},@@ -3914,7 +4147,7 @@ async fn test_empty_diagnostic_ranges(cx: &mut gpui::TestAppContext) {Unclipped(PointUtf16::new(1, 10))..Unclipped(PointUtf16::new(1, 10)),Diagnostic {severity: DiagnosticSeverity::ERROR,- message: "syntax error 2".to_string(),+ message: "syntax error 2".into(),source_kind: DiagnosticSourceKind::Pushed,..Diagnostic::default()},@@ -3970,7 +4203,7 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppCDiagnostic {severity: DiagnosticSeverity::ERROR,is_primary: true,- message: "syntax error a1".to_string(),+ message: "syntax error a1".into(),source_kind: DiagnosticSourceKind::Pushed,..Diagnostic::default()},@@ -3989,7 +4222,7 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppCDiagnostic {severity: DiagnosticSeverity::ERROR,is_primary: true,- message: "syntax error b1".to_string(),+ message: "syntax error b1".into(),source_kind: DiagnosticSourceKind::Pushed,..Diagnostic::default()},@@ -4033,7 +4266,7 @@ async fn test_diagnostic_summaries_cleared_on_worktree_entry_removal(Diagnostic {severity: DiagnosticSeverity::ERROR,is_primary: true,- message: "error in a".to_string(),+ message: "error in a".into(),source_kind: DiagnosticSourceKind::Pushed,..Diagnostic::default()},@@ -4052,7 +4285,7 @@ async fn test_diagnostic_summaries_cleared_on_worktree_entry_removal(Diagnostic {severity: DiagnosticSeverity::WARNING,is_primary: true,- message: "warning in b".to_string(),+ message: "warning in b".into(),source_kind: DiagnosticSourceKind::Pushed,..Diagnostic::default()},@@ -4113,7 +4346,7 @@ async fn test_diagnostic_summaries_cleared_on_server_restart(cx: &mut gpui::Testdiagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "error before restart".to_string(),+ message: lsp::DiagnosticMessage::from("error before restart"),..Default::default()}],});@@ -4237,7 +4470,7 @@ async fn test_diagnostic_summaries_cleared_on_buffer_reload(cx: &mut gpui::TestAdiagnostics: vec![lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 3)),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "error in a".to_string(),+ message: lsp::DiagnosticMessage::from("error in a"),..Default::default()}],});@@ -4317,7 +4550,9 @@ async fn test_diagnostic_summaries_cleared_on_buffer_close_without_workspace_dialsp::Position::new(0, 3),),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "pulled error no-ws".to_string(),+ message: lsp::DiagnosticMessage::from(+ "pulled error no-ws",+ ),..Default::default()}],},@@ -4420,7 +4655,9 @@ async fn test_diagnostic_summaries_retained_on_buffer_close_with_workspace_diagnlsp::Position::new(0, 3),),severity: Some(lsp::DiagnosticSeverity::ERROR),- message: "pulled error ws".to_string(),+ message: lsp::DiagnosticMessage::from(+ "pulled error ws",+ ),..Default::default()}],},@@ -7655,35 +7892,35 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(1, 8), lsp::Position::new(1, 9)),severity: Some(DiagnosticSeverity::WARNING),- message: "error 1".to_string(),+ message: lsp::DiagnosticMessage::from("error 1"),related_information: Some(error_1_related_information.to_vec()),..Default::default()},lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(1, 8), lsp::Position::new(1, 9)),severity: Some(DiagnosticSeverity::HINT),- message: "error 1 hint 1".to_string(),+ message: lsp::DiagnosticMessage::from("error 1 hint 1"),related_information: Some(error_1_hint_related_information.to_vec()),..Default::default()},lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(2, 8), lsp::Position::new(2, 17)),severity: Some(DiagnosticSeverity::ERROR),- message: "error 2".to_string(),+ message: lsp::DiagnosticMessage::from("error 2"),related_information: Some(error_2_related_information.to_vec()),..Default::default()},lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(1, 13), lsp::Position::new(1, 15)),severity: Some(DiagnosticSeverity::HINT),- message: "error 2 hint 1".to_string(),+ message: lsp::DiagnosticMessage::from("error 2 hint 1"),related_information: Some(error_2_hint_related_information.to_vec()),..Default::default()},lsp::Diagnostic {range: lsp::Range::new(lsp::Position::new(1, 13), lsp::Position::new(1, 15)),severity: Some(DiagnosticSeverity::HINT),- message: "error 2 hint 2".to_string(),+ message: lsp::DiagnosticMessage::from("error 2 hint 2"),related_information: Some(error_2_hint_related_information.to_vec()),..Default::default()},@@ -7718,7 +7955,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {related_information: expected_related_information(&error_1_related_information),diagnostic: Diagnostic {severity: DiagnosticSeverity::WARNING,- message: "error 1".to_string(),+ message: "error 1".into(),group_id: 1,is_primary: true,source_kind: DiagnosticSourceKind::Pushed,@@ -7732,7 +7969,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {),diagnostic: Diagnostic {severity: DiagnosticSeverity::HINT,- message: "error 1 hint 1".to_string(),+ message: "error 1 hint 1".into(),group_id: 1,is_primary: false,source_kind: DiagnosticSourceKind::Pushed,@@ -7746,7 +7983,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {),diagnostic: Diagnostic {severity: DiagnosticSeverity::HINT,- message: "error 2 hint 1".to_string(),+ message: "error 2 hint 1".into(),group_id: 0,is_primary: false,source_kind: DiagnosticSourceKind::Pushed,@@ -7760,7 +7997,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {),diagnostic: Diagnostic {severity: DiagnosticSeverity::HINT,- message: "error 2 hint 2".to_string(),+ message: "error 2 hint 2".into(),group_id: 0,is_primary: false,source_kind: DiagnosticSourceKind::Pushed,@@ -7772,7 +8009,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {related_information: expected_related_information(&error_2_related_information),diagnostic: Diagnostic {severity: DiagnosticSeverity::ERROR,- message: "error 2".to_string(),+ message: "error 2".into(),group_id: 0,is_primary: true,source_kind: DiagnosticSourceKind::Pushed,@@ -7792,7 +8029,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {),diagnostic: Diagnostic {severity: DiagnosticSeverity::HINT,- message: "error 2 hint 1".to_string(),+ message: "error 2 hint 1".into(),group_id: 0,is_primary: false,source_kind: DiagnosticSourceKind::Pushed,@@ -7806,7 +8043,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {),diagnostic: Diagnostic {severity: DiagnosticSeverity::HINT,- message: "error 2 hint 2".to_string(),+ message: "error 2 hint 2".into(),group_id: 0,is_primary: false,source_kind: DiagnosticSourceKind::Pushed,@@ -7818,7 +8055,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {related_information: expected_related_information(&error_2_related_information),diagnostic: Diagnostic {severity: DiagnosticSeverity::ERROR,- message: "error 2".to_string(),+ message: "error 2".into(),group_id: 0,is_primary: true,source_kind: DiagnosticSourceKind::Pushed,@@ -7836,7 +8073,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {related_information: expected_related_information(&error_1_related_information),diagnostic: Diagnostic {severity: DiagnosticSeverity::WARNING,- message: "error 1".to_string(),+ message: "error 1".into(),group_id: 1,is_primary: true,source_kind: DiagnosticSourceKind::Pushed,@@ -7850,7 +8087,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {),diagnostic: Diagnostic {severity: DiagnosticSeverity::HINT,- message: "error 1 hint 1".to_string(),+ message: "error 1 hint 1".into(),group_id: 1,is_primary: false,source_kind: DiagnosticSourceKind::Pushed,@@ -9792,7 +10029,7 @@ async fn test_code_actions_include_related_information(cx: &mut gpui::TestAppConseverity: Some(DiagnosticSeverity::ERROR),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(related_information.clone()),data: Some(json!({ "fix_id": "test-fix" })),..Default::default()@@ -9815,7 +10052,7 @@ async fn test_code_actions_include_related_information(cx: &mut gpui::TestAppConseverity: Some(DiagnosticSeverity::ERROR),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(related_information),data: Some(json!({ "fix_id": "test-fix" })),..Default::default()@@ -9829,7 +10066,7 @@ async fn test_code_actions_include_related_information(cx: &mut gpui::TestAppConseverity: Some(DiagnosticSeverity::INFORMATION),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "overlapping related diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("overlapping related diagnostic"),data: Some(json!({ "fix_id": "test-fix" })),..Default::default()},@@ -9863,7 +10100,7 @@ async fn test_code_actions_without_related_information(cx: &mut gpui::TestAppConrange: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),severity: Some(DiagnosticSeverity::ERROR),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),..Default::default()}],});@@ -9877,7 +10114,7 @@ async fn test_code_actions_without_related_information(cx: &mut gpui::TestAppConrange: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),severity: Some(DiagnosticSeverity::ERROR),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: None,..Default::default()}]@@ -9913,7 +10150,7 @@ async fn test_code_actions_with_primary_diagnostic_outside_of_the_range(severity: Some(DiagnosticSeverity::ERROR),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri,@@ -9936,7 +10173,7 @@ async fn test_code_actions_with_primary_diagnostic_outside_of_the_range(severity: Some(DiagnosticSeverity::INFORMATION),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "related diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("related diagnostic"),related_information: None,..Default::default()}]@@ -9973,7 +10210,7 @@ async fn test_code_actions_preserve_supporting_diagnostic_entry(cx: &mut gpui::Tseverity: Some(DiagnosticSeverity::ERROR),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri: uri.clone(),@@ -9989,7 +10226,7 @@ async fn test_code_actions_preserve_supporting_diagnostic_entry(cx: &mut gpui::Tseverity: Some(DiagnosticSeverity::WARNING),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "supporting diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("supporting diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri: uri.clone(),@@ -10014,7 +10251,7 @@ async fn test_code_actions_preserve_supporting_diagnostic_entry(cx: &mut gpui::Tseverity: Some(DiagnosticSeverity::ERROR),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri: Uri::from_file_path(path!("/dir/a.ts")).unwrap(),@@ -10030,7 +10267,7 @@ async fn test_code_actions_preserve_supporting_diagnostic_entry(cx: &mut gpui::Tseverity: Some(DiagnosticSeverity::WARNING),code: Some(lsp::NumberOrString::String("test-code".to_string())),source: Some("test-language-server".to_string()),- message: "supporting diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("supporting diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri: Uri::from_file_path(path!("/dir/a.ts")).unwrap(),@@ -10081,7 +10318,7 @@ async fn test_code_actions_related_information_follows_edits(cx: &mut gpui::Testrange: lsp::Range::new(lsp::Position::new(1, 0), lsp::Position::new(1, 3)),severity: Some(DiagnosticSeverity::ERROR),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri,@@ -10174,7 +10411,7 @@ async fn test_code_actions_related_information_of_disk_based_diagnostics(range: lsp::Range::new(lsp::Position::new(1, 0), lsp::Position::new(1, 3)),severity: Some(DiagnosticSeverity::ERROR),source: Some("disk".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri,@@ -10273,7 +10510,7 @@ async fn test_code_actions_related_information_drifts_across_merges(cx: &mut gpurange: lsp::Range::new(lsp::Position::new(1, 0), lsp::Position::new(1, 3)),severity: Some(DiagnosticSeverity::ERROR),source: Some("test-language-server".to_string()),- message: "primary diagnostic".to_string(),+ message: lsp::DiagnosticMessage::from("primary diagnostic"),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri,@@ -10367,7 +10604,7 @@ async fn test_code_actions_with_related_information_from_multiple_servers(),severity: Some(DiagnosticSeverity::ERROR),source: Some(name.to_string()),- message: format!("{name} primary diagnostic"),+ message: lsp::DiagnosticMessage::from(format!("{name} primary diagnostic")),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri: uri.clone(),@@ -10400,7 +10637,7 @@ async fn test_code_actions_with_related_information_from_multiple_servers(),severity: Some(DiagnosticSeverity::ERROR),source: Some(name.to_string()),- message: format!("{name} primary diagnostic"),+ message: lsp::DiagnosticMessage::from(format!("{name} primary diagnostic")),related_information: Some(vec![lsp::DiagnosticRelatedInformation {location: lsp::Location {uri: uri.clone(),@@ -10420,7 +10657,7 @@ async fn test_code_actions_with_related_information_from_multiple_servers(),severity: Some(DiagnosticSeverity::INFORMATION),source: Some(name.to_string()),- message: format!("{name} related diagnostic"),+ message: lsp::DiagnosticMessage::from(format!("{name} related diagnostic")),..Default::default()},]diff --git a/crates/prompt_store/src/prompts.rs b/crates/prompt_store/src/prompts.rsindex eb72f38e6ca..e0bf08de575 100644--- a/crates/prompt_store/src/prompts.rs+++ b/crates/prompt_store/src/prompts.rs@@ -410,7 +410,7 @@ impl PromptBuilder {let start = entry.range.start;ContentPromptDiagnosticContext {line_number: (start.row + 1) as usize,- error_message: entry.diagnostic.message.clone(),+ error_message: entry.diagnostic.message.to_string(),code_content: buffer.text_for_range(entry.range).collect(),}})@@ -493,7 +493,7 @@ impl PromptBuilder {let start = entry.range.start;ContentPromptDiagnosticContext {line_number: (start.row + 1) as usize,- error_message: entry.diagnostic.message.clone(),+ error_message: entry.diagnostic.message.to_string(),code_content: buffer.text_for_range(entry.range).collect(),}})diff --git a/crates/proto/proto/buffer.proto b/crates/proto/proto/buffer.protoindex 69bd844ee74..2647b0d0f58 100644--- a/crates/proto/proto/buffer.proto+++ b/crates/proto/proto/buffer.proto@@ -294,6 +294,13 @@ message Diagnostic {optional string data = 12;optional string code_description = 13;optional string markdown = 14;+ optional MarkupKind markup_message_kind = 18;+ optional string untrimmed_markup_message = 19;+}++enum MarkupKind {+ PlainText = 0;+ Markdown = 1;}message SearchQuery {diff --git a/crates/proto/proto/lsp.proto b/crates/proto/proto/lsp.protoindex 4016656e0aa..5f5877bdb71 100644--- a/crates/proto/proto/lsp.proto+++ b/crates/proto/proto/lsp.proto@@ -365,11 +365,6 @@ message Documentation {}}-enum MarkupKind {- PlainText = 0;- Markdown = 1;-}-message ParameterInformation {oneof label {string simple = 1;@@ -1063,6 +1058,8 @@ message LspDiagnostic {repeated LspDiagnosticRelatedInformation related_information = 8;repeated LspDiagnosticTag tags = 9;optional string data = 10;+ // Set when the message is a MarkupContent rather than a plain string.+ optional MarkupKind markup_message_kind = 11;enum Severity {None = 0;