about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-19 05:08:47 +0000
committerbors <bors@rust-lang.org>2022-07-19 05:08:47 +0000
commit88515b981db65aa994e23ed5a2a9160f0c10613b (patch)
tree2d2213a2c8bbf051a2604f085548cd26158706c8
parent567a5e9ef7c753e03d528cbc19110db99e8d6878 (diff)
parent474f5eafc790cdd12fa04c518d2443543df72900 (diff)
downloadrust-88515b981db65aa994e23ed5a2a9160f0c10613b.tar.gz
rust-88515b981db65aa994e23ed5a2a9160f0c10613b.zip
Auto merge of #12809 - lnicola:empty-diagnostics, r=lnicola
fix: Work around Code bug with empty diagnostics

Closes #11404
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs7
-rw-r--r--crates/rust-analyzer/src/handlers.rs3
-rw-r--r--crates/rust-analyzer/src/main_loop.rs16
3 files changed, 18 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index 8f779df18d3..cff4bd7f66a 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 e3875228a18..520aa7d1dd4 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 49b83941119..0579cae4ed0 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::<Vec<_>>();
+                // 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();