mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Move empty diagnostics workaround back into the server
This commit is contained in:
parent
55bf51df41
commit
9ad0a8c467
2 changed files with 26 additions and 17 deletions
|
@ -328,8 +328,33 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
|
|
||||||
let uri = file_id_to_url(&self.vfs.read().0, file_id);
|
let uri = file_id_to_url(&self.vfs.read().0, file_id);
|
||||||
let diagnostics =
|
let mut diagnostics =
|
||||||
self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
|
self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
|
||||||
|
|
||||||
|
// VSCode assumes diagnostic messages to be non-empty strings, so we need to patch
|
||||||
|
// empty diagnostics. Neither the docs of VSCode nor the LSP spec say whether
|
||||||
|
// diagnostic messages are actually allowed to be empty or not and patching this
|
||||||
|
// in the VSCode client does not work as the assertion happens in the protocol
|
||||||
|
// conversion. So this hack is here to stay, and will be considered a hack
|
||||||
|
// until the LSP decides to state that empty messages are allowed.
|
||||||
|
|
||||||
|
// See https://github.com/rust-lang/rust-analyzer/issues/11404
|
||||||
|
// See https://github.com/rust-lang/rust-analyzer/issues/13130
|
||||||
|
let patch_empty = |message: &mut String| {
|
||||||
|
if message.is_empty() {
|
||||||
|
*message = " ".to_string();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for d in &mut diagnostics {
|
||||||
|
patch_empty(&mut d.message);
|
||||||
|
if let Some(dri) = &mut d.related_information {
|
||||||
|
for dri in dri {
|
||||||
|
patch_empty(&mut dri.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let version = from_proto::vfs_path(&uri)
|
let version = from_proto::vfs_path(&uri)
|
||||||
.map(|path| self.mem_docs.get(&path).map(|it| it.version))
|
.map(|path| self.mem_docs.get(&path).map(|it| it.version))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
|
@ -99,22 +99,6 @@ export async function createClient(
|
||||||
traceOutputChannel: traceOutputChannel(),
|
traceOutputChannel: traceOutputChannel(),
|
||||||
outputChannel: outputChannel(),
|
outputChannel: outputChannel(),
|
||||||
middleware: {
|
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 = " ";
|
|
||||||
}
|
|
||||||
if (diagnostic.relatedInformation) {
|
|
||||||
for (const relatedInformation of diagnostic.relatedInformation) {
|
|
||||||
if (!relatedInformation.message) {
|
|
||||||
relatedInformation.message = " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
next(uri, diagnostics);
|
|
||||||
},
|
|
||||||
async provideHover(
|
async provideHover(
|
||||||
document: vscode.TextDocument,
|
document: vscode.TextDocument,
|
||||||
position: vscode.Position,
|
position: vscode.Position,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue