Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rcjsuen opened this issue Nov 14, 2024 · 4 comments
Labels
info-needed Issue requires more information from poster

Comments

@rcjsuen
Copy link
Contributor

rcjsuen commented Nov 14, 2024

private setDiagnostics(uri: Uri, diagnostics: VDiagnostic[] | undefined) {
if (!this._diagnostics) {
return;
}
this._diagnostics.set(uri, diagnostics);
}

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
Copy link
Member

@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?

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Nov 15, 2024
@rcjsuen
Copy link
Contributor Author

rcjsuen commented Nov 15, 2024

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.

private handleDiagnostics(params: PublishDiagnosticsParams) {
if (!this._diagnostics) {
return;
}
const key = params.uri;
if (this._diagnosticQueueState.state === 'busy' && this._diagnosticQueueState.document === key) {
// Cancel the active run;
this._diagnosticQueueState.tokenSource.cancel();
}
this._diagnosticQueue.set(params.uri, params.diagnostics);
this.triggerDiagnosticQueue();
}

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
Copy link
Contributor Author

rcjsuen commented Nov 15, 2024

@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
Copy link
Contributor Author

rcjsuen commented Nov 15, 2024

Looks like this is intentional (microsoft/vscode#45436) and someone else reported this this year (microsoft/vscode#203569). 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants