Skip to content

Commit

Permalink
Move VSCode diagnostics workaroudn into client code
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Aug 13, 2022
1 parent 038c36a commit 1d66361
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
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
11 changes: 10 additions & 1 deletion editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as vscode from "vscode";
import * as ra from "../src/lsp_ext";
import * as Is from "vscode-languageclient/lib/common/utils/is";
import { assert } from "./util";
import { WorkspaceEdit } from "vscode";
import { Uri, WorkspaceEdit } from "vscode";
import { Workspace } from "./ctx";
import { updateConfig } from "./config";
import { substituteVariablesInEnv } from "./config";
Expand Down 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

0 comments on commit 1d66361

Please sign in to comment.