-
Notifications
You must be signed in to change notification settings - Fork 744
Provide Program diagnostics as push diags in tsconfig.json #2118
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements push diagnostics for program-level diagnostics in tsconfig.json files. When TypeScript program diagnostics are generated (e.g., configuration errors), they are now pushed to the client via LSP's textDocument/publishDiagnostics notification, associated with the tsconfig.json file. Diagnostics are cleared when projects are closed.
Key changes:
- Added
PublishDiagnosticsmethod to theClientinterface and implemented it in the LSP server - Added diagnostic publishing logic that tracks project changes and sends/clears diagnostics accordingly
- Refactored diagnostic conversion to support both pull and push diagnostic scenarios
- Added
DisablePushDiagnosticsoption for testing, particularly for fourslash tests which don't handle unsolicited server notifications
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/project/client.go | Added PublishDiagnostics method to the Client interface |
| internal/project/session.go | Added DisablePushDiagnostics field, implemented publishProgramDiagnostics and publishProjectDiagnostics methods to send program diagnostics, added nil client check |
| internal/project/snapshot_test.go | Added noopClient implementation for snapshot tests that now require a Client |
| internal/project/refcounting_test.go | Updated to provide noopClient to session initialization |
| internal/project/project_test.go | Added comprehensive TestPushDiagnostics test suite covering initial publishing, clearing on project removal, updates on program changes, and exclusion of inferred projects |
| internal/lsp/server.go | Implemented PublishDiagnostics method, added extraction of disablePushDiagnostics from initialization options |
| internal/ls/lsconv/converters.go | Added DiagnosticToLSPPull and DiagnosticToLSPPush functions to handle different client capability sets, added support for diagnostics without associated files |
| internal/ls/diagnostics.go | Refactored to use the new DiagnosticToLSPPull function from lsconv package |
| internal/fourslash/fourslash.go | Added disablePushDiagnostics: true to initialization options to prevent fourslash tests from receiving unsolicited notifications |
| internal/testutil/projecttestutil/clientmock_generated.go | Generated mock updated with PublishDiagnostics method and associated tracking |
| if s.initializeParams != nil && s.initializeParams.InitializationOptions != nil && *s.initializeParams.InitializationOptions != nil { | ||
| // handle userPreferences from initializationOptions | ||
| userPreferences := s.session.NewUserPreferences() | ||
| userPreferences.Parse(*s.initializeParams.InitializationOptions) | ||
| s.session.InitializeWithConfig(userPreferences) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code was unused
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Can a single-file edit that results in a fast program clone affect program diagnostics? If not, we could gate the collection on |
|
No, I don't believe it can, since we check if a file's important bits change before doing the easy fast clone for that reason. I can do that. |
andrewbranch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
|
This is still failing the API tests, I'm trying to figure out why |
|
It's the client nil check; just dropped that since there's a flag that enables the push diags... the API is a little weird given it's sort of a language server sort of not. |
This uses LSP push diags to send
ProgramDiagnosticswhen present, removing them when a project is closed. The actual implementation of it seems fine, but the testing is pretty annoying.There are unit tests for this, but fourslash cannot handle client-initiated anything except the two hardcoded init ones. So, I'm just forcibly disabling those via an init option set for fourslash. Nasty but making fourslash more like a real LSP client is going to take a lot of work.
Also, we have program diags that are not associated with files at all. I've just hacked it so that these diags get reported at a zero position.