microsoft / vscode-languageserver-node

Language server protocol implementation for VSCode. This allows implementing language services in JS/TS running on node.js
MIT License
1.48k stars 325 forks source link

textDocument/publishDiagnostics called multiple times but only one of the file's diagnostics are shown #1587

Open rcjsuen opened 1 week ago

rcjsuen commented 1 week ago

https://github.com/microsoft/vscode-languageserver-node/blob/8e6bf18f22b2e83b60a27a51447b99acf98c4381/client/src/common/client.ts#L1742-L1747

I have a language server that boots up and scans the workspace folders. It finds four files to scan and publishes diagnostics for all four of them and only one of them has diagnostics in the "Problems" pane.

I have confirmed with a breakpoint that this._diagnostics.set(uri, diagnostics); is called multiple times but only one of the file's diagnostics are being shown. If I try to debug further I am greeted with your standard unreadable extensionHostProcess.js.

Image

The traces for the missing files seem correct and I even made the correct one have an incorrect URI and it still showed up in the "Problems" pane just fine. This is 100% reproducible so I'm not convinced it's some strange race condition...? 🤨 How can I debug the extension so that I can walk through actual VS Code source code instead of looking at the unreadable extensionHostProcess.js?

dbaeumer commented 1 week ago

@rcjsuen you would need to run and compile VS Code from source :-). The instructions are here: https://github.com/microsoft/vscode/wiki/How-to-Contribute

Have you tried to reproduce this with a simple VS Code extension that adds the diagnostics directly in code?

rcjsuen commented 1 week ago

you would need to run and compile VS Code from source :-)

Sounds painful. :)

Have you tried to reproduce this with a simple VS Code extension that adds the diagnostics directly in code?

Great suggestion. I tried that and couldn't reproduce it.

https://github.com/microsoft/vscode-languageserver-node/blob/8e6bf18f22b2e83b60a27a51447b99acf98c4381/client/src/common/client.ts#L1694-L1705

Also cheated with client as any and then calling the private handleDiagnostics function and that seems to work. I'll try to examine the payloads more closely to make sure I didn't make any copy/paste errors and see if I can further refine my testing...

rcjsuen commented 1 week ago

@dbaeumer I figured out the problem. It seems like vscode.DiagnosticSeverity.Hint diagnostics is intended to not show up in "Problems"...? 🤷 I only see three of the four.

Image

const collection = vscode.languages.createDiagnosticCollection("rcjsuen-testing");
collection.set(vscode.Uri.file("/rcjsuen/testing"), [
    new vscode.Diagnostic(new vscode.Range(0, 0, 0, 10), "Error", vscode.DiagnosticSeverity.Error),
    new vscode.Diagnostic(new vscode.Range(0, 0, 0, 10), "Hint", vscode.DiagnosticSeverity.Hint),
    new vscode.Diagnostic(new vscode.Range(0, 0, 0, 10), "Information", vscode.DiagnosticSeverity.Information),
    new vscode.Diagnostic(new vscode.Range(0, 0, 0, 10), "Warning", vscode.DiagnosticSeverity.Warning),
])
rcjsuen commented 1 week ago

Looks like this is intentional (https://github.com/microsoft/vscode/issues/45436) and someone else reported this this year (https://github.com/microsoft/vscode/issues/203569). 🤔