diff options
author | Peter Weinberger <pjw@google.com> | 2023-02-18 15:25:18 -0500 |
---|---|---|
committer | Peter Weinberger <pjw@google.com> | 2023-02-22 15:03:40 +0000 |
commit | e85b5336ed5c729c983d08d5f581b5034e8f1a9b (patch) | |
tree | 6bf5d3da6f6584130b69d39403c5c3ee3f63b915 | |
parent | 193023cca0b707b4d668e5d332649cba285e99f7 (diff) | |
download | golang-x-tools-e85b5336ed5c729c983d08d5f581b5034e8f1a9b.tar.gz |
gopls/protocol: remove stub special cases
This CL removes all the trivial special cases from generate.tables.go.
The custom unmarshalers return an exported error, so that
json_test.go can still do some checking.
Change-Id: I6f1d67b029200c6ce147539410195ecebdb24ab9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/469515
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
-rw-r--r-- | gopls/internal/lsp/cmd/cmd.go | 4 | ||||
-rw-r--r-- | gopls/internal/lsp/fake/editor.go | 2 | ||||
-rw-r--r-- | gopls/internal/lsp/general.go | 28 | ||||
-rw-r--r-- | gopls/internal/lsp/protocol/generate/main.go | 13 | ||||
-rw-r--r-- | gopls/internal/lsp/protocol/generate/output.go | 2 | ||||
-rw-r--r-- | gopls/internal/lsp/protocol/generate/tables.go | 54 | ||||
-rw-r--r-- | gopls/internal/lsp/protocol/tsclient.go | 2 | ||||
-rw-r--r-- | gopls/internal/lsp/protocol/tsjson.go | 131 | ||||
-rw-r--r-- | gopls/internal/lsp/protocol/tsprotocol.go | 56 | ||||
-rw-r--r-- | gopls/internal/lsp/protocol/tsserver.go | 2 | ||||
-rw-r--r-- | gopls/internal/lsp/workspace.go | 4 | ||||
-rw-r--r-- | gopls/test/json_test.go | 18 |
12 files changed, 156 insertions, 160 deletions
diff --git a/gopls/internal/lsp/cmd/cmd.go b/gopls/internal/lsp/cmd/cmd.go index 6d5332b5a..cb1d78de5 100644 --- a/gopls/internal/lsp/cmd/cmd.go +++ b/gopls/internal/lsp/cmd/cmd.go @@ -360,8 +360,8 @@ func (c *connection) initialize(ctx context.Context, options func(*source.Option params.Capabilities.TextDocument.DocumentSymbol.HierarchicalDocumentSymbolSupport = opts.HierarchicalDocumentSymbolSupport params.Capabilities.TextDocument.SemanticTokens = protocol.SemanticTokensClientCapabilities{} params.Capabilities.TextDocument.SemanticTokens.Formats = []protocol.TokenFormat{"relative"} - params.Capabilities.TextDocument.SemanticTokens.Requests.Range = true - params.Capabilities.TextDocument.SemanticTokens.Requests.Full = true + params.Capabilities.TextDocument.SemanticTokens.Requests.Range.Value = true + params.Capabilities.TextDocument.SemanticTokens.Requests.Full.Value = true params.Capabilities.TextDocument.SemanticTokens.TokenTypes = lsp.SemanticTypes() params.Capabilities.TextDocument.SemanticTokens.TokenModifiers = lsp.SemanticModifiers() params.InitializationOptions = map[string]interface{}{ diff --git a/gopls/internal/lsp/fake/editor.go b/gopls/internal/lsp/fake/editor.go index 6fa9a8bdb..15078526c 100644 --- a/gopls/internal/lsp/fake/editor.go +++ b/gopls/internal/lsp/fake/editor.go @@ -255,7 +255,7 @@ func (e *Editor) initialize(ctx context.Context) error { params.Capabilities.TextDocument.Completion.CompletionItem.TagSupport.ValueSet = []protocol.CompletionItemTag{protocol.ComplDeprecated} params.Capabilities.TextDocument.Completion.CompletionItem.SnippetSupport = true - params.Capabilities.TextDocument.SemanticTokens.Requests.Full = true + params.Capabilities.TextDocument.SemanticTokens.Requests.Full.Value = true // copied from lsp/semantic.go to avoid import cycle in tests params.Capabilities.TextDocument.SemanticTokens.TokenTypes = []string{ "namespace", "type", "class", "enum", "interface", diff --git a/gopls/internal/lsp/general.go b/gopls/internal/lsp/general.go index d55e10384..31b5124f4 100644 --- a/gopls/internal/lsp/general.go +++ b/gopls/internal/lsp/general.go @@ -136,32 +136,32 @@ See https://github.com/golang/go/issues/45732 for more information.`, return &protocol.InitializeResult{ Capabilities: protocol.ServerCapabilities{ - CallHierarchyProvider: true, + CallHierarchyProvider: &protocol.Or_ServerCapabilities_callHierarchyProvider{Value: true}, CodeActionProvider: codeActionProvider, CodeLensProvider: &protocol.CodeLensOptions{}, // must be non-nil to enable the code lens capability CompletionProvider: protocol.CompletionOptions{ TriggerCharacters: []string{"."}, }, - DefinitionProvider: true, - TypeDefinitionProvider: true, - ImplementationProvider: true, - DocumentFormattingProvider: true, - DocumentSymbolProvider: true, - WorkspaceSymbolProvider: true, + DefinitionProvider: &protocol.Or_ServerCapabilities_definitionProvider{Value: true}, + TypeDefinitionProvider: &protocol.Or_ServerCapabilities_typeDefinitionProvider{Value: true}, + ImplementationProvider: &protocol.Or_ServerCapabilities_implementationProvider{Value: true}, + DocumentFormattingProvider: &protocol.Or_ServerCapabilities_documentFormattingProvider{Value: true}, + DocumentSymbolProvider: &protocol.Or_ServerCapabilities_documentSymbolProvider{Value: true}, + WorkspaceSymbolProvider: &protocol.Or_ServerCapabilities_workspaceSymbolProvider{Value: true}, ExecuteCommandProvider: protocol.ExecuteCommandOptions{ Commands: options.SupportedCommands, }, - FoldingRangeProvider: true, - HoverProvider: true, - DocumentHighlightProvider: true, + FoldingRangeProvider: &protocol.Or_ServerCapabilities_foldingRangeProvider{Value: true}, + HoverProvider: &protocol.Or_ServerCapabilities_hoverProvider{Value: true}, + DocumentHighlightProvider: &protocol.Or_ServerCapabilities_documentHighlightProvider{Value: true}, DocumentLinkProvider: protocol.DocumentLinkOptions{}, InlayHintProvider: protocol.InlayHintOptions{}, - ReferencesProvider: true, + ReferencesProvider: &protocol.Or_ServerCapabilities_referencesProvider{Value: true}, RenameProvider: renameOpts, - SelectionRangeProvider: protocol.SelectionRangeRegistrationOptions{}, + SelectionRangeProvider: &protocol.Or_ServerCapabilities_selectionRangeProvider{Value: true}, SemanticTokensProvider: protocol.SemanticTokensOptions{ - Range: true, - Full: true, + Range: &protocol.Or_SemanticTokensOptions_range{Value: true}, + Full: &protocol.Or_SemanticTokensOptions_full{Value: true}, Legend: protocol.SemanticTokensLegend{ TokenTypes: s.session.Options().SemanticTypes, TokenModifiers: s.session.Options().SemanticMods, diff --git a/gopls/internal/lsp/protocol/generate/main.go b/gopls/internal/lsp/protocol/generate/main.go index b00a00e00..e78c74917 100644 --- a/gopls/internal/lsp/protocol/generate/main.go +++ b/gopls/internal/lsp/protocol/generate/main.go @@ -191,9 +191,20 @@ func writejsons() { out := new(bytes.Buffer) fmt.Fprintln(out, fileHdr) out.WriteString("import \"encoding/json\"\n\n") - out.WriteString("import \"errors\"\n") out.WriteString("import \"fmt\"\n") + out.WriteString(` +// UnmarshalError indicates that a JSON value did not conform to +// one of the expected cases of an LSP union type. +type UnmarshalError struct { + msg string +} + +func (e UnmarshalError) Error() string { + return e.msg +} +`) + for _, k := range jsons.keys() { out.WriteString(jsons[k]) } diff --git a/gopls/internal/lsp/protocol/generate/output.go b/gopls/internal/lsp/protocol/generate/output.go index 04f1080c1..18dd6ea3f 100644 --- a/gopls/internal/lsp/protocol/generate/output.go +++ b/gopls/internal/lsp/protocol/generate/output.go @@ -387,7 +387,7 @@ func genMarshal() { fmt.Fprintf(&buf, "\tvar h%d %s\n", i, nmx) fmt.Fprintf(&buf, "\tif err := json.Unmarshal(x, &h%d); err == nil {\n\t\tt.Value = h%d\n\t\t\treturn nil\n\t\t}\n", i, i) } - fmt.Fprintf(&buf, "return errors.New(\"unmarshal failed to match one of %v\")\n", names) + fmt.Fprintf(&buf, "return &UnmarshalError{\"unmarshal failed to match one of %v\"}", names) buf.WriteString("}\n\n") jsons[nm] = buf.String() } diff --git a/gopls/internal/lsp/protocol/generate/tables.go b/gopls/internal/lsp/protocol/generate/tables.go index 121894a98..552de7122 100644 --- a/gopls/internal/lsp/protocol/generate/tables.go +++ b/gopls/internal/lsp/protocol/generate/tables.go @@ -140,50 +140,22 @@ var renameProp = map[prop]string{ {"Hover", "contents"}: "MarkupContent", {"InlayHint", "label"}: "[]InlayHintLabelPart", - // removing this causes the test in json_test.go to fail - // First, the custom unmarshaler returns the 'wrong' error type - // Second, cmp.Diff reports too many errors. - // TODO(pjw): fix json_test.go and maybe the generated code - {"Lit_SemanticTokensClientCapabilities_requests", "full"}: "interface{}", - {"Lit_SemanticTokensClientCapabilities_requests", "range"}: "bool", - {"NotebookCellTextDocumentFilter", "notebook"}: "NotebookDocumentFilter", {"RelatedFullDocumentDiagnosticReport", "relatedDocuments"}: "map[DocumentURI]interface{}", {"RelatedUnchangedDocumentDiagnosticReport", "relatedDocuments"}: "map[DocumentURI]interface{}", - // this one also has the json_test.go problem - {"RenameClientCapabilities", "prepareSupportDefaultBehavior"}: "interface{}", - - {"SemanticTokensOptions", "full"}: "bool", - {"SemanticTokensOptions", "range"}: "interface{}", - {"ServerCapabilities", "callHierarchyProvider"}: "interface{}", - {"ServerCapabilities", "codeActionProvider"}: "interface{}", - {"ServerCapabilities", "colorProvider"}: "interface{}", - {"ServerCapabilities", "declarationProvider"}: "bool", - {"ServerCapabilities", "definitionProvider"}: "bool", - {"ServerCapabilities", "diagnosticProvider"}: "interface{}", - {"ServerCapabilities", "documentFormattingProvider"}: "bool", - {"ServerCapabilities", "documentHighlightProvider"}: "bool", - {"ServerCapabilities", "documentRangeFormattingProvider"}: "bool", - {"ServerCapabilities", "documentSymbolProvider"}: "bool", - {"ServerCapabilities", "foldingRangeProvider"}: "interface{}", - {"ServerCapabilities", "hoverProvider"}: "bool", - {"ServerCapabilities", "implementationProvider"}: "interface{}", - {"ServerCapabilities", "inlayHintProvider"}: "interface{}", - {"ServerCapabilities", "inlineValueProvider"}: "interface{}", - {"ServerCapabilities", "linkedEditingRangeProvider"}: "interface{}", - {"ServerCapabilities", "monikerProvider"}: "interface{}", - {"ServerCapabilities", "notebookDocumentSync"}: "interface{}", - {"ServerCapabilities", "referencesProvider"}: "bool", - {"ServerCapabilities", "renameProvider"}: "interface{}", - {"ServerCapabilities", "selectionRangeProvider"}: "interface{}", - {"ServerCapabilities", "semanticTokensProvider"}: "interface{}", - {"ServerCapabilities", "textDocumentSync"}: "interface{}", - {"ServerCapabilities", "typeDefinitionProvider"}: "interface{}", - {"ServerCapabilities", "typeHierarchyProvider"}: "interface{}", - {"ServerCapabilities", "workspaceSymbolProvider"}: "bool", - {"TextDocumentEdit", "edits"}: "[]TextEdit", - {"TextDocumentSyncOptions", "save"}: "SaveOptions", - {"WorkspaceEdit", "documentChanges"}: "[]DocumentChanges", + // PJW: this one is tricky. + {"ServerCapabilities", "codeActionProvider"}: "interface{}", + + {"ServerCapabilities", "inlayHintProvider"}: "interface{}", + // slightly tricky + {"ServerCapabilities", "renameProvider"}: "interface{}", + // slightly tricky + {"ServerCapabilities", "semanticTokensProvider"}: "interface{}", + // slightly tricky + {"ServerCapabilities", "textDocumentSync"}: "interface{}", + {"TextDocumentEdit", "edits"}: "[]TextEdit", + {"TextDocumentSyncOptions", "save"}: "SaveOptions", + {"WorkspaceEdit", "documentChanges"}: "[]DocumentChanges", } // which entries of renameProp were used diff --git a/gopls/internal/lsp/protocol/tsclient.go b/gopls/internal/lsp/protocol/tsclient.go index 839cde385..835ad5a9c 100644 --- a/gopls/internal/lsp/protocol/tsclient.go +++ b/gopls/internal/lsp/protocol/tsclient.go @@ -7,7 +7,7 @@ package protocol // Code generated from version 3.17.0 of protocol/metaModel.json. -// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-13) +// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-18) import ( "context" diff --git a/gopls/internal/lsp/protocol/tsjson.go b/gopls/internal/lsp/protocol/tsjson.go index 333b6e398..48c1a5c51 100644 --- a/gopls/internal/lsp/protocol/tsjson.go +++ b/gopls/internal/lsp/protocol/tsjson.go @@ -7,13 +7,20 @@ package protocol // Code generated from version 3.17.0 of protocol/metaModel.json. -// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-13) +// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-18) import "encoding/json" -import "errors" import "fmt" +type UnmarshalError struct { + msg string +} + +func (e UnmarshalError) Error() string { + return e.msg +} + // from line 4768 func (t OrFEditRangePItemDefaults) MarshalJSON() ([]byte, error) { switch x := t.Value.(type) { @@ -42,7 +49,7 @@ func (t *OrFEditRangePItemDefaults) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [FEditRangePItemDefaults Range]") + return &UnmarshalError{"unmarshal failed to match one of [FEditRangePItemDefaults Range]"} } // from line 9810 @@ -73,7 +80,7 @@ func (t *OrFNotebookPNotebookSelector) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [NotebookDocumentFilter string]") + return &UnmarshalError{"unmarshal failed to match one of [NotebookDocumentFilter string]"} } // from line 5519 @@ -104,7 +111,7 @@ func (t *OrPLocation_workspace_symbol) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [Location PLocationMsg_workspace_symbol]") + return &UnmarshalError{"unmarshal failed to match one of [Location PLocationMsg_workspace_symbol]"} } // from line 4162 @@ -135,7 +142,7 @@ func (t *OrPSection_workspace_didChangeConfiguration) UnmarshalJSON(x []byte) er t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [[]string string]") + return &UnmarshalError{"unmarshal failed to match one of [[]string string]"} } // from line 7074 @@ -166,7 +173,7 @@ func (t *OrPTooltipPLabel) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [MarkupContent string]") + return &UnmarshalError{"unmarshal failed to match one of [MarkupContent string]"} } // from line 3698 @@ -197,7 +204,7 @@ func (t *OrPTooltip_textDocument_inlayHint) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [MarkupContent string]") + return &UnmarshalError{"unmarshal failed to match one of [MarkupContent string]"} } // from line 6183 @@ -228,7 +235,7 @@ func (t *Or_CancelParams_id) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [int32 string]") + return &UnmarshalError{"unmarshal failed to match one of [int32 string]"} } // from line 4581 @@ -259,7 +266,7 @@ func (t *Or_CompletionItem_documentation) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [MarkupContent string]") + return &UnmarshalError{"unmarshal failed to match one of [MarkupContent string]"} } // from line 4664 @@ -290,7 +297,7 @@ func (t *Or_CompletionItem_textEdit) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [InsertReplaceEdit TextEdit]") + return &UnmarshalError{"unmarshal failed to match one of [InsertReplaceEdit TextEdit]"} } // from line 13752 @@ -321,7 +328,7 @@ func (t *Or_Definition) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [Location []Location]") + return &UnmarshalError{"unmarshal failed to match one of [Location []Location]"} } // from line 8546 @@ -352,7 +359,7 @@ func (t *Or_Diagnostic_code) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [int32 string]") + return &UnmarshalError{"unmarshal failed to match one of [int32 string]"} } // from line 13884 @@ -383,7 +390,7 @@ func (t *Or_DocumentDiagnosticReport) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [RelatedFullDocumentDiagnosticReport RelatedUnchangedDocumentDiagnosticReport]") + return &UnmarshalError{"unmarshal failed to match one of [RelatedFullDocumentDiagnosticReport RelatedUnchangedDocumentDiagnosticReport]"} } // from line 3821 @@ -414,7 +421,7 @@ func (t *Or_DocumentDiagnosticReportPartialResult_relatedDocuments_Value) Unmars t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [FullDocumentDiagnosticReport UnchangedDocumentDiagnosticReport]") + return &UnmarshalError{"unmarshal failed to match one of [FullDocumentDiagnosticReport UnchangedDocumentDiagnosticReport]"} } // from line 14094 @@ -445,7 +452,7 @@ func (t *Or_DocumentFilter) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [NotebookCellTextDocumentFilter TextDocumentFilter]") + return &UnmarshalError{"unmarshal failed to match one of [NotebookCellTextDocumentFilter TextDocumentFilter]"} } // from line 4890 @@ -483,7 +490,7 @@ func (t *Or_Hover_contents) UnmarshalJSON(x []byte) error { t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [MarkedString MarkupContent []MarkedString]") + return &UnmarshalError{"unmarshal failed to match one of [MarkedString MarkupContent []MarkedString]"} } // from line 3657 @@ -514,7 +521,7 @@ func (t *Or_InlayHint_label) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [[]InlayHintLabelPart string]") + return &UnmarshalError{"unmarshal failed to match one of [[]InlayHintLabelPart string]"} } // from line 13862 @@ -552,7 +559,7 @@ func (t *Or_InlineValue) UnmarshalJSON(x []byte) error { t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [InlineValueEvaluatableExpression InlineValueText InlineValueVariableLookup]") + return &UnmarshalError{"unmarshal failed to match one of [InlineValueEvaluatableExpression InlineValueText InlineValueVariableLookup]"} } // from line 14059 @@ -583,7 +590,7 @@ func (t *Or_MarkedString) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [Msg_MarkedString string]") + return &UnmarshalError{"unmarshal failed to match one of [Msg_MarkedString string]"} } // from line 10117 @@ -614,7 +621,7 @@ func (t *Or_NotebookCellTextDocumentFilter_notebook) UnmarshalJSON(x []byte) err t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [NotebookDocumentFilter string]") + return &UnmarshalError{"unmarshal failed to match one of [NotebookDocumentFilter string]"} } // from line 9856 @@ -645,7 +652,7 @@ func (t *Or_NotebookDocumentSyncOptions_notebookSelector_Elem_Item1_notebook) Un t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [NotebookDocumentFilter string]") + return &UnmarshalError{"unmarshal failed to match one of [NotebookDocumentFilter string]"} } // from line 7167 @@ -676,7 +683,7 @@ func (t *Or_RelatedFullDocumentDiagnosticReport_relatedDocuments_Value) Unmarsha t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [FullDocumentDiagnosticReport UnchangedDocumentDiagnosticReport]") + return &UnmarshalError{"unmarshal failed to match one of [FullDocumentDiagnosticReport UnchangedDocumentDiagnosticReport]"} } // from line 7206 @@ -707,7 +714,7 @@ func (t *Or_RelatedUnchangedDocumentDiagnosticReport_relatedDocuments_Value) Unm t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [FullDocumentDiagnosticReport UnchangedDocumentDiagnosticReport]") + return &UnmarshalError{"unmarshal failed to match one of [FullDocumentDiagnosticReport UnchangedDocumentDiagnosticReport]"} } // from line 10740 @@ -738,7 +745,7 @@ func (t *Or_RelativePattern_baseUri) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [URI WorkspaceFolder]") + return &UnmarshalError{"unmarshal failed to match one of [URI WorkspaceFolder]"} } // from line 1370 @@ -769,7 +776,7 @@ func (t *Or_Result_textDocument_codeAction_Item0_Elem) UnmarshalJSON(x []byte) e t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [CodeAction Command]") + return &UnmarshalError{"unmarshal failed to match one of [CodeAction Command]"} } // from line 12196 @@ -800,7 +807,7 @@ func (t *Or_SemanticTokensClientCapabilities_requests_full) UnmarshalJSON(x []by t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [FFullPRequests bool]") + return &UnmarshalError{"unmarshal failed to match one of [FFullPRequests bool]"} } // from line 12176 @@ -831,7 +838,7 @@ func (t *Or_SemanticTokensClientCapabilities_requests_range) UnmarshalJSON(x []b t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [FRangePRequests bool]") + return &UnmarshalError{"unmarshal failed to match one of [FRangePRequests bool]"} } // from line 6578 @@ -862,7 +869,7 @@ func (t *Or_SemanticTokensOptions_full) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [PFullESemanticTokensOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [PFullESemanticTokensOptions bool]"} } // from line 6558 @@ -893,7 +900,7 @@ func (t *Or_SemanticTokensOptions_range) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [PRangeESemanticTokensOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [PRangeESemanticTokensOptions bool]"} } // from line 8226 @@ -931,7 +938,7 @@ func (t *Or_ServerCapabilities_callHierarchyProvider) UnmarshalJSON(x []byte) er t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [CallHierarchyOptions CallHierarchyRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [CallHierarchyOptions CallHierarchyRegistrationOptions bool]"} } // from line 8034 @@ -962,7 +969,7 @@ func (t *Or_ServerCapabilities_codeActionProvider) UnmarshalJSON(x []byte) error t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [CodeActionOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [CodeActionOptions bool]"} } // from line 8070 @@ -1000,7 +1007,7 @@ func (t *Or_ServerCapabilities_colorProvider) UnmarshalJSON(x []byte) error { t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [DocumentColorOptions DocumentColorRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [DocumentColorOptions DocumentColorRegistrationOptions bool]"} } // from line 7896 @@ -1038,7 +1045,7 @@ func (t *Or_ServerCapabilities_declarationProvider) UnmarshalJSON(x []byte) erro t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [DeclarationOptions DeclarationRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [DeclarationOptions DeclarationRegistrationOptions bool]"} } // from line 7918 @@ -1069,7 +1076,7 @@ func (t *Or_ServerCapabilities_definitionProvider) UnmarshalJSON(x []byte) error t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [DefinitionOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [DefinitionOptions bool]"} } // from line 8383 @@ -1100,7 +1107,7 @@ func (t *Or_ServerCapabilities_diagnosticProvider) UnmarshalJSON(x []byte) error t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [DiagnosticOptions DiagnosticRegistrationOptions]") + return &UnmarshalError{"unmarshal failed to match one of [DiagnosticOptions DiagnosticRegistrationOptions]"} } // from line 8110 @@ -1131,7 +1138,7 @@ func (t *Or_ServerCapabilities_documentFormattingProvider) UnmarshalJSON(x []byt t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [DocumentFormattingOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [DocumentFormattingOptions bool]"} } // from line 7998 @@ -1162,7 +1169,7 @@ func (t *Or_ServerCapabilities_documentHighlightProvider) UnmarshalJSON(x []byte t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [DocumentHighlightOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [DocumentHighlightOptions bool]"} } // from line 8128 @@ -1193,7 +1200,7 @@ func (t *Or_ServerCapabilities_documentRangeFormattingProvider) UnmarshalJSON(x t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [DocumentRangeFormattingOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [DocumentRangeFormattingOptions bool]"} } // from line 8016 @@ -1224,7 +1231,7 @@ func (t *Or_ServerCapabilities_documentSymbolProvider) UnmarshalJSON(x []byte) e t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [DocumentSymbolOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [DocumentSymbolOptions bool]"} } // from line 8173 @@ -1262,7 +1269,7 @@ func (t *Or_ServerCapabilities_foldingRangeProvider) UnmarshalJSON(x []byte) err t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [FoldingRangeOptions FoldingRangeRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [FoldingRangeOptions FoldingRangeRegistrationOptions bool]"} } // from line 7869 @@ -1293,7 +1300,7 @@ func (t *Or_ServerCapabilities_hoverProvider) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [HoverOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [HoverOptions bool]"} } // from line 7958 @@ -1331,7 +1338,7 @@ func (t *Or_ServerCapabilities_implementationProvider) UnmarshalJSON(x []byte) e t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [ImplementationOptions ImplementationRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [ImplementationOptions ImplementationRegistrationOptions bool]"} } // from line 8360 @@ -1369,7 +1376,7 @@ func (t *Or_ServerCapabilities_inlayHintProvider) UnmarshalJSON(x []byte) error t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [InlayHintOptions InlayHintRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [InlayHintOptions InlayHintRegistrationOptions bool]"} } // from line 8337 @@ -1407,7 +1414,7 @@ func (t *Or_ServerCapabilities_inlineValueProvider) UnmarshalJSON(x []byte) erro t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [InlineValueOptions InlineValueRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [InlineValueOptions InlineValueRegistrationOptions bool]"} } // from line 8249 @@ -1445,7 +1452,7 @@ func (t *Or_ServerCapabilities_linkedEditingRangeProvider) UnmarshalJSON(x []byt t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [LinkedEditingRangeOptions LinkedEditingRangeRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [LinkedEditingRangeOptions LinkedEditingRangeRegistrationOptions bool]"} } // from line 8291 @@ -1483,7 +1490,7 @@ func (t *Or_ServerCapabilities_monikerProvider) UnmarshalJSON(x []byte) error { t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [MonikerOptions MonikerRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [MonikerOptions MonikerRegistrationOptions bool]"} } // from line 7841 @@ -1514,7 +1521,7 @@ func (t *Or_ServerCapabilities_notebookDocumentSync) UnmarshalJSON(x []byte) err t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [NotebookDocumentSyncOptions NotebookDocumentSyncRegistrationOptions]") + return &UnmarshalError{"unmarshal failed to match one of [NotebookDocumentSyncOptions NotebookDocumentSyncRegistrationOptions]"} } // from line 7980 @@ -1545,7 +1552,7 @@ func (t *Or_ServerCapabilities_referencesProvider) UnmarshalJSON(x []byte) error t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [ReferenceOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [ReferenceOptions bool]"} } // from line 8155 @@ -1576,7 +1583,7 @@ func (t *Or_ServerCapabilities_renameProvider) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [RenameOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [RenameOptions bool]"} } // from line 8195 @@ -1614,7 +1621,7 @@ func (t *Or_ServerCapabilities_selectionRangeProvider) UnmarshalJSON(x []byte) e t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [SelectionRangeOptions SelectionRangeRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [SelectionRangeOptions SelectionRangeRegistrationOptions bool]"} } // from line 8272 @@ -1645,7 +1652,7 @@ func (t *Or_ServerCapabilities_semanticTokensProvider) UnmarshalJSON(x []byte) e t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [SemanticTokensOptions SemanticTokensRegistrationOptions]") + return &UnmarshalError{"unmarshal failed to match one of [SemanticTokensOptions SemanticTokensRegistrationOptions]"} } // from line 7823 @@ -1676,7 +1683,7 @@ func (t *Or_ServerCapabilities_textDocumentSync) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [TextDocumentSyncKind TextDocumentSyncOptions]") + return &UnmarshalError{"unmarshal failed to match one of [TextDocumentSyncKind TextDocumentSyncOptions]"} } // from line 7936 @@ -1714,7 +1721,7 @@ func (t *Or_ServerCapabilities_typeDefinitionProvider) UnmarshalJSON(x []byte) e t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [TypeDefinitionOptions TypeDefinitionRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [TypeDefinitionOptions TypeDefinitionRegistrationOptions bool]"} } // from line 8314 @@ -1752,7 +1759,7 @@ func (t *Or_ServerCapabilities_typeHierarchyProvider) UnmarshalJSON(x []byte) er t.Value = h2 return nil } - return errors.New("unmarshal failed to match one of [TypeHierarchyOptions TypeHierarchyRegistrationOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [TypeHierarchyOptions TypeHierarchyRegistrationOptions bool]"} } // from line 8092 @@ -1783,7 +1790,7 @@ func (t *Or_ServerCapabilities_workspaceSymbolProvider) UnmarshalJSON(x []byte) t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [WorkspaceSymbolOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [WorkspaceSymbolOptions bool]"} } // from line 8840 @@ -1814,7 +1821,7 @@ func (t *Or_SignatureInformation_documentation) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [MarkupContent string]") + return &UnmarshalError{"unmarshal failed to match one of [MarkupContent string]"} } // from line 6691 @@ -1845,7 +1852,7 @@ func (t *Or_TextDocumentEdit_edits_Elem) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [AnnotatedTextEdit TextEdit]") + return &UnmarshalError{"unmarshal failed to match one of [AnnotatedTextEdit TextEdit]"} } // from line 9776 @@ -1876,7 +1883,7 @@ func (t *Or_TextDocumentSyncOptions_save) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [SaveOptions bool]") + return &UnmarshalError{"unmarshal failed to match one of [SaveOptions bool]"} } // from line 13985 @@ -1907,7 +1914,7 @@ func (t *Or_WorkspaceDocumentDiagnosticReport) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [WorkspaceFullDocumentDiagnosticReport WorkspaceUnchangedDocumentDiagnosticReport]") + return &UnmarshalError{"unmarshal failed to match one of [WorkspaceFullDocumentDiagnosticReport WorkspaceUnchangedDocumentDiagnosticReport]"} } // from line 3218 @@ -1952,7 +1959,7 @@ func (t *Or_WorkspaceEdit_documentChanges_Elem) UnmarshalJSON(x []byte) error { t.Value = h3 return nil } - return errors.New("unmarshal failed to match one of [CreateFile DeleteFile RenameFile TextDocumentEdit]") + return &UnmarshalError{"unmarshal failed to match one of [CreateFile DeleteFile RenameFile TextDocumentEdit]"} } // from line 247 @@ -1983,5 +1990,5 @@ func (t *Or_textDocument_declaration) UnmarshalJSON(x []byte) error { t.Value = h1 return nil } - return errors.New("unmarshal failed to match one of [Declaration []DeclarationLink]") + return &UnmarshalError{"unmarshal failed to match one of [Declaration []DeclarationLink]"} } diff --git a/gopls/internal/lsp/protocol/tsprotocol.go b/gopls/internal/lsp/protocol/tsprotocol.go index c8b02d075..58292991d 100644 --- a/gopls/internal/lsp/protocol/tsprotocol.go +++ b/gopls/internal/lsp/protocol/tsprotocol.go @@ -7,7 +7,7 @@ package protocol // Code generated from version 3.17.0 of protocol/metaModel.json. -// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-13) +// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-18) import "encoding/json" @@ -3044,7 +3044,7 @@ type NotebookCellTextDocumentFilter struct { // line 10112 * value is provided it matches against the * notebook type. '*' matches every notebook. */ - Notebook NotebookDocumentFilter `json:"notebook"` + Notebook Or_NotebookCellTextDocumentFilter_notebook `json:"notebook"` /* * A language id like `python`. * @@ -3742,12 +3742,12 @@ type PRequestsPSemanticTokens struct { // line 12171 * The client will send the `textDocument/semanticTokens/range` request if * the server provides a corresponding handler. */ - Range bool `json:"range"` + Range Or_SemanticTokensClientCapabilities_requests_range `json:"range"` /* * The client will send the `textDocument/semanticTokens/full` request if * the server provides a corresponding handler. */ - Full interface{} `json:"full"` + Full Or_SemanticTokensClientCapabilities_requests_full `json:"full"` } // created for Literal (Lit_CodeActionClientCapabilities_resolveSupport) @@ -4208,7 +4208,7 @@ type RenameClientCapabilities struct { // line 11933 * * @since 3.16.0 */ - PrepareSupportDefaultBehavior interface{} `json:"prepareSupportDefaultBehavior,omitempty"` + PrepareSupportDefaultBehavior *PrepareSupportDefaultBehavior `json:"prepareSupportDefaultBehavior,omitempty"` /* * Whether the client honors the change annotations in * text edits and resource operations returned via the @@ -4476,9 +4476,9 @@ type SemanticTokensOptions struct { // line 6545 * Server supports providing semantic tokens for a specific range * of a document. */ - Range interface{} `json:"range,omitempty"` + Range *Or_SemanticTokensOptions_range `json:"range,omitempty"` // Server supports providing semantic tokens for a full document. - Full bool `json:"full,omitempty"` + Full *Or_SemanticTokensOptions_full `json:"full,omitempty"` WorkDoneProgressOptions } @@ -4554,27 +4554,27 @@ type ServerCapabilities struct { // line 7808 * * @since 3.17.0 */ - NotebookDocumentSync interface{} `json:"notebookDocumentSync,omitempty"` + NotebookDocumentSync *Or_ServerCapabilities_notebookDocumentSync `json:"notebookDocumentSync,omitempty"` // The server provides completion support. CompletionProvider CompletionOptions `json:"completionProvider,omitempty"` // The server provides hover support. - HoverProvider bool `json:"hoverProvider,omitempty"` + HoverProvider *Or_ServerCapabilities_hoverProvider `json:"hoverProvider,omitempty"` // The server provides signature help support. SignatureHelpProvider SignatureHelpOptions `json:"signatureHelpProvider,omitempty"` // The server provides Goto Declaration support. - DeclarationProvider bool `json:"declarationProvider,omitempty"` + DeclarationProvider *Or_ServerCapabilities_declarationProvider `json:"declarationProvider,omitempty"` // The server provides goto definition support. - DefinitionProvider bool `json:"definitionProvider,omitempty"` + DefinitionProvider *Or_ServerCapabilities_definitionProvider `json:"definitionProvider,omitempty"` // The server provides Goto Type Definition support. - TypeDefinitionProvider interface{} `json:"typeDefinitionProvider,omitempty"` + TypeDefinitionProvider *Or_ServerCapabilities_typeDefinitionProvider `json:"typeDefinitionProvider,omitempty"` // The server provides Goto Implementation support. - ImplementationProvider interface{} `json:"implementationProvider,omitempty"` + ImplementationProvider *Or_ServerCapabilities_implementationProvider `json:"implementationProvider,omitempty"` // The server provides find references support. - ReferencesProvider bool `json:"referencesProvider,omitempty"` + ReferencesProvider *Or_ServerCapabilities_referencesProvider `json:"referencesProvider,omitempty"` // The server provides document highlight support. - DocumentHighlightProvider bool `json:"documentHighlightProvider,omitempty"` + DocumentHighlightProvider *Or_ServerCapabilities_documentHighlightProvider `json:"documentHighlightProvider,omitempty"` // The server provides document symbol support. - DocumentSymbolProvider bool `json:"documentSymbolProvider,omitempty"` + DocumentSymbolProvider *Or_ServerCapabilities_documentSymbolProvider `json:"documentSymbolProvider,omitempty"` /* * The server provides code actions. CodeActionOptions may only be * specified if the client states that it supports @@ -4586,13 +4586,13 @@ type ServerCapabilities struct { // line 7808 // The server provides document link support. DocumentLinkProvider DocumentLinkOptions `json:"documentLinkProvider,omitempty"` // The server provides color provider support. - ColorProvider interface{} `json:"colorProvider,omitempty"` + ColorProvider *Or_ServerCapabilities_colorProvider `json:"colorProvider,omitempty"` // The server provides workspace symbol support. - WorkspaceSymbolProvider bool `json:"workspaceSymbolProvider,omitempty"` + WorkspaceSymbolProvider *Or_ServerCapabilities_workspaceSymbolProvider `json:"workspaceSymbolProvider,omitempty"` // The server provides document formatting. - DocumentFormattingProvider bool `json:"documentFormattingProvider,omitempty"` + DocumentFormattingProvider *Or_ServerCapabilities_documentFormattingProvider `json:"documentFormattingProvider,omitempty"` // The server provides document range formatting. - DocumentRangeFormattingProvider bool `json:"documentRangeFormattingProvider,omitempty"` + DocumentRangeFormattingProvider *Or_ServerCapabilities_documentRangeFormattingProvider `json:"documentRangeFormattingProvider,omitempty"` // The server provides document formatting on typing. DocumentOnTypeFormattingProvider *DocumentOnTypeFormattingOptions `json:"documentOnTypeFormattingProvider,omitempty"` /* @@ -4602,9 +4602,9 @@ type ServerCapabilities struct { // line 7808 */ RenameProvider interface{} `json:"renameProvider,omitempty"` // The server provides folding provider support. - FoldingRangeProvider interface{} `json:"foldingRangeProvider,omitempty"` + FoldingRangeProvider *Or_ServerCapabilities_foldingRangeProvider `json:"foldingRangeProvider,omitempty"` // The server provides selection range support. - SelectionRangeProvider interface{} `json:"selectionRangeProvider,omitempty"` + SelectionRangeProvider *Or_ServerCapabilities_selectionRangeProvider `json:"selectionRangeProvider,omitempty"` // The server provides execute command support. ExecuteCommandProvider ExecuteCommandOptions `json:"executeCommandProvider,omitempty"` /* @@ -4612,13 +4612,13 @@ type ServerCapabilities struct { // line 7808 * * @since 3.16.0 */ - CallHierarchyProvider interface{} `json:"callHierarchyProvider,omitempty"` + CallHierarchyProvider *Or_ServerCapabilities_callHierarchyProvider `json:"callHierarchyProvider,omitempty"` /* * The server provides linked editing range support. * * @since 3.16.0 */ - LinkedEditingRangeProvider interface{} `json:"linkedEditingRangeProvider,omitempty"` + LinkedEditingRangeProvider *Or_ServerCapabilities_linkedEditingRangeProvider `json:"linkedEditingRangeProvider,omitempty"` /* * The server provides semantic tokens support. * @@ -4630,19 +4630,19 @@ type ServerCapabilities struct { // line 7808 * * @since 3.16.0 */ - MonikerProvider interface{} `json:"monikerProvider,omitempty"` + MonikerProvider *Or_ServerCapabilities_monikerProvider `json:"monikerProvider,omitempty"` /* * The server provides type hierarchy support. * * @since 3.17.0 */ - TypeHierarchyProvider interface{} `json:"typeHierarchyProvider,omitempty"` + TypeHierarchyProvider *Or_ServerCapabilities_typeHierarchyProvider `json:"typeHierarchyProvider,omitempty"` /* * The server provides inline values. * * @since 3.17.0 */ - InlineValueProvider interface{} `json:"inlineValueProvider,omitempty"` + InlineValueProvider *Or_ServerCapabilities_inlineValueProvider `json:"inlineValueProvider,omitempty"` /* * The server provides inlay hints. * @@ -4654,7 +4654,7 @@ type ServerCapabilities struct { // line 7808 * * @since 3.17.0 */ - DiagnosticProvider interface{} `json:"diagnosticProvider,omitempty"` + DiagnosticProvider *Or_ServerCapabilities_diagnosticProvider `json:"diagnosticProvider,omitempty"` // Workspace specific server capabilities. Workspace Workspace6Gn `json:"workspace,omitempty"` // Experimental server capabilities. diff --git a/gopls/internal/lsp/protocol/tsserver.go b/gopls/internal/lsp/protocol/tsserver.go index 3fa638d19..e04662dbe 100644 --- a/gopls/internal/lsp/protocol/tsserver.go +++ b/gopls/internal/lsp/protocol/tsserver.go @@ -7,7 +7,7 @@ package protocol // Code generated from version 3.17.0 of protocol/metaModel.json. -// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-13) +// git hash 9b742021fb04ad081aa3676a9eecf4fa612084b4 (as of 2023-02-18) import ( "context" diff --git a/gopls/internal/lsp/workspace.go b/gopls/internal/lsp/workspace.go index c50ae32bb..7c02239e6 100644 --- a/gopls/internal/lsp/workspace.go +++ b/gopls/internal/lsp/workspace.go @@ -88,8 +88,8 @@ func semanticTokenRegistration(tokenTypes, tokenModifiers []string) protocol.Reg TokenTypes: tokenTypes, TokenModifiers: tokenModifiers, }, - Full: true, - Range: true, + Full: &protocol.Or_SemanticTokensOptions_full{Value: true}, + Range: &protocol.Or_SemanticTokensOptions_range{Value: true}, }, } } diff --git a/gopls/test/json_test.go b/gopls/test/json_test.go index 993af3095..7a91a953a 100644 --- a/gopls/test/json_test.go +++ b/gopls/test/json_test.go @@ -28,8 +28,9 @@ import ( // bools are changed to numbers or strings // numbers are changed to strings or bools -// a recent Initialize message taken from a log -const input = `{"processId":38349,"clientInfo":{"name":"vscode","version":"1.56.0-insider"},"rootPath":"/Users/pjw/latest/tools","rootUri":"file:///Users/pjw/latest/tools","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true,"prepareSupportDefaultBehavior":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","member","macro","keyword","modifier","comment","string","number","regexp","operator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}}}},"window":{"workDoneProgress":true}},"initializationOptions":{"usePlaceholders":true,"completionDocumentation":true,"verboseOutput":false,"codelenses":{"gc_details":true},"analyses":{"fillstruct":true,"staticcheck":true},"experimentalWorkspaceModule":true,"semanticTokens":true},"trace":"off","workspaceFolders":[{"uri":"file:///Users/pjw/latest/tools","name":"tools"}]}` +// a recent Initialize message taken from a log (at some point +// some field incompatibly changed from bool to int32) +const input = `{"processId":46408,"clientInfo":{"name":"Visual Studio Code - Insiders","version":"1.76.0-insider"},"locale":"en-us","rootPath":"/Users/pjw/hakim","rootUri":"file:///Users/pjw/hakim","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional","normalizesLineEndings":true,"changeAnnotationSupport":{"groupsOnLabel":true}},"configuration":true,"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]},"resolveSupport":{"properties":["location.range"]}},"codeLens":{"refreshSupport":true},"executeCommand":{"dynamicRegistration":true},"didChangeConfiguration":{"dynamicRegistration":true},"workspaceFolders":true,"semanticTokens":{"refreshSupport":true},"fileOperations":{"dynamicRegistration":true,"didCreate":true,"didRename":true,"didDelete":true,"willCreate":true,"willRename":true,"willDelete":true},"inlineValue":{"refreshSupport":true},"inlayHint":{"refreshSupport":true},"diagnostics":{"refreshSupport":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"insertTextModeSupport":{"valueSet":[1,2]},"labelDetailsSupport":true},"insertTextMode":2,"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode"]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"honorsChangeAnnotations":false},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true,"prepareSupportDefaultBehavior":1,"honorsChangeAnnotations":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true,"foldingRangeKind":{"valueSet":["comment","imports","region"]},"foldingRange":{"collapsedText":false}},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator","decorator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}},"multilineTokenSupport":false,"overlappingTokenSupport":false,"serverCancelSupport":true,"augmentsSyntaxTokens":true},"linkedEditingRange":{"dynamicRegistration":true},"typeHierarchy":{"dynamicRegistration":true},"inlineValue":{"dynamicRegistration":true},"inlayHint":{"dynamicRegistration":true,"resolveSupport":{"properties":["tooltip","textEdits","label.tooltip","label.location","label.command"]}},"diagnostic":{"dynamicRegistration":true,"relatedDocumentSupport":false}},"window":{"showMessage":{"messageActionItem":{"additionalPropertiesSupport":true}},"showDocument":{"support":true},"workDoneProgress":true},"general":{"staleRequestSupport":{"cancel":true,"retryOnContentModified":["textDocument/semanticTokens/full","textDocument/semanticTokens/range","textDocument/semanticTokens/full/delta"]},"regularExpressions":{"engine":"ECMAScript","version":"ES2020"},"markdown":{"parser":"marked","version":"1.1.0"},"positionEncodings":["utf-16"]},"notebookDocument":{"synchronization":{"dynamicRegistration":true,"executionSummarySupport":true}}},"initializationOptions":{"usePlaceholders":true,"completionDocumentation":true,"verboseOutput":false,"build.directoryFilters":["-foof","-internal/lsp/protocol/typescript"],"codelenses":{"reference":true,"gc_details":true},"analyses":{"fillstruct":true,"staticcheck":true,"unusedparams":false,"composites":false},"semanticTokens":true,"noSemanticString":true,"noSemanticNumber":true,"templateExtensions":["tmpl","gotmpl"],"ui.completion.matcher":"Fuzzy","ui.inlayhint.hints":{"assignVariableTypes":false,"compositeLiteralFields":false,"compositeLiteralTypes":false,"constantValues":false,"functionTypeParameters":false,"parameterNames":false,"rangeVariableTypes":false},"ui.vulncheck":"Off","allExperiments":true},"trace":"off","workspaceFolders":[{"uri":"file:///Users/pjw/hakim","name":"hakim"}]}` type DiffReporter struct { path cmp.Path @@ -115,13 +116,18 @@ func tryChange(start, end int, repl string) error { mb := mod[a:b] return ma, mb } + if err := json.Unmarshal([]byte(input), &p); err != nil { return fmt.Errorf("%s %v", repl, err) } - if err := json.Unmarshal([]byte(mod), &q); err == nil { - return nil // no errors is ok - } else if _, ok := err.(*json.UnmarshalTypeError); !ok { - return fmt.Errorf("%T, not *json.UnmarshalTypeError", err) + switch err := json.Unmarshal([]byte(mod), &q).(type) { + case nil: //ok + case *json.UnmarshalTypeError: + break + case *protocol.UnmarshalError: + return nil // cmp.Diff produces several diffs for custom unmrshalers + default: + return fmt.Errorf("%T unexpected unmarshal error", err) } var r DiffReporter |