Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move VSCode diagnostics workaround into client code #13016

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,8 +1320,7 @@ pub(crate) fn publish_diagnostics(
.unwrap(),
}),
source: Some("rust-analyzer".to_string()),
// https://github.com/rust-lang/rust-analyzer/issues/11404
message: if !d.message.is_empty() { d.message } else { " ".to_string() },
message: d.message,
related_information: None,
tags: if d.unused { Some(vec![DiagnosticTag::UNNECESSARY]) } else { None },
data: None,
Expand Down
22 changes: 4 additions & 18 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,29 +327,15 @@ impl GlobalState {
continue;
}

let url = file_id_to_url(&self.vfs.read().0, file_id);
let mut diagnostics =
let uri = file_id_to_url(&self.vfs.read().0, file_id);
let diagnostics =
self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
for d in &mut diagnostics {
// https://github.com/rust-lang/rust-analyzer/issues/11404
// FIXME: We should move this workaround into the client code
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)
let version = from_proto::vfs_path(&uri)
.map(|path| self.mem_docs.get(&path).map(|it| it.version))
.unwrap_or_default();

self.send_notification::<lsp_types::notification::PublishDiagnostics>(
lsp_types::PublishDiagnosticsParams { uri: url, diagnostics, version },
lsp_types::PublishDiagnosticsParams { uri, diagnostics, version },
);
}
}
Expand Down
9 changes: 9 additions & 0 deletions editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ export async function createClient(
traceOutputChannel: traceOutputChannel(),
outputChannel: outputChannel(),
middleware: {
async handleDiagnostics(uri, diagnostics, next) {
// Workaround for https://github.com/microsoft/vscode/issues/155531
for (const diagnostic of diagnostics) {
if (!diagnostic.message) {
diagnostic.message = " ";
}
}
next(uri, diagnostics);
},
async provideHover(
document: vscode.TextDocument,
position: vscode.Position,
Expand Down