Skip to content

Commit 88515b9

Browse files
committed
Auto merge of rust-lang#12809 - lnicola:empty-diagnostics, r=lnicola
fix: Work around Code bug with empty diagnostics Closes rust-lang#11404
2 parents 567a5e9 + 474f5ea commit 88515b9

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

crates/rust-analyzer/src/diagnostics/to_proto.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,6 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
462462
message: "original diagnostic".to_string(),
463463
};
464464
for sub in &subdiagnostics {
465-
let mut message = sub.related.message.clone();
466-
// Change empty message to " ", as they greatly confuse VS Code.
467-
if message.is_empty() {
468-
message = String::from(" ");
469-
}
470465
diagnostics.push(MappedRustDiagnostic {
471466
url: sub.related.location.uri.clone(),
472467
fix: sub.suggested_fix.clone(),
@@ -476,7 +471,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
476471
code: code.clone().map(lsp_types::NumberOrString::String),
477472
code_description: code_description.clone(),
478473
source: Some(source.clone()),
479-
message,
474+
message: sub.related.message.clone(),
480475
related_information: Some(vec![back_ref.clone()]),
481476
tags: None, // don't apply modifiers again
482477
data: None,

crates/rust-analyzer/src/handlers.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,8 @@ pub(crate) fn publish_diagnostics(
13181318
.unwrap(),
13191319
}),
13201320
source: Some("rust-analyzer".to_string()),
1321-
message: d.message,
1321+
// https://github.com/rust-lang/rust-analyzer/issues/11404
1322+
message: if !d.message.is_empty() { d.message } else { " ".to_string() },
13221323
related_information: None,
13231324
tags: if d.unused { Some(vec![DiagnosticTag::UNNECESSARY]) } else { None },
13241325
data: None,

crates/rust-analyzer/src/main_loop.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,21 @@ impl GlobalState {
487487
}
488488

489489
let url = file_id_to_url(&self.vfs.read().0, file_id);
490-
let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect();
490+
let mut diagnostics =
491+
self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
492+
// https://github.com/rust-lang/rust-analyzer/issues/11404
493+
for d in &mut diagnostics {
494+
if d.message.is_empty() {
495+
d.message = " ".to_string();
496+
}
497+
if let Some(rds) = d.related_information.as_mut() {
498+
for rd in rds {
499+
if rd.message.is_empty() {
500+
rd.message = " ".to_string();
501+
}
502+
}
503+
}
504+
}
491505
let version = from_proto::vfs_path(&url)
492506
.map(|path| self.mem_docs.get(&path).map(|it| it.version))
493507
.unwrap_or_default();

0 commit comments

Comments
 (0)