diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 8f779df18d..cff4bd7f66 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -462,11 +462,6 @@ pub(crate) fn map_rust_diagnostic_to_lsp( message: "original diagnostic".to_string(), }; for sub in &subdiagnostics { - let mut message = sub.related.message.clone(); - // Change empty message to " ", as they greatly confuse VS Code. - if message.is_empty() { - message = String::from(" "); - } diagnostics.push(MappedRustDiagnostic { url: sub.related.location.uri.clone(), fix: sub.suggested_fix.clone(), @@ -476,7 +471,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( code: code.clone().map(lsp_types::NumberOrString::String), code_description: code_description.clone(), source: Some(source.clone()), - message, + message: sub.related.message.clone(), related_information: Some(vec![back_ref.clone()]), tags: None, // don't apply modifiers again data: None, diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index e3875228a1..520aa7d1dd 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1318,7 +1318,8 @@ pub(crate) fn publish_diagnostics( .unwrap(), }), source: Some("rust-analyzer".to_string()), - message: d.message, + // https://github.com/rust-lang/rust-analyzer/issues/11404 + message: if !d.message.is_empty() { d.message } else { " ".to_string() }, related_information: None, tags: if d.unused { Some(vec![DiagnosticTag::UNNECESSARY]) } else { None }, data: None, diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 49b8394111..0579cae4ed 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -487,7 +487,21 @@ impl GlobalState { } let url = file_id_to_url(&self.vfs.read().0, file_id); - let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect(); + let mut diagnostics = + self.diagnostics.diagnostics_for(file_id).cloned().collect::>(); + // https://github.com/rust-lang/rust-analyzer/issues/11404 + for d in &mut diagnostics { + if d.message.is_empty() { + d.message = " ".to_string(); + } + if let Some(rds) = d.related_information.as_mut() { + for rd in rds { + if rd.message.is_empty() { + rd.message = " ".to_string(); + } + } + } + } let version = from_proto::vfs_path(&url) .map(|path| self.mem_docs.get(&path).map(|it| it.version)) .unwrap_or_default();