Skip to content

Commit 9ad0a8c

Browse files
committed
Move empty diagnostics workaround back into the server
1 parent 55bf51d commit 9ad0a8c

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

crates/rust-analyzer/src/main_loop.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,33 @@ impl GlobalState {
328328
}
329329

330330
let uri = file_id_to_url(&self.vfs.read().0, file_id);
331-
let diagnostics =
331+
let mut diagnostics =
332332
self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
333+
334+
// VSCode assumes diagnostic messages to be non-empty strings, so we need to patch
335+
// empty diagnostics. Neither the docs of VSCode nor the LSP spec say whether
336+
// diagnostic messages are actually allowed to be empty or not and patching this
337+
// in the VSCode client does not work as the assertion happens in the protocol
338+
// conversion. So this hack is here to stay, and will be considered a hack
339+
// until the LSP decides to state that empty messages are allowed.
340+
341+
// See https://github.com/rust-lang/rust-analyzer/issues/11404
342+
// See https://github.com/rust-lang/rust-analyzer/issues/13130
343+
let patch_empty = |message: &mut String| {
344+
if message.is_empty() {
345+
*message = " ".to_string();
346+
}
347+
};
348+
349+
for d in &mut diagnostics {
350+
patch_empty(&mut d.message);
351+
if let Some(dri) = &mut d.related_information {
352+
for dri in dri {
353+
patch_empty(&mut dri.message);
354+
}
355+
}
356+
}
357+
333358
let version = from_proto::vfs_path(&uri)
334359
.map(|path| self.mem_docs.get(&path).map(|it| it.version))
335360
.unwrap_or_default();

editors/code/src/client.ts

-16
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,6 @@ export async function createClient(
9999
traceOutputChannel: traceOutputChannel(),
100100
outputChannel: outputChannel(),
101101
middleware: {
102-
async handleDiagnostics(uri, diagnostics, next) {
103-
// Workaround for https://github.com/microsoft/vscode/issues/155531
104-
for (const diagnostic of diagnostics) {
105-
if (!diagnostic.message) {
106-
diagnostic.message = " ";
107-
}
108-
if (diagnostic.relatedInformation) {
109-
for (const relatedInformation of diagnostic.relatedInformation) {
110-
if (!relatedInformation.message) {
111-
relatedInformation.message = " ";
112-
}
113-
}
114-
}
115-
}
116-
next(uri, diagnostics);
117-
},
118102
async provideHover(
119103
document: vscode.TextDocument,
120104
position: vscode.Position,

0 commit comments

Comments
 (0)