Skip to content

Commit 1d66361

Browse files
committed
Move VSCode diagnostics workaroudn into client code
1 parent 038c36a commit 1d66361

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

crates/rust-analyzer/src/main_loop.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -327,29 +327,15 @@ impl GlobalState {
327327
continue;
328328
}
329329

330-
let url = file_id_to_url(&self.vfs.read().0, file_id);
331-
let mut diagnostics =
330+
let uri = file_id_to_url(&self.vfs.read().0, file_id);
331+
let diagnostics =
332332
self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
333-
for d in &mut diagnostics {
334-
// https://github.com/rust-lang/rust-analyzer/issues/11404
335-
// FIXME: We should move this workaround into the client code
336-
if d.message.is_empty() {
337-
d.message = " ".to_string();
338-
}
339-
if let Some(rds) = d.related_information.as_mut() {
340-
for rd in rds {
341-
if rd.message.is_empty() {
342-
rd.message = " ".to_string();
343-
}
344-
}
345-
}
346-
}
347-
let version = from_proto::vfs_path(&url)
333+
let version = from_proto::vfs_path(&uri)
348334
.map(|path| self.mem_docs.get(&path).map(|it| it.version))
349335
.unwrap_or_default();
350336

351337
self.send_notification::<lsp_types::notification::PublishDiagnostics>(
352-
lsp_types::PublishDiagnosticsParams { uri: url, diagnostics, version },
338+
lsp_types::PublishDiagnosticsParams { uri, diagnostics, version },
353339
);
354340
}
355341
}

editors/code/src/client.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as vscode from "vscode";
33
import * as ra from "../src/lsp_ext";
44
import * as Is from "vscode-languageclient/lib/common/utils/is";
55
import { assert } from "./util";
6-
import { WorkspaceEdit } from "vscode";
6+
import { Uri, WorkspaceEdit } from "vscode";
77
import { Workspace } from "./ctx";
88
import { updateConfig } from "./config";
99
import { substituteVariablesInEnv } from "./config";
@@ -105,6 +105,15 @@ export async function createClient(
105105
traceOutputChannel: traceOutputChannel(),
106106
outputChannel: outputChannel(),
107107
middleware: {
108+
async handleDiagnostics(uri, diagnostics, next) {
109+
// Workaround for https://github.com/microsoft/vscode/issues/155531
110+
for (const diagnostic of diagnostics) {
111+
if (!diagnostic.message) {
112+
diagnostic.message = " ";
113+
}
114+
}
115+
next(uri, diagnostics);
116+
},
108117
async provideHover(
109118
document: vscode.TextDocument,
110119
position: vscode.Position,

0 commit comments

Comments
 (0)