Skip to content

Commit

Permalink
Auto merge of rust-lang#12809 - lnicola:empty-diagnostics, r=lnicola
Browse files Browse the repository at this point in the history
fix: Work around Code bug with empty diagnostics

Closes rust-lang#11404
  • Loading branch information
bors committed Jul 19, 2022
2 parents 567a5e9 + 474f5ea commit 88515b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 1 addition & 6 deletions crates/rust-analyzer/src/diagnostics/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 88515b9

Please sign in to comment.