Skip to content

Commit 4e672d5

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/protocol: PublishDiagnosticsParams.version omitempty
This CL reverts the status of the PublishDiagnostics.version field to omitempty. This status was removed by CL 73501, causing some clients (e.g. coc.nvim) to treat the zero version (meaning "missing" to gopls' file.Handle) as an actual version in the past. Unfortunately it is not possible to reproduce the regression using gopls' JSON encoding structures, hence the lack of a test. Fixes golang/go#73501 Updates golang/go#71489 Change-Id: Ia116f948e13782610c9de8d2d7ffd99bdb377d3e Reviewed-on: https://go-review.googlesource.com/c/tools/+/678095 Commit-Queue: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent e88c5a4 commit 4e672d5

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

gopls/internal/cmd/cmd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ func updateFile(filename string, old, new []byte, edits []diff.Edit, flags *Edit
641641

642642
func (c *cmdClient) PublishDiagnostics(ctx context.Context, p *protocol.PublishDiagnosticsParams) error {
643643
// Don't worry about diagnostics without versions.
644+
//
645+
// (Note: the representation of PublishDiagnosticsParams
646+
// cannot distinguish a missing Version from v0, but the
647+
// server never sends back an explicit zero.)
644648
if p.Version == 0 {
645649
return nil
646650
}

gopls/internal/protocol/generate/tables.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var goplsStar = map[prop]int{
3434
{"CompletionItem", "kind"}: wantOpt, // need temporary variables
3535
{"CompletionParams", "context"}: wantOpt, // needs nil checks
3636

37-
{"Diagnostic", "severity"}: wantOpt, // nil checks or more careful thought
37+
{"Diagnostic", "severity"}: wantOpt, // needs nil checks or more careful thought
3838
{"DidSaveTextDocumentParams", "text"}: wantOptStar, // capabilities_test.go:112 logic
3939
{"DocumentHighlight", "kind"}: wantOpt, // need temporary variables
4040

@@ -46,6 +46,7 @@ var goplsStar = map[prop]int{
4646
{"Hover", "range"}: wantOpt, // complex expressions
4747
{"InlayHint", "kind"}: wantOpt, // temporary variables
4848

49+
{"PublishDiagnosticsParams", "version"}: wantOpt, // zero => missing (#73501)
4950
{"TextDocumentClientCapabilities", "codeAction"}: wantOpt, // A.B.C.D
5051
{"TextDocumentClientCapabilities", "completion"}: wantOpt, // A.B.C.D
5152
{"TextDocumentClientCapabilities", "documentSymbol"}: wantOpt, // A.B.C.D

gopls/internal/protocol/tsprotocol.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gopls/internal/server/diagnostics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ func (s *server) publishFileDiagnosticsLocked(ctx context.Context, views viewSet
904904
if err := s.client.PublishDiagnostics(ctx, &protocol.PublishDiagnosticsParams{
905905
Diagnostics: toProtocolDiagnostics(unique),
906906
URI: uri,
907-
Version: version,
907+
Version: version, // 0 ("on disk") => omitted from JSON encoding
908908
}); err != nil {
909909
return err
910910
}

0 commit comments

Comments
 (0)