-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/lsp: add OnSave diagnostics
Gopls publishes diagnostics as soon as it observes issues, even while the user is in the middle of typing resulting in transient errors. Some users find this behavior rather distracting. 'diagnosticsDelay' may help avoid wasted work, but time-based decision does not always match users' expectation on when they want to see diagnostics updates. Historically, vscode-go offered two additional ways to diagnose code. * On save * Manual trigger They were implemented by running the go compiler and vet/lint tools outside gopls. Now we are working to move all code analysis logic into the language server (golang/vscode-go#2799). We need replacement for these features (golang/vscode-go#50). This change introduces a new gopls setting 'diagnosticsTrigger'. The default is 'Edit'. The additional option is 'Save', which is implemented by preventing file modification events from triggering diagnosis. This helps migrating users of the legacy "Build/Vet On Save" mode. For users of the manual trigger mode, we can consider to add the "Manual" mode and expose a custom LSP command that triggers diagnosis when we see the demand. Alternatives I explored: * Pull Model Diagnostics - LSP 3.17 introduced client-initiated diagnostics supporta The idea fits well with 'on save' or 'manual trigger' features, but I am afraid this requires non-trivial amount of work in gopls side. https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics Moreover, the state of client side implementations is unclear. For example, VS Code does not seem to support all features listed in the DiagnosticClientCapability yet. The interaction between DocumentDiagnostics and WorkspaceDiagnostics, and how mature the vscode implementation is unclear to me at this moment. * Emulate from Client-side - I attempted to buffer diagnostics reports in the LSP client middleware layer, and make them visible only when files are saved. That adds a non-trivial amount of TS/JS code on the extension side which defeats the purpose of our deprecation work. Moreover, that causes the diagnostics diff to be computed in one more place (in addition to VSCode side and Gopls side), and adds complexities. I also think some users in other editors want this feature. For golang/vscode-go#50 Change-Id: If07d3446bee7bed90851ad2272d82d163ae586cd Reviewed-on: https://go-review.googlesource.com/c/tools/+/534861 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
- Loading branch information
Showing
6 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters