From f5e54a0178e35c307bc857160525a17b9e839c5f Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Sat, 6 Feb 2021 05:24:28 +0900 Subject: [PATCH] all: support lsp 3.15.3 --- basic.go | 176 ++- basic_gojay.go | 65 +- basic_test.go | 50 +- client.go | 12 +- client_gojay.go | 4 +- client_json.go | 4 +- general.go | 360 ++++- general_gojay.go | 1267 ++++++++++++++-- general_gojay_test.go | 84 ++ general_json_test.go | 82 + general_test.go | 3118 ++++++++++++++++++++++++++++++++++++--- handler.go | 44 - handler_gojay.go | 63 + handler_json.go | 58 + keys_gojay.go | 25 + language.go | 186 ++- language_gojay.go | 290 +++- language_gojay_test.go | 12 + language_json_test.go | 12 + language_test.go | 824 ++++++++++- progress.go | 198 +++ progress_gojay.go | 250 ++++ selectionrange.go | 105 ++ selectionrange_gojay.go | 164 ++ selectionrange_json.go | 10 + server.go | 68 +- server_gojay.go | 16 +- server_json.go | 16 +- text_test.go | 2 +- util.go | 4 +- util_test.go | 8 +- version.go | 2 +- window.go | 16 + window_gojay.go | 74 +- window_gojay_test.go | 8 + window_json_test.go | 8 + window_test.go | 192 +++ workspace.go | 9 +- workspace_gojay.go | 16 +- workspace_test.go | 52 +- 40 files changed, 7383 insertions(+), 571 deletions(-) create mode 100644 handler_gojay.go create mode 100644 handler_json.go create mode 100644 progress.go create mode 100644 progress_gojay.go create mode 100644 selectionrange.go create mode 100644 selectionrange_gojay.go create mode 100644 selectionrange_json.go diff --git a/basic.go b/basic.go index 91ad33d9..88928dd9 100644 --- a/basic.go +++ b/basic.go @@ -95,6 +95,11 @@ type Diagnostic struct { // Message is the diagnostic's message. Message string `json:"message"` + // Tags is the additional metadata about the diagnostic. + // + // @since 3.15.0. + Tags []DiagnosticTag `json:"tags,omitempty"` + // RelatedInformation an array of related diagnostic information, e.g. when symbol-names within // a scope collide all definitions can be marked via this property. RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"` @@ -133,6 +138,37 @@ func (d DiagnosticSeverity) String() string { } } +// DiagnosticTag is the diagnostic tags. +// +// @since 3.15.0. +type DiagnosticTag float64 + +// list of DiagnosticTag. +const ( + // DiagnosticUnnecessary unused or unnecessary code. + // + // Clients are allowed to render diagnostics with this tag faded out instead of having + // an error squiggle. + DiagnosticUnnecessary DiagnosticTag = 1 + + // DiagnosticDeprecated deprecated or obsolete code. + // + // Clients are allowed to rendered diagnostics with this tag strike through. + DiagnosticDeprecated DiagnosticTag = 2 +) + +// String implements fmt.Stringer. +func (d DiagnosticTag) String() string { + switch d { + case DiagnosticUnnecessary: + return "Unnecessary" + case DiagnosticDeprecated: + return "Deprecated" + default: + return strconv.FormatFloat(float64(d), 'f', -10, 64) + } +} + // DiagnosticRelatedInformation represents a related message and source code location for a diagnostic. // // This should be used to point to code locations that cause or related to a diagnostics, e.g when duplicating @@ -312,6 +348,9 @@ type TextDocumentItem struct { type LanguageIdentifier string const ( + // ABAPLanguage ABAP Language. + ABAPLanguage LanguageIdentifier = "abap" + // BatLanguage Windows Bat Language. BatLanguage LanguageIdentifier = "bat" @@ -321,8 +360,8 @@ const ( // ClojureLanguage Clojure Language. ClojureLanguage LanguageIdentifier = "clojure" - // CoffeescriptLanguage Coffeescript Language. - CoffeescriptLanguage LanguageIdentifier = "coffeescript" + // CoffeescriptLanguage CoffeeScript Language. + CoffeeScriptLanguage LanguageIdentifier = "coffeescript" // CLanguage C Language. CLanguage LanguageIdentifier = "c" @@ -345,6 +384,12 @@ const ( // DockerfileLanguage Dockerfile Language. DockerfileLanguage LanguageIdentifier = "dockerfile" + // ElixirLanguage Elixir Language. + ElixirLanguage LanguageIdentifier = "elixir" + + // ErlangLanguage Erlang Language. + ErlangLanguage LanguageIdentifier = "erlang" + // FsharpLanguage F# Language. FsharpLanguage LanguageIdentifier = "fsharp" @@ -375,6 +420,9 @@ const ( // JavaScriptLanguage JavaScript Language. JavaScriptLanguage LanguageIdentifier = "javascript" + // JavaScriptReactLanguage JavaScript React Language. + JavaScriptReactLanguage LanguageIdentifier = "javascriptreact" + // JSONLanguage JSON Language. JSONLanguage LanguageIdentifier = "json" @@ -429,11 +477,11 @@ const ( // RustLanguage Rust Language. RustLanguage LanguageIdentifier = "rust" - // ScssLanguage Sass Language. - ScssLanguage LanguageIdentifier = "scss" + // SCSSLanguage SCSS Languages syntax using curly brackets. + SCSSLanguage LanguageIdentifier = "scss" - // SassLanguage Sass Language. - SassLanguage LanguageIdentifier = "sass" + // SASSLanguage SCSS Languages indented syntax. + SASSLanguage LanguageIdentifier = "sass" // ScalaLanguage Scala Language. ScalaLanguage LanguageIdentifier = "scala" @@ -453,8 +501,11 @@ const ( // TypeScriptLanguage TypeScript Language. TypeScriptLanguage LanguageIdentifier = "typescript" - // TexLanguage TeX Language. - TexLanguage LanguageIdentifier = "tex" + // TypeScriptReactLanguage TypeScript React Language. + TypeScriptReactLanguage LanguageIdentifier = "typescriptreact" + + // TeXLanguage TeX Language. + TeXLanguage LanguageIdentifier = "tex" // VBLanguage Visual Basic Language. VBLanguage LanguageIdentifier = "vb" @@ -471,58 +522,63 @@ const ( // languageIdentifierMap map of LanguageIdentifiers. var languageIdentifierMap = map[string]LanguageIdentifier{ - "bat": BatLanguage, - "bibtex": BibtexLanguage, - "clojure": ClojureLanguage, - "coffeescript": CoffeescriptLanguage, - "c": CLanguage, - "cpp": CppLanguage, - "csharp": CsharpLanguage, - "css": CSSLanguage, - "diff": DiffLanguage, - "dart": DartLanguage, - "dockerfile": DockerfileLanguage, - "fsharp": FsharpLanguage, - "git-commit": GitCommitLanguage, - "git-rebase": GitRebaseLanguage, - "go": GoLanguage, - "groovy": GroovyLanguage, - "handlebars": HandlebarsLanguage, - "html": HTMLLanguage, - "ini": IniLanguage, - "java": JavaLanguage, - "javascript": JavaScriptLanguage, - "json": JSONLanguage, - "latex": LatexLanguage, - "less": LessLanguage, - "lua": LuaLanguage, - "makefile": MakefileLanguage, - "markdown": MarkdownLanguage, - "objective-c": ObjectiveCLanguage, - "objective-cpp": ObjectiveCppLanguage, - "perl": PerlLanguage, - "perl6": Perl6Language, - "php": PHPLanguage, - "powershell": PowershellLanguage, - "jade": JadeLanguage, - "python": PythonLanguage, - "r": RLanguage, - "razor": RazorLanguage, - "ruby": RubyLanguage, - "rust": RustLanguage, - "scss": ScssLanguage, - "sass": SassLanguage, - "scala": ScalaLanguage, - "shaderlab": ShaderlabLanguage, - "shellscript": ShellscriptLanguage, - "sql": SQLLanguage, - "swift": SwiftLanguage, - "typescript": TypeScriptLanguage, - "tex": TexLanguage, - "vb": VBLanguage, - "xml": XMLLanguage, - "xsl": XslLanguage, - "yaml": YamlLanguage, + "abap": ABAPLanguage, + "bat": BatLanguage, + "bibtex": BibtexLanguage, + "clojure": ClojureLanguage, + "coffeescript": CoffeeScriptLanguage, + "c": CLanguage, + "cpp": CppLanguage, + "csharp": CsharpLanguage, + "css": CSSLanguage, + "diff": DiffLanguage, + "dart": DartLanguage, + "dockerfile": DockerfileLanguage, + "elixir": ElixirLanguage, + "erlang": ErlangLanguage, + "fsharp": FsharpLanguage, + "git-commit": GitCommitLanguage, + "git-rebase": GitRebaseLanguage, + "go": GoLanguage, + "groovy": GroovyLanguage, + "handlebars": HandlebarsLanguage, + "html": HTMLLanguage, + "ini": IniLanguage, + "java": JavaLanguage, + "javascript": JavaScriptLanguage, + "javascriptreact": JavaScriptReactLanguage, + "json": JSONLanguage, + "latex": LatexLanguage, + "less": LessLanguage, + "lua": LuaLanguage, + "makefile": MakefileLanguage, + "markdown": MarkdownLanguage, + "objective-c": ObjectiveCLanguage, + "objective-cpp": ObjectiveCppLanguage, + "perl": PerlLanguage, + "perl6": Perl6Language, + "php": PHPLanguage, + "powershell": PowershellLanguage, + "jade": JadeLanguage, + "python": PythonLanguage, + "r": RLanguage, + "razor": RazorLanguage, + "ruby": RubyLanguage, + "rust": RustLanguage, + "scss": SCSSLanguage, + "sass": SASSLanguage, + "scala": ScalaLanguage, + "shaderlab": ShaderlabLanguage, + "shellscript": ShellscriptLanguage, + "sql": SQLLanguage, + "swift": SwiftLanguage, + "typescript": TypeScriptLanguage, + "typescriptreact": TypeScriptReactLanguage, + "tex": TeXLanguage, + "vb": VBLanguage, + "xml": XMLLanguage, + "xsl": XslLanguage, + "yaml": YamlLanguage, } // ToLanguageIdentifier converts ft to LanguageIdentifier. diff --git a/basic_gojay.go b/basic_gojay.go index a83c7410..2dc56edb 100644 --- a/basic_gojay.go +++ b/basic_gojay.go @@ -41,6 +41,35 @@ var ( _ gojay.UnmarshalerJSONObject = (*Position)(nil) ) +// Positions represents a slice of Position. +type Positions []Position + +// MarshalJSONArray implements gojay.MarshalerJSONArray. +func (v Positions) MarshalJSONArray(enc *gojay.Encoder) { + for i := range v { + enc.Object(&v[i]) + } +} + +// IsNil implements gojay.MarshalerJSONArray. +func (v Positions) IsNil() bool { return len(v) == 0 } + +// UnmarshalJSONArray implements gojay.UnmarshalerJSONArray. +func (v *Positions) UnmarshalJSONArray(dec *gojay.Decoder) error { + value := Position{} + if err := dec.Object(&value); err != nil { + return err + } + *v = append(*v, value) + return nil +} + +// compile time check whether the Positions implements a gojay.MarshalerJSONArray and gojay.UnmarshalerJSONArray interfaces. +var ( + _ gojay.MarshalerJSONArray = (*Positions)(nil) + _ gojay.UnmarshalerJSONArray = (*Positions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *Range) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyStart, &v.Start) @@ -144,6 +173,7 @@ func (v *Diagnostic) MarshalJSONObject(enc *gojay.Encoder) { enc.AddInterfaceKeyOmitEmpty(keyCode, v.Code) enc.StringKeyOmitEmpty(keySource, v.Source) enc.StringKey(keyMessage, v.Message) + enc.ArrayKeyOmitEmpty(keyTags, DiagnosticTags(v.Tags)) enc.ArrayKeyOmitEmpty(keyRelatedInformation, DiagnosticRelatedInformations(v.RelatedInformation)) } @@ -163,6 +193,8 @@ func (v *Diagnostic) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { return dec.String(&v.Source) case keyMessage: return dec.String(&v.Message) + case keyTags: + return dec.Array((*DiagnosticTags)(&v.Tags)) case keyRelatedInformation: values := DiagnosticRelatedInformations{} err := dec.Array(&values) @@ -175,7 +207,7 @@ func (v *Diagnostic) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { } // NKeys returns the number of keys to unmarshal. -func (v *Diagnostic) NKeys() int { return 6 } +func (v *Diagnostic) NKeys() int { return 7 } // compile time check whether the Diagnostic implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -183,6 +215,35 @@ var ( _ gojay.UnmarshalerJSONObject = (*Diagnostic)(nil) ) +// DiagnosticTags represents a slice of DiagnosticTag. +type DiagnosticTags []DiagnosticTag + +// MarshalJSONArray implements gojay.MarshalerJSONArray. +func (v DiagnosticTags) MarshalJSONArray(enc *gojay.Encoder) { + for i := range v { + enc.Float64(float64(v[i])) + } +} + +// IsNil implements gojay.MarshalerJSONArray. +func (v DiagnosticTags) IsNil() bool { return len(v) == 0 } + +// UnmarshalJSONArray implements gojay.UnmarshalerJSONArray. +func (v *DiagnosticTags) UnmarshalJSONArray(dec *gojay.Decoder) error { + var value DiagnosticTag + if err := dec.Float64((*float64)(&value)); err != nil { + return err + } + *v = append(*v, value) + return nil +} + +// compile time check whether the CodeActionKinds implements a gojay.MarshalerJSONArray and gojay.UnmarshalerJSONArray interfaces. +var ( + _ gojay.MarshalerJSONArray = (*DiagnosticTags)(nil) + _ gojay.UnmarshalerJSONArray = (*DiagnosticTags)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *DiagnosticRelatedInformation) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyLocation, &v.Location) @@ -718,7 +779,7 @@ var ( func (v *VersionedTextDocumentIdentifier) MarshalJSONObject(enc *gojay.Encoder) { enc.StringKey(keyURI, string(v.URI)) if v.Version == nil { - v.Version = Uint64Ptr(0) + v.Version = NewVersion(0) } enc.Uint64KeyNullEmpty(keyVersion, *v.Version) } diff --git a/basic_test.go b/basic_test.go index a4172ab2..8dc29e27 100644 --- a/basic_test.go +++ b/basic_test.go @@ -462,7 +462,7 @@ func testLocationLink(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc func testDiagnostic(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/basic.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"basic_gen.go"}]}` + want = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","tags":[1,2],"relatedInformation":[{"location":{"uri":"file:///path/to/basic.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"basic_gen.go"}]}` wantNilSeverity = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/basic.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"basic_gen.go"}]}` wantNilCode = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/basic.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"basic_gen.go"}]}` wantNilRelatedInformation = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar"}` @@ -484,6 +484,10 @@ func testDiagnostic(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) Code: "foo/bar", Source: "test foo bar", Message: "foo bar", + Tags: []DiagnosticTag{ + DiagnosticUnnecessary, + DiagnosticDeprecated, + }, RelatedInformation: []DiagnosticRelatedInformation{ { Location: Location{ @@ -784,6 +788,40 @@ func TestDiagnosticSeverity_String(t *testing.T) { } } +func TestDiagnosticTag_String(t *testing.T) { + tests := []struct { + name string + d DiagnosticTag + want string + }{ + { + name: "Unnecessary", + d: DiagnosticUnnecessary, + want: "Unnecessary", + }, + { + name: "Deprecated", + d: DiagnosticDeprecated, + want: "Deprecated", + }, + { + name: "Unknown", + d: DiagnosticTag(0), + want: "0", + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + if got := tt.d.String(); got != tt.want { + t.Errorf("DiagnosticSeverity.String() = %v, want %v", got, tt.want) + } + }) + } +} + func testDiagnosticRelatedInformation(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( want = `{"location":{"uri":"file:///path/to/basic.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"basic_gen.go"}` @@ -1148,7 +1186,7 @@ func testTextDocumentEdit(t *testing.T, marshal marshalFunc, unmarshal unmarshal TextDocumentIdentifier: TextDocumentIdentifier{ URI: "file:///path/to/basic.go", }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, Edits: []TextEdit{ { @@ -1171,7 +1209,7 @@ func testTextDocumentEdit(t *testing.T, marshal marshalFunc, unmarshal unmarshal TextDocumentIdentifier: TextDocumentIdentifier{ URI: "file:///path/to/basic.go", }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, Edits: []TextEdit{ { @@ -2134,7 +2172,7 @@ func testWorkspaceEdit(t *testing.T, marshal marshalFunc, unmarshal unmarshalFun TextDocumentIdentifier: TextDocumentIdentifier{ URI: uri.File("/path/to/basic.go"), }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, Edits: []TextEdit{ { @@ -2161,7 +2199,7 @@ func testWorkspaceEdit(t *testing.T, marshal marshalFunc, unmarshal unmarshalFun TextDocumentIdentifier: TextDocumentIdentifier{ URI: uri.File("/path/to/basic.go"), }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, Edits: []TextEdit{ { @@ -2563,7 +2601,7 @@ func testVersionedTextDocumentIdentifier(t *testing.T, marshal marshalFunc, unma TextDocumentIdentifier: TextDocumentIdentifier{ URI: uri.File("/path/to/basic.go"), }, - Version: Uint64Ptr(10), + Version: NewVersion(10), } wantTypeNullVersion := VersionedTextDocumentIdentifier{ TextDocumentIdentifier: TextDocumentIdentifier{ diff --git a/client.go b/client.go index 60eed9fb..5116cf61 100644 --- a/client.go +++ b/client.go @@ -49,8 +49,8 @@ type Client interface { Telemetry(ctx context.Context, params interface{}) (err error) RegisterCapability(ctx context.Context, params *RegistrationParams) (err error) UnregisterCapability(ctx context.Context, params *UnregistrationParams) (err error) - WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (result bool, err error) - WorkspaceConfiguration(ctx context.Context, params *ConfigurationParams) (result []interface{}, err error) + ApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (result bool, err error) + Configuration(ctx context.Context, params *ConfigurationParams) (result []interface{}, err error) WorkspaceFolders(ctx context.Context) (result []WorkspaceFolder, err error) } @@ -170,8 +170,8 @@ func (c *client) UnregisterCapability(ctx context.Context, params *Unregistratio return Call(ctx, c.Conn, MethodClientUnregisterCapability, params, nil) } -// WorkspaceApplyEdit sends the request from the server to the client to modify resource on the client side. -func (c *client) WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (result bool, err error) { +// ApplyEdit sends the request from the server to the client to modify resource on the client side. +func (c *client) ApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (result bool, err error) { c.logger.Debug("call " + MethodWorkspaceApplyEdit) defer c.logger.Debug("end "+MethodWorkspaceApplyEdit, zap.Error(err)) @@ -181,12 +181,12 @@ func (c *client) WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceE return result, nil } -// WorkspaceConfiguration sends the request from the server to the client to fetch configuration settings from the client. +// Configuration sends the request from the server to the client to fetch configuration settings from the client. // // The request can fetch several configuration settings in one roundtrip. // The order of the returned configuration settings correspond to the order of the // passed ConfigurationItems (e.g. the first item in the response is the result for the first configuration item in the params). -func (c *client) WorkspaceConfiguration(ctx context.Context, params *ConfigurationParams) (_ []interface{}, err error) { +func (c *client) Configuration(ctx context.Context, params *ConfigurationParams) (_ []interface{}, err error) { c.logger.Debug("call " + MethodWorkspaceConfiguration) defer c.logger.Debug("end "+MethodWorkspaceConfiguration, zap.Error(err)) diff --git a/client_gojay.go b/client_gojay.go index b785ad32..6f60f6f1 100644 --- a/client_gojay.go +++ b/client_gojay.go @@ -107,7 +107,7 @@ func clientDispatch(ctx context.Context, client Client, reply jsonrpc2.Replier, if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } - resp, err := client.WorkspaceApplyEdit(ctx, ¶ms) + resp, err := client.ApplyEdit(ctx, ¶ms) return true, reply(ctx, resp, err) case MethodWorkspaceConfiguration: // request @@ -117,7 +117,7 @@ func clientDispatch(ctx context.Context, client Client, reply jsonrpc2.Replier, if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } - resp, err := client.WorkspaceConfiguration(ctx, ¶ms) + resp, err := client.Configuration(ctx, ¶ms) return true, reply(ctx, resp, err) case MethodWorkspaceWorkspaceFolders: // request diff --git a/client_json.go b/client_json.go index 8ac494c0..1ff21b3d 100644 --- a/client_json.go +++ b/client_json.go @@ -105,7 +105,7 @@ func clientDispatch(ctx context.Context, client Client, reply jsonrpc2.Replier, if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } - resp, err := client.WorkspaceApplyEdit(ctx, ¶ms) + resp, err := client.ApplyEdit(ctx, ¶ms) return true, reply(ctx, resp, err) case MethodWorkspaceConfiguration: // request @@ -115,7 +115,7 @@ func clientDispatch(ctx context.Context, client Client, reply jsonrpc2.Replier, if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } - resp, err := client.WorkspaceConfiguration(ctx, ¶ms) + resp, err := client.Configuration(ctx, ¶ms) return true, reply(ctx, resp, err) case MethodWorkspaceWorkspaceFolders: // request diff --git a/general.go b/general.go index b6b97a58..86e3b374 100644 --- a/general.go +++ b/general.go @@ -30,13 +30,31 @@ const ( TraceVerbose TraceMode = "verbose" ) +// ClientInfo information about the client. +// +// @since 3.15.0. +type ClientInfo struct { + // Name is the name of the client as defined by the client. + Name string `json:"name"` + + // Version is the client's version as defined by the client. + Version string `json:"version,omitempty"` +} + // InitializeParams params of Initialize Request. type InitializeParams struct { + WorkDoneProgressParams + // ProcessID is the process Id of the parent process that started // the server. Is null if the process has not been started by another process. // If the parent process is not alive then the server should exit (see exit notification) its process. ProcessID float64 `json:"processId"` + // ClientInfo is the information about the client. + // + // @since 3.15.0 + ClientInfo *ClientInfo `json:"clientInfo,omitempty"` + // RootPath is the rootPath of the workspace. Is null // if no folder is open. // @@ -200,6 +218,16 @@ type TextDocumentClientCapabilitiesCompletionItemKind struct { ValueSet []CompletionItemKind `json:"valueSet,omitempty"` } +// TextDocumentClientCapabilitiesCompletionItemTagSupport specific capabilities for the `TagSupport` in the `textDocument/completion` request. +// +// @since 3.15.0. +type TextDocumentClientCapabilitiesCompletionItemTagSupport struct { + // ValueSet is the tags supported by the client. + // + // @since 3.15.0. + ValueSet []CompletionItemTag `json:"valueSet,omitempty"` +} + // TextDocumentClientCapabilitiesCompletionItem is the client supports the following `CompletionItem` specific // capabilities. type TextDocumentClientCapabilitiesCompletionItem struct { @@ -223,6 +251,15 @@ type TextDocumentClientCapabilitiesCompletionItem struct { // PreselectSupport client supports the preselect property on a completion item. PreselectSupport bool `json:"preselectSupport,omitempty"` + + // TagSupport is the client supports the tag property on a completion item. + // + // Clients supporting tags have to handle unknown tags gracefully. + // Clients especially need to preserve unknown tags when sending + // a completion item back to the server in a resolve call. + // + // @since 3.15.0. + TagSupport *TextDocumentClientCapabilitiesCompletionItemTagSupport `json:"tagSupport,omitempty"` } // TextDocumentClientCapabilitiesHover capabilities specific to the `textDocument/hover`. @@ -243,6 +280,13 @@ type TextDocumentClientCapabilitiesSignatureHelp struct { // SignatureInformation is the client supports the following `SignatureInformation` // specific properties. SignatureInformation *TextDocumentClientCapabilitiesSignatureInformation `json:"signatureInformation,omitempty"` + + // ContextSupport is the client supports to send additional context information for a `textDocument/signatureHelp` request. + // + // A client that opts into contextSupport will also support the `retriggerCharacters` on `SignatureHelpOptions`. + // + // @since 3.15.0. + ContextSupport bool `json:"contextSupport,omitempty"` } // TextDocumentClientCapabilitiesSignatureInformation is the client supports the following `SignatureInformation` @@ -265,18 +309,53 @@ type TextDocumentClientCapabilitiesParameterInformation struct { LabelOffsetSupport bool `json:"labelOffsetSupport,omitempty"` } +// ReferencesParams params of References Request. +// +// @since 3.15.0. +type ReferencesParams struct { + TextDocumentPositionParams + WorkDoneProgressParams + PartialResultParams + + // Context is the ReferenceParams context. + Context ReferenceContext `json:"context"` +} + // TextDocumentClientCapabilitiesReferences capabilities specific to the `textDocument/references`. type TextDocumentClientCapabilitiesReferences struct { // DynamicRegistration whether references supports dynamic registration. DynamicRegistration bool `json:"dynamicRegistration,omitempty"` } +// DocumentHighlightOptions registration option of DocumentHighlight server capability. +// +// @since 3.15.0. +type DocumentHighlightOptions struct { + WorkDoneProgressOptions +} + +// DocumentHighlightParams params of DocumentHighlight Request. +// +// @since 3.15.0. +type DocumentHighlightParams struct { + TextDocumentPositionParams + WorkDoneProgressParams + PartialResultParams +} + // TextDocumentClientCapabilitiesDocumentHighlight capabilities specific to the `textDocument/documentHighlight`. type TextDocumentClientCapabilitiesDocumentHighlight struct { // DynamicRegistration Whether document highlight supports dynamic registration. DynamicRegistration bool `json:"dynamicRegistration,omitempty"` } +// DocumentSymbolOptions registration option of DocumentSymbol server capability. +// +// @since 3.15.0. +type DocumentSymbolOptions struct { + WorkDoneProgressOptions +} + // TextDocumentClientCapabilitiesDocumentSymbol capabilities specific to the `textDocument/documentSymbol`. type TextDocumentClientCapabilitiesDocumentSymbol struct { // DynamicRegistration whether document symbol supports dynamic registration. @@ -289,12 +368,33 @@ type TextDocumentClientCapabilitiesDocumentSymbol struct { HierarchicalDocumentSymbolSupport bool `json:"hierarchicalDocumentSymbolSupport,omitempty"` } +// WorkspaceSymbolOptions registration option of WorkspaceSymbol server capability. +// +// @since 3.15.0. +type WorkspaceSymbolOptions struct { + WorkDoneProgressOptions +} + +// DocumentFormattingOptions registration option of DocumentFormatting server capability. +// +// @since 3.15.0. +type DocumentFormattingOptions struct { + WorkDoneProgressOptions +} + // TextDocumentClientCapabilitiesFormatting capabilities specific to the `textDocument/formatting`. type TextDocumentClientCapabilitiesFormatting struct { // DynamicRegistration whether formatting supports dynamic registration. DynamicRegistration bool `json:"dynamicRegistration,omitempty"` } +// DocumentRangeFormattingOptions registration option of DocumentRangeFormatting server capability. +// +// @since 3.15.0. +type DocumentRangeFormattingOptions struct { + WorkDoneProgressOptions +} + // TextDocumentClientCapabilitiesRangeFormatting capabilities specific to the `textDocument/rangeFormatting`. type TextDocumentClientCapabilitiesRangeFormatting struct { // DynamicRegistration whether range formatting supports dynamic registration. @@ -307,6 +407,31 @@ type TextDocumentClientCapabilitiesOnTypeFormatting struct { DynamicRegistration bool `json:"dynamicRegistration,omitempty"` } +// DeclarationOptions registration option of Declaration server capability. +// +// @since 3.15.0. +type DeclarationOptions struct { + WorkDoneProgressOptions +} + +// DeclarationRegistrationOptions registration option of Declaration server capability. +// +// @since 3.15.0. +type DeclarationRegistrationOptions struct { + DeclarationOptions + TextDocumentRegistrationOptions + StaticRegistrationOptions +} + +// DeclarationParams params of Declaration Request. +// +// @since 3.15.0. +type DeclarationParams struct { + TextDocumentPositionParams + WorkDoneProgressParams + PartialResultParams +} + // TextDocumentClientCapabilitiesDeclaration capabilities specific to the `textDocument/declaration`. type TextDocumentClientCapabilitiesDeclaration struct { // DynamicRegistration whether declaration supports dynamic registration. If this is set to `true` @@ -320,6 +445,22 @@ type TextDocumentClientCapabilitiesDeclaration struct { LinkSupport bool `json:"linkSupport,omitempty"` } +// DefinitionOptions registration option of Definition server capability. +// +// @since 3.15.0. +type DefinitionOptions struct { + WorkDoneProgressOptions +} + +// DefinitionParams params of Definition Request. +// +// @since 3.15.0. +type DefinitionParams struct { + TextDocumentPositionParams + WorkDoneProgressParams + PartialResultParams +} + // TextDocumentClientCapabilitiesDefinition capabilities specific to the `textDocument/definition`. // // Since 3.14.0. @@ -331,6 +472,31 @@ type TextDocumentClientCapabilitiesDefinition struct { LinkSupport bool `json:"linkSupport,omitempty"` } +// TypeDefinitionOptions registration option of TypeDefinition server capability. +// +// @since 3.15.0. +type TypeDefinitionOptions struct { + WorkDoneProgressOptions +} + +// TypeDefinitionRegistrationOptions registration option of TypeDefinition server capability. +// +// @since 3.15.0. +type TypeDefinitionRegistrationOptions struct { + TextDocumentRegistrationOptions + TypeDefinitionOptions + StaticRegistrationOptions +} + +// TypeDefinitionParams params of TypeDefinition Request. +// +// @since 3.15.0. +type TypeDefinitionParams struct { + TextDocumentPositionParams + WorkDoneProgressParams + PartialResultParams +} + // TextDocumentClientCapabilitiesTypeDefinition capabilities specific to the `textDocument/typeDefinition` // // Since 3.6.0. @@ -346,6 +512,31 @@ type TextDocumentClientCapabilitiesTypeDefinition struct { LinkSupport bool `json:"linkSupport,omitempty"` } +// ImplementationOptions registration option of Implementation server capability. +// +// @since 3.15.0. +type ImplementationOptions struct { + WorkDoneProgressOptions +} + +// ImplementationRegistrationOptions registration option of Implementation server capability. +// +// @since 3.15.0. +type ImplementationRegistrationOptions struct { + TextDocumentRegistrationOptions + ImplementationOptions + StaticRegistrationOptions +} + +// ImplementationParams params of Implementation Request. +// +// @since 3.15.0. +type ImplementationParams struct { + TextDocumentPositionParams + WorkDoneProgressParams + PartialResultParams +} + // TextDocumentClientCapabilitiesImplementation capabilities specific to the `textDocument/implementation`. // // Since 3.6.0. @@ -365,11 +556,17 @@ type TextDocumentClientCapabilitiesImplementation struct { type TextDocumentClientCapabilitiesCodeAction struct { // DynamicRegistration whether code action supports dynamic registration. DynamicRegistration bool `json:"dynamicRegistration,omitempty"` + // CodeActionLiteralSupport is the client support code action literals as a valid // response of the `textDocument/codeAction` request. // // Since 3.8.0 CodeActionLiteralSupport *TextDocumentClientCapabilitiesCodeActionLiteralSupport `json:"codeActionLiteralSupport,omitempty"` + + // IsPreferredSupport whether code action supports the `isPreferred` property. + // + // @since 3.15.0. + IsPreferredSupport bool `json:"isPreferredSupport,omitempty"` } // TextDocumentClientCapabilitiesCodeActionLiteralSupport is the client support code action literals as a valid response of the `textDocument/codeAction` request. @@ -392,12 +589,38 @@ type TextDocumentClientCapabilitiesCodeActionKind struct { type TextDocumentClientCapabilitiesCodeLens struct { // DynamicRegistration Whether code lens supports dynamic registration. DynamicRegistration bool `json:"dynamicRegistration,omitempty"` + + // TooltipSupport whether the client support the `tooltip` property on `DocumentLink`. + // + // @since 3.15.0. + TooltipSupport bool `json:"tooltipSupport,omitempty"` } // TextDocumentClientCapabilitiesDocumentLink capabilities specific to the `textDocument/documentLink`. type TextDocumentClientCapabilitiesDocumentLink struct { // DynamicRegistration whether document link supports dynamic registration. DynamicRegistration bool `json:"dynamicRegistration,omitempty"` + + // TooltipSupport whether the client supports the `tooltip` property on `DocumentLink`. + // + // @since 3.15.0. + TooltipSupport bool `json:"tooltipSupport,omitempty"` +} + +// DocumentColorOptions registration option of DocumentColor server capability. +// +// @since 3.15.0. +type DocumentColorOptions struct { + WorkDoneProgressOptions +} + +// DocumentColorRegistrationOptions registration option of DocumentColor server capability. +// +// @since 3.15.0. +type DocumentColorRegistrationOptions struct { + TextDocumentRegistrationOptions + StaticRegistrationOptions + DocumentColorOptions } // TextDocumentClientCapabilitiesColorProvider capabilities specific to the `textDocument/documentColor` and the @@ -426,8 +649,40 @@ type TextDocumentClientCapabilitiesPublishDiagnostics struct { // RelatedInformation whether the clients accepts diagnostics with related information. RelatedInformation bool `json:"relatedInformation,omitempty"` - // TagSupport client supports the tag property to provide meta data about a diagnostic. - TagSupport bool `json:"tagSupport,omitempty"` + // TagSupport clients supporting tags have to handle unknown tags gracefully. + // + // @since 3.15.0. + TagSupport *TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport `json:"tagSupport,omitempty"` + + // VersionSupport whether the client interprets the version property of the + // `textDocument/publishDiagnostics` notification`s parameter. + // + // @since 3.15.0. + VersionSupport bool `json:"versionSupport,omitempty"` +} + +// TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport is the client capacity of TagSupport. +// +// @since 3.15.0. +type TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport struct { + // ValueSet is the tags supported by the client. + ValueSet []DiagnosticTag `json:"valueSet"` +} + +// FoldingRangeOptions registration option of FoldingRange server capability. +// +// @since 3.15.0. +type FoldingRangeOptions struct { + WorkDoneProgressOptions +} + +// FoldingRangeRegistrationOptions registration option of FoldingRange server capability. +// +// @since 3.15.0. +type FoldingRangeRegistrationOptions struct { + TextDocumentRegistrationOptions + FoldingRangeOptions + StaticRegistrationOptions } // TextDocumentClientCapabilitiesFoldingRange capabilities specific to `textDocument/foldingRange` requests. @@ -533,9 +788,22 @@ type TextDocumentClientCapabilities struct { FoldingRange *TextDocumentClientCapabilitiesFoldingRange `json:"foldingRange,omitempty"` // SelectionRange capabilities specific to `textDocument/selectionRange` requests. + // + // @since 3.15.0. SelectionRange *TextDocumentClientCapabilitiesSelectionRange `json:"selectionRange,omitempty"` } +// WindowClientCapabilities represents a WindowClientCapabilities specific client capabilities. +// +// @since 3.15.0. +type WindowClientCapabilities struct { + // WorkDoneProgress whether client supports handling progress notifications. If set servers are allowed to + // report in `workDoneProgress` property in the request specific server capabilities. + // + // @since 3.15.0. + WorkDoneProgress bool `json:"workDoneProgress,omitempty"` +} + // ClientCapabilities now define capabilities for dynamic registration, workspace and text document features the client supports. // The experimental can be used to pass experimental capabilities under development. For future compatibility a ClientCapabilities object literal can have more properties set than currently defined. // Servers receiving a ClientCapabilities object literal with unknown properties should ignore these properties. A missing property should be interpreted as an absence of the capability. @@ -547,6 +815,9 @@ type ClientCapabilities struct { // TextDocument specific client capabilities. TextDocument *TextDocumentClientCapabilities `json:"textDocument,omitempty"` + // Window specific client capabilities. + Window *WindowClientCapabilities `json:"window,omitempty"` + // Experimental client capabilities. Experimental interface{} `json:"experimental,omitempty"` } @@ -555,6 +826,22 @@ type ClientCapabilities struct { type InitializeResult struct { // Capabilities is the capabilities the language server provides. Capabilities ServerCapabilities `json:"capabilities"` + + // ServerInfo Information about the server. + // + // @since 3.15.0. + ServerInfo *ServerInfo `json:"serverInfo,omitempty"` +} + +// ServerInfo Information about the server. +// +// @since 3.15.0. +type ServerInfo struct { + // Name is the name of the server as defined by the server. + Name string `json:"name"` + + // Version is the server's version as defined by the server. + Version string `json:"version,omitempty"` } // InitializeError known error codes for an `InitializeError`. @@ -612,6 +899,29 @@ type SignatureHelpOptions struct { // The characters that trigger signature help // automatically. TriggerCharacters []string `json:"triggerCharacters,omitempty"` + + // RetriggerCharacters is the slist of characters that re-trigger signature help. + // + // These trigger characters are only active when signature help is already + // showing. + // All trigger characters are also counted as re-trigger characters. + // + // @since 3.15.0. + RetriggerCharacters []string `json:"retriggerCharacters,omitempty"` +} + +// ReferencesOptions ReferencesProvider options. +// +// @since 3.15.0. +type ReferencesOptions struct { + WorkDoneProgressOptions +} + +// WorkDoneProgressOptions WorkDoneProgress options. +// +// @since 3.15.0. +type WorkDoneProgressOptions struct { + WorkDoneProgress bool `json:"workDoneProgress,omitempty"` } // CodeActionOptions CodeAction options. @@ -675,7 +985,7 @@ type TextDocumentSyncOptions struct { // Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full // and TextDocumentSyncKind.Incremental. If omitted it defaults to TextDocumentSyncKind.None. - Change float64 `json:"change,omitempty"` + Change TextDocumentSyncKind `json:"change,omitempty"` // WillSave notifications are sent to the server. WillSave bool `json:"willSave,omitempty"` @@ -687,6 +997,11 @@ type TextDocumentSyncOptions struct { Save *SaveOptions `json:"save,omitempty"` } +// HoverOptions option of hover provider server capabilities. +type HoverOptions struct { + WorkDoneProgressOptions +} + // StaticRegistrationOptions staticRegistration options to be returned in the initialize request. type StaticRegistrationOptions struct { // ID is the id used to register the request. The id can be used to deregister @@ -720,10 +1035,10 @@ type ServerCapabilitiesWorkspaceFolders struct { type ServerCapabilities struct { // TextDocumentSync defines how text documents are synced. Is either a detailed structure defining each notification or // for backwards compatibility the TextDocumentSyncKind number. If omitted it defaults to `TextDocumentSyncKind.None`. - TextDocumentSync interface{} `json:"textDocumentSync,omitempty"` + TextDocumentSync interface{} `json:"textDocumentSync,omitempty"` // number | *TextDocumentSyncOptions // HoverProvider is the server provides hover support. - HoverProvider bool `json:"hoverProvider,omitempty"` + HoverProvider interface{} `json:"hoverProvider,omitempty"` // TODO(zchee): boolean | *HoverOptions // CompletionProvider is the server provides completion support. CompletionProvider *CompletionOptions `json:"completionProvider,omitempty"` @@ -731,44 +1046,49 @@ type ServerCapabilities struct { // SignatureHelpProvider is the server provides signature help support. SignatureHelpProvider *SignatureHelpOptions `json:"signatureHelpProvider,omitempty"` + // DeclarationProvider is the server provides go to declaration support. + // + // @since 3.14.0. + DeclarationProvider interface{} `json:"declarationProvider,omitempty"` // TODO(zchee): boolean | *DeclarationOptions | *DeclarationRegistrationOptions + // DefinitionProvider is the server provides goto definition support. - DefinitionProvider bool `json:"definitionProvider,omitempty"` + DefinitionProvider interface{} `json:"definitionProvider,omitempty"` // TODO(zchee): boolean | *DefinitionOptions // TypeDefinitionProvider is the server provides Goto Type Definition support. // // Since 3.6.0 - TypeDefinitionProvider interface{} `json:"typeDefinitionProvider,omitempty"` + TypeDefinitionProvider interface{} `json:"typeDefinitionProvider,omitempty"` // TODO(zchee): boolean | *TypeDefinitionOptions | *TypeDefinitionRegistrationOptions // ImplementationProvider is the server provides Goto Implementation support. // // Since 3.6.0 - ImplementationProvider interface{} `json:"implementationProvider,omitempty"` + ImplementationProvider interface{} `json:"implementationProvider,omitempty"` // TODO(zchee): boolean | *ImplementationOptions | *ImplementationRegistrationOptions // ReferencesProvider is the server provides find references support. - ReferencesProvider bool `json:"referencesProvider,omitempty"` + ReferencesProvider interface{} `json:"referencesProvider,omitempty"` // TODO(zchee): boolean | *ReferencesOptions // DocumentHighlightProvider is the server provides document highlight support. - DocumentHighlightProvider bool `json:"documentHighlightProvider,omitempty"` + DocumentHighlightProvider interface{} `json:"documentHighlightProvider,omitempty"` // TODO(zchee): boolean | *DocumentHighlightOptions // DocumentSymbolProvider is the server provides document symbol support. - DocumentSymbolProvider bool `json:"documentSymbolProvider,omitempty"` + DocumentSymbolProvider interface{} `json:"documentSymbolProvider,omitempty"` // TODO(zchee): boolean | *DocumentSymbolOptions // WorkspaceSymbolProvider is the server provides workspace symbol support. - WorkspaceSymbolProvider bool `json:"workspaceSymbolProvider,omitempty"` + WorkspaceSymbolProvider interface{} `json:"workspaceSymbolProvider,omitempty"` // TODO(zchee): boolean | *WorkspaceSymbolOptions // CodeActionProvider is the server provides code actions. The `CodeActionOptions` return type is only // valid if the client signals code action literal support via the property // `textDocument.codeAction.codeActionLiteralSupport`. - CodeActionProvider bool `json:"codeActionProvider,omitempty"` + CodeActionProvider interface{} `json:"codeActionProvider,omitempty"` // TODO(zchee): boolean | *CodeActionOptions // CodeLensProvider is the server provides code lens. CodeLensProvider *CodeLensOptions `json:"codeLensProvider,omitempty"` // DocumentFormattingProvider is the server provides document formatting. - DocumentFormattingProvider bool `json:"documentFormattingProvider,omitempty"` + DocumentFormattingProvider interface{} `json:"documentFormattingProvider,omitempty"` // TODO(zchee): boolean | *DocumentFormattingOptions // DocumentRangeFormattingProvider is the server provides document range formatting. - DocumentRangeFormattingProvider bool `json:"documentRangeFormattingProvider,omitempty"` + DocumentRangeFormattingProvider interface{} `json:"documentRangeFormattingProvider,omitempty"` // TODO(zchee): boolean | *DocumentRangeFormattingOptions // DocumentOnTypeFormattingProvider is the server provides document formatting on typing. DocumentOnTypeFormattingProvider *DocumentOnTypeFormattingOptions `json:"documentOnTypeFormattingProvider,omitempty"` @@ -776,7 +1096,7 @@ type ServerCapabilities struct { // RenameProvider is the server provides rename support. RenameOptions may only be // specified if the client states that it supports // `prepareSupport` in its initial `initialize` request. - RenameProvider interface{} `json:"renameProvider,omitempty"` // boolean | RenameOptions + RenameProvider interface{} `json:"renameProvider,omitempty"` // TODO(zchee): boolean | *RenameOptions // The server provides document link support. DocumentLinkProvider *DocumentLinkOptions `json:"documentLinkProvider,omitempty"` @@ -784,15 +1104,17 @@ type ServerCapabilities struct { // ColorProvider is the server provides color provider support. // // Since 3.6.0 - ColorProvider interface{} `json:"colorProvider,omitempty"` + ColorProvider interface{} `json:"colorProvider,omitempty"` // TODO(zchee): boolean | *DocumentColorOptions | *DocumentColorRegistrationOptions // FoldingRangeProvider is the server provides folding provider support. // // Since 3.10.0 - FoldingRangeProvider interface{} `json:"foldingRangeProvider,omitempty"` + FoldingRangeProvider interface{} `json:"foldingRangeProvider,omitempty"` // TODO(zchee): boolean | *FoldingRangeOptions | *FoldingRangeRegistrationOptions // SelectionRangeProvider is the server provides selection range support. - SelectionRangeProvider interface{} `json:"selectionRangeProvider,omitempty"` // boolean || (TextDocumentRegistrationOptions || StaticRegistrationOptions || SelectionRangeProviderOptions) + // + // @since 3.15.0. + SelectionRangeProvider interface{} `json:"selectionRangeProvider,omitempty"` // TODO(zchee): boolean | *EnableSelectionRange | *SelectionRangeOptions | *SelectionRangeRegistrationOptions // ExecuteCommandProvider is the server provides execute command support. ExecuteCommandProvider *ExecuteCommandOptions `json:"executeCommandProvider,omitempty"` diff --git a/general_gojay.go b/general_gojay.go index 85c178d3..e16f579e 100644 --- a/general_gojay.go +++ b/general_gojay.go @@ -6,7 +6,34 @@ package protocol -import "github.com/francoispqt/gojay" +import ( + "github.com/francoispqt/gojay" +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *CancelParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.AddInterfaceKey(keyID, v.ID) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *CancelParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *CancelParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyID { + return dec.Interface(&v.ID) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *CancelParams) NKeys() int { return 1 } + +// compile time check whether the CancelParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*CancelParams)(nil) + _ gojay.UnmarshalerJSONObject = (*CancelParams)(nil) +) // MarshalJSONArray implements gojay.MarshalerJSONArray. func (v WorkspaceFolders) MarshalJSONArray(enc *gojay.Encoder) { @@ -34,9 +61,40 @@ var ( _ gojay.UnmarshalerJSONArray = (*WorkspaceFolders)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *ClientInfo) MarshalJSONObject(enc *gojay.Encoder) { + enc.StringKey(keyName, v.Name) + enc.StringKeyOmitEmpty(keyVersion, v.Version) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *ClientInfo) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ClientInfo) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyName: + return dec.String(&v.Name) + case keyVersion: + return dec.String(&v.Version) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ClientInfo) NKeys() int { return 2 } + +// compile time check whether the ClientInfo implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*ClientInfo)(nil) + _ gojay.UnmarshalerJSONObject = (*ClientInfo)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *InitializeParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) enc.Float64Key(keyProcessID, v.ProcessID) + enc.ObjectKeyOmitEmpty(keyClientInfo, v.ClientInfo) enc.StringKeyOmitEmpty(keyRootPath, v.RootPath) enc.StringKey(keyRootURI, string(v.RootURI)) enc.AddInterfaceKey(keyInitializationOptions, v.InitializationOptions) @@ -51,8 +109,15 @@ func (v *InitializeParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *InitializeParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) case keyProcessID: return dec.Float64(&v.ProcessID) + case keyClientInfo: + if v.ClientInfo == nil { + v.ClientInfo = &ClientInfo{} + } + return dec.Object(v.ClientInfo) case keyRootPath: return dec.String(&v.RootPath) case keyRootURI: @@ -64,18 +129,13 @@ func (v *InitializeParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) err case keyTrace: return dec.String((*string)(&v.Trace)) case keyWorkspaceFolders: - var values WorkspaceFolders - err := dec.Array(&values) - if err == nil && len(values) > 0 { - v.WorkspaceFolders = []WorkspaceFolder(values) - } - return err + return dec.Array((*WorkspaceFolders)(&v.WorkspaceFolders)) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *InitializeParams) NKeys() int { return 7 } +func (v *InitializeParams) NKeys() int { return 9 } // compile time check whether the InitializeParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -473,6 +533,31 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesCompletionItemKind)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesCompletionItemTagSupport) MarshalJSONObject(enc *gojay.Encoder) { + enc.ArrayKey(keyValueSet, (*CompletionItemTags)(&v.ValueSet)) +} + +// IsNil returns wether the structure is nil value or not. +func (v *TextDocumentClientCapabilitiesCompletionItemTagSupport) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesCompletionItemTagSupport) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyValueSet { + return dec.Array((*CompletionItemTags)(&v.ValueSet)) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *TextDocumentClientCapabilitiesCompletionItemTagSupport) NKeys() int { return 1 } + +// compile time check whether the TextDocumentClientCapabilitiesCompletionItemTagSupport implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesCompletionItemTagSupport)(nil) + _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesCompletionItemTagSupport)(nil) +) + // MarkupKinds represents a slice of MarkupKind. type MarkupKinds []MarkupKind @@ -509,6 +594,7 @@ func (v *TextDocumentClientCapabilitiesCompletionItem) MarshalJSONObject(enc *go enc.ArrayKeyOmitEmpty(keyDocumentationFormat, (*MarkupKinds)(&v.DocumentationFormat)) enc.BoolKeyOmitEmpty(keyDeprecatedSupport, v.DeprecatedSupport) enc.BoolKeyOmitEmpty(keyPreselectSupport, v.PreselectSupport) + enc.ObjectKeyOmitEmpty(keyTagSupport, v.TagSupport) } // IsNil returns wether the structure is nil value or not. @@ -527,12 +613,17 @@ func (v *TextDocumentClientCapabilitiesCompletionItem) UnmarshalJSONObject(dec * return dec.Bool(&v.DeprecatedSupport) case keyPreselectSupport: return dec.Bool(&v.PreselectSupport) + case keyTagSupport: + if v.TagSupport == nil { + v.TagSupport = &TextDocumentClientCapabilitiesCompletionItemTagSupport{} + } + return dec.Object(v.TagSupport) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesCompletionItem) NKeys() int { return 5 } +func (v *TextDocumentClientCapabilitiesCompletionItem) NKeys() int { return 6 } // compile time check whether the TextDocumentClientCapabilitiesCompletionItem implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -573,6 +664,7 @@ var ( func (v *TextDocumentClientCapabilitiesSignatureHelp) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) enc.ObjectKeyOmitEmpty(keySignatureInformation, v.SignatureInformation) + enc.BoolKeyOmitEmpty(keyContextSupport, v.ContextSupport) } // IsNil returns wether the structure is nil value or not. @@ -588,12 +680,14 @@ func (v *TextDocumentClientCapabilitiesSignatureHelp) UnmarshalJSONObject(dec *g v.SignatureInformation = &TextDocumentClientCapabilitiesSignatureInformation{} } return dec.Object(v.SignatureInformation) + case keyContextSupport: + return dec.Bool(&v.ContextSupport) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesSignatureHelp) NKeys() int { return 2 } +func (v *TextDocumentClientCapabilitiesSignatureHelp) NKeys() int { return 3 } // compile time check whether the TextDocumentClientCapabilitiesSignatureHelp implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -611,14 +705,17 @@ func (v *TextDocumentClientCapabilitiesSignatureInformation) IsNil() bool { retu // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *TextDocumentClientCapabilitiesSignatureInformation) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyDocumentationFormat { + switch k { + case keyDocumentationFormat: return dec.Array((*MarkupKinds)(&v.DocumentationFormat)) + case keyParameterInformation: + return dec.Object(v.ParameterInformation) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesSignatureInformation) NKeys() int { return 1 } +func (v *TextDocumentClientCapabilitiesSignatureInformation) NKeys() int { return 2 } // compile time check whether the TextDocumentClientCapabilitiesSignatureInformation implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -626,6 +723,69 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesSignatureInformation)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesParameterInformation) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyLabelOffsetSupport, v.LabelOffsetSupport) +} + +// IsNil returns wether the structure is nil value or not. +func (v *TextDocumentClientCapabilitiesParameterInformation) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesParameterInformation) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyLabelOffsetSupport { + return dec.Bool(&v.LabelOffsetSupport) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *TextDocumentClientCapabilitiesParameterInformation) NKeys() int { return 1 } + +// compile time check whether the TextDocumentClientCapabilitiesSignatureInformation implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesParameterInformation)(nil) + _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesParameterInformation)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *ReferencesParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) + enc.ObjectKeyOmitEmpty(keyContext, &v.Context) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *ReferencesParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ReferencesParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + case keyContext: + return dec.Object(&v.Context) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ReferencesParams) NKeys() int { return 5 } + +// compile time check whether the ReferencesParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*ReferencesParams)(nil) + _ gojay.UnmarshalerJSONObject = (*ReferencesParams)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesReferences) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) @@ -651,6 +811,66 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesReferences)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DocumentHighlightOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil returns wether the structure is nil value or not. +func (v *DocumentHighlightOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *DocumentHighlightOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *DocumentHighlightOptions) NKeys() int { return 1 } + +// compile time check whether the DocumentHighlightOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DocumentHighlightOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DocumentHighlightOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DocumentHighlightParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DocumentHighlightParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DocumentHighlightParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DocumentHighlightParams) NKeys() int { return 4 } + +// compile time check whether the DocumentHighlightParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DocumentHighlightParams)(nil) + _ gojay.UnmarshalerJSONObject = (*DocumentHighlightParams)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesDocumentHighlight) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) @@ -676,6 +896,31 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesDocumentHighlight)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DocumentSymbolOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DocumentSymbolOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DocumentSymbolOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DocumentSymbolOptions) NKeys() int { return 1 } + +// compile time check whether the DocumentSymbolOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DocumentSymbolOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DocumentSymbolOptions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesDocumentSymbol) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) @@ -711,6 +956,56 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesDocumentSymbol)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WorkspaceSymbolOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WorkspaceSymbolOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WorkspaceSymbolOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WorkspaceSymbolOptions) NKeys() int { return 1 } + +// compile time check whether the WorkspaceSymbolOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WorkspaceSymbolOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*WorkspaceSymbolOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DocumentFormattingOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil returns wether the structure is nil value or not. +func (v *DocumentFormattingOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *DocumentFormattingOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *DocumentFormattingOptions) NKeys() int { return 1 } + +// compile time check whether the DocumentFormattingOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DocumentFormattingOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DocumentFormattingOptions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesFormatting) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) @@ -736,6 +1031,31 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesFormatting)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DocumentRangeFormattingOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil returns wether the structure is nil value or not. +func (v *DocumentRangeFormattingOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *DocumentRangeFormattingOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *DocumentRangeFormattingOptions) NKeys() int { return 1 } + +// compile time check whether the DocumentRangeFormattingOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DocumentRangeFormattingOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DocumentRangeFormattingOptions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesRangeFormatting) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) @@ -777,26 +1097,334 @@ func (v *TextDocumentClientCapabilitiesOnTypeFormatting) UnmarshalJSONObject(dec return nil } -// NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesOnTypeFormatting) NKeys() int { return 1 } +// NKeys returns the number of keys to unmarshal. +func (v *TextDocumentClientCapabilitiesOnTypeFormatting) NKeys() int { return 1 } + +// compile time check whether the TextDocumentClientCapabilitiesOnTypeFormatting implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesOnTypeFormatting)(nil) + _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesOnTypeFormatting)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DeclarationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DeclarationOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DeclarationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DeclarationOptions) NKeys() int { return 1 } + +// compile time check whether the DeclarationOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DeclarationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DeclarationOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DeclarationRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) + enc.AddArrayKey(keyDocumentSelector, &v.DocumentSelector) + enc.StringKeyOmitEmpty(keyID, v.ID) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DeclarationRegistrationOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DeclarationRegistrationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyWorkDoneProgress: + return dec.Bool(&v.WorkDoneProgress) + case keyDocumentSelector: + if v.DocumentSelector == nil { + v.DocumentSelector = DocumentSelector{} + } + return dec.Array(&v.DocumentSelector) + case keyID: + return dec.String(&v.ID) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DeclarationRegistrationOptions) NKeys() int { return 3 } + +// compile time check whether the DeclarationOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DeclarationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DeclarationOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DeclarationParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DeclarationParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DeclarationParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DeclarationParams) NKeys() int { return 4 } + +// compile time check whether the DeclarationParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DeclarationParams)(nil) + _ gojay.UnmarshalerJSONObject = (*DeclarationParams)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesDeclaration) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) + enc.BoolKeyOmitEmpty(keyLinkSupport, v.LinkSupport) +} + +// IsNil returns wether the structure is nil value or not. +func (v *TextDocumentClientCapabilitiesDeclaration) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesDeclaration) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyDynamicRegistration: + return dec.Bool(&v.DynamicRegistration) + case keyLinkSupport: + return dec.Bool(&v.LinkSupport) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *TextDocumentClientCapabilitiesDeclaration) NKeys() int { return 2 } + +// compile time check whether the TextDocumentClientCapabilitiesDeclaration implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesDeclaration)(nil) + _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesDeclaration)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DefinitionOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DefinitionOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DefinitionOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DefinitionOptions) NKeys() int { return 1 } + +// compile time check whether the DefinitionOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DefinitionOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DefinitionOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DefinitionParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DefinitionParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DefinitionParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DefinitionParams) NKeys() int { return 4 } + +// compile time check whether the DefinitionParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DefinitionParams)(nil) + _ gojay.UnmarshalerJSONObject = (*DefinitionParams)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesDefinition) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) + enc.BoolKeyOmitEmpty(keyLinkSupport, v.LinkSupport) +} + +// IsNil returns wether the structure is nil value or not. +func (v *TextDocumentClientCapabilitiesDefinition) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesDefinition) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyDynamicRegistration: + return dec.Bool(&v.DynamicRegistration) + case keyLinkSupport: + return dec.Bool(&v.LinkSupport) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *TextDocumentClientCapabilitiesDefinition) NKeys() int { return 2 } + +// compile time check whether the TextDocumentClientCapabilitiesDefinition implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesDefinition)(nil) + _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesDefinition)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TypeDefinitionOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *TypeDefinitionOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *TypeDefinitionOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *TypeDefinitionOptions) NKeys() int { return 1 } + +// compile time check whether the TypeDefinitionOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TypeDefinitionOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*TypeDefinitionOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TypeDefinitionRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.AddArrayKey(keyDocumentSelector, &v.DocumentSelector) + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) + enc.StringKeyOmitEmpty(keyID, v.ID) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *TypeDefinitionRegistrationOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *TypeDefinitionRegistrationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyWorkDoneProgress: + return dec.Bool(&v.WorkDoneProgress) + case keyDocumentSelector: + if v.DocumentSelector == nil { + v.DocumentSelector = DocumentSelector{} + } + return dec.Array(&v.DocumentSelector) + case keyID: + return dec.String(&v.ID) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *TypeDefinitionRegistrationOptions) NKeys() int { return 3 } + +// compile time check whether the TypeDefinitionRegistrationOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TypeDefinitionRegistrationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*TypeDefinitionRegistrationOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TypeDefinitionParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *TypeDefinitionParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *TypeDefinitionParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *TypeDefinitionParams) NKeys() int { return 4 } -// compile time check whether the TextDocumentClientCapabilitiesOnTypeFormatting implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +// compile time check whether the TypeDefinitionParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( - _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesOnTypeFormatting)(nil) - _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesOnTypeFormatting)(nil) + _ gojay.MarshalerJSONObject = (*TypeDefinitionParams)(nil) + _ gojay.UnmarshalerJSONObject = (*TypeDefinitionParams)(nil) ) // MarshalJSONObject implements gojay.MarshalerJSONObject. -func (v *TextDocumentClientCapabilitiesDeclaration) MarshalJSONObject(enc *gojay.Encoder) { +func (v *TextDocumentClientCapabilitiesTypeDefinition) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) enc.BoolKeyOmitEmpty(keyLinkSupport, v.LinkSupport) } // IsNil returns wether the structure is nil value or not. -func (v *TextDocumentClientCapabilitiesDeclaration) IsNil() bool { return v == nil } +func (v *TextDocumentClientCapabilitiesTypeDefinition) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. -func (v *TextDocumentClientCapabilitiesDeclaration) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { +func (v *TextDocumentClientCapabilitiesTypeDefinition) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { case keyDynamicRegistration: return dec.Bool(&v.DynamicRegistration) @@ -807,70 +1435,107 @@ func (v *TextDocumentClientCapabilitiesDeclaration) UnmarshalJSONObject(dec *goj } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesDeclaration) NKeys() int { return 2 } +func (v *TextDocumentClientCapabilitiesTypeDefinition) NKeys() int { return 2 } -// compile time check whether the TextDocumentClientCapabilitiesDeclaration implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +// compile time check whether the TextDocumentClientCapabilitiesTypeDefinition implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( - _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesDeclaration)(nil) - _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesDeclaration)(nil) + _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesTypeDefinition)(nil) + _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesTypeDefinition)(nil) ) // MarshalJSONObject implements gojay.MarshalerJSONObject. -func (v *TextDocumentClientCapabilitiesDefinition) MarshalJSONObject(enc *gojay.Encoder) { - enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) - enc.BoolKeyOmitEmpty(keyLinkSupport, v.LinkSupport) +func (v *ImplementationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) } -// IsNil returns wether the structure is nil value or not. -func (v *TextDocumentClientCapabilitiesDefinition) IsNil() bool { return v == nil } +// IsNil implements gojay.MarshalerJSONObject. +func (v *ImplementationOptions) IsNil() bool { return v == nil } -// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. -func (v *TextDocumentClientCapabilitiesDefinition) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ImplementationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ImplementationOptions) NKeys() int { return 1 } + +// compile time check whether the ImplementationOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*ImplementationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*ImplementationOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *ImplementationRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) + enc.AddArrayKey(keyDocumentSelector, &v.DocumentSelector) + enc.StringKeyOmitEmpty(keyID, v.ID) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *ImplementationRegistrationOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ImplementationRegistrationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { - case keyDynamicRegistration: - return dec.Bool(&v.DynamicRegistration) - case keyLinkSupport: - return dec.Bool(&v.LinkSupport) + case keyWorkDoneProgress: + return dec.Bool(&v.WorkDoneProgress) + case keyDocumentSelector: + if v.DocumentSelector == nil { + v.DocumentSelector = DocumentSelector{} + } + return dec.Array(&v.DocumentSelector) + case keyID: + return dec.String(&v.ID) } return nil } -// NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesDefinition) NKeys() int { return 2 } +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ImplementationRegistrationOptions) NKeys() int { return 3 } -// compile time check whether the TextDocumentClientCapabilitiesDefinition implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +// compile time check whether the ImplementationRegistrationOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( - _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesDefinition)(nil) - _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesDefinition)(nil) + _ gojay.MarshalerJSONObject = (*ImplementationRegistrationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*ImplementationRegistrationOptions)(nil) ) // MarshalJSONObject implements gojay.MarshalerJSONObject. -func (v *TextDocumentClientCapabilitiesTypeDefinition) MarshalJSONObject(enc *gojay.Encoder) { - enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) - enc.BoolKeyOmitEmpty(keyLinkSupport, v.LinkSupport) +func (v *ImplementationParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) } -// IsNil returns wether the structure is nil value or not. -func (v *TextDocumentClientCapabilitiesTypeDefinition) IsNil() bool { return v == nil } +// IsNil implements gojay.MarshalerJSONObject. +func (v *ImplementationParams) IsNil() bool { return v == nil } -// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. -func (v *TextDocumentClientCapabilitiesTypeDefinition) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ImplementationParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { - case keyDynamicRegistration: - return dec.Bool(&v.DynamicRegistration) - case keyLinkSupport: - return dec.Bool(&v.LinkSupport) + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) } return nil } -// NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesTypeDefinition) NKeys() int { return 2 } +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ImplementationParams) NKeys() int { return 4 } -// compile time check whether the TextDocumentClientCapabilitiesTypeDefinition implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +// compile time check whether the ImplementationParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( - _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesTypeDefinition)(nil) - _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesTypeDefinition)(nil) + _ gojay.MarshalerJSONObject = (*ImplementationParams)(nil) + _ gojay.UnmarshalerJSONObject = (*ImplementationParams)(nil) ) // MarshalJSONObject implements gojay.MarshalerJSONObject. @@ -906,6 +1571,7 @@ var ( func (v *TextDocumentClientCapabilitiesCodeAction) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) enc.ObjectKeyOmitEmpty(keyCodeActionLiteralSupport, v.CodeActionLiteralSupport) + enc.BoolKeyOmitEmpty(keyIsPreferredSupport, v.IsPreferredSupport) } // IsNil returns wether the structure is nil value or not. @@ -921,12 +1587,14 @@ func (v *TextDocumentClientCapabilitiesCodeAction) UnmarshalJSONObject(dec *goja v.CodeActionLiteralSupport = &TextDocumentClientCapabilitiesCodeActionLiteralSupport{} } return dec.Object(v.CodeActionLiteralSupport) + case keyIsPreferredSupport: + return dec.Bool(&v.IsPreferredSupport) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesCodeAction) NKeys() int { return 2 } +func (v *TextDocumentClientCapabilitiesCodeAction) NKeys() int { return 3 } // compile time check whether the TextDocumentClientCapabilitiesCodeAction implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1016,9 +1684,98 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesCodeActionKind)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport) MarshalJSONObject(enc *gojay.Encoder) { + enc.ArrayKeyOmitEmpty(keyValueSet, (*DiagnosticTags)(&v.ValueSet)) +} + +// IsNil returns wether the structure is nil value or not. +func (v *TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. +func (v *TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyValueSet { + if v.ValueSet == nil { + v.ValueSet = []DiagnosticTag{} + } + return dec.Array((*DiagnosticTags)(&v.ValueSet)) + } + return nil +} + +// NKeys returns the number of keys to unmarshal. +func (v *TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport) NKeys() int { return 1 } + +// compile time check whether the TextDocumentClientCapabilitiesCodeActionKind implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport)(nil) + _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *FoldingRangeOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *FoldingRangeOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *FoldingRangeOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *FoldingRangeOptions) NKeys() int { return 1 } + +// compile time check whether the FoldingRangeOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*FoldingRangeOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*FoldingRangeOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *FoldingRangeRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.AddArrayKey(keyDocumentSelector, &v.DocumentSelector) + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) + enc.StringKeyOmitEmpty(keyID, v.ID) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *FoldingRangeRegistrationOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *FoldingRangeRegistrationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyDocumentSelector: + if v.DocumentSelector == nil { + v.DocumentSelector = DocumentSelector{} + } + return dec.Array(&v.DocumentSelector) + case keyWorkDoneProgress: + return dec.Bool(&v.WorkDoneProgress) + case keyID: + return dec.String(&v.ID) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *FoldingRangeRegistrationOptions) NKeys() int { return 4 } + +// compile time check whether the FoldingRangeRegistrationOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*FoldingRangeRegistrationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*FoldingRangeRegistrationOptions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesCodeLens) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) + enc.BoolKeyOmitEmpty(keyTooltipSupport, v.TooltipSupport) } // IsNil returns wether the structure is nil value or not. @@ -1026,14 +1783,17 @@ func (v *TextDocumentClientCapabilitiesCodeLens) IsNil() bool { return v == nil // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *TextDocumentClientCapabilitiesCodeLens) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyDynamicRegistration { + switch k { + case keyDynamicRegistration: return dec.Bool(&v.DynamicRegistration) + case keyTooltipSupport: + return dec.Bool(&v.TooltipSupport) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesCodeLens) NKeys() int { return 1 } +func (v *TextDocumentClientCapabilitiesCodeLens) NKeys() int { return 2 } // compile time check whether the TextDocumentClientCapabilitiesCodeLens implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1044,6 +1804,7 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesDocumentLink) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) + enc.BoolKeyOmitEmpty(keyTooltipSupport, v.TooltipSupport) } // IsNil returns wether the structure is nil value or not. @@ -1051,14 +1812,17 @@ func (v *TextDocumentClientCapabilitiesDocumentLink) IsNil() bool { return v == // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *TextDocumentClientCapabilitiesDocumentLink) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyDynamicRegistration { + switch k { + case keyDynamicRegistration: return dec.Bool(&v.DynamicRegistration) + case keyTooltipSupport: + return dec.Bool(&v.TooltipSupport) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesDocumentLink) NKeys() int { return 1 } +func (v *TextDocumentClientCapabilitiesDocumentLink) NKeys() int { return 2 } // compile time check whether the TextDocumentClientCapabilitiesDocumentLink implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1066,6 +1830,66 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilitiesDocumentLink)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DocumentColorOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DocumentColorOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DocumentColorOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DocumentColorOptions) NKeys() int { return 1 } + +// compile time check whether the DocumentColorOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DocumentColorOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DocumentColorOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *DocumentColorRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.AddArrayKey(keyDocumentSelector, &v.DocumentSelector) + enc.StringKeyOmitEmpty(keyID, v.ID) + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *DocumentColorRegistrationOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *DocumentColorRegistrationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyDocumentSelector: + if v.DocumentSelector == nil { + v.DocumentSelector = DocumentSelector{} + } + return dec.Array(&v.DocumentSelector) + case keyID: + return dec.String(&v.ID) + case keyWorkDoneProgress: + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *DocumentColorRegistrationOptions) NKeys() int { return 4 } + +// compile time check whether the DocumentColorRegistrationOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*DocumentColorRegistrationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*DocumentColorRegistrationOptions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesColorProvider) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyDynamicRegistration, v.DynamicRegistration) @@ -1123,7 +1947,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentClientCapabilitiesPublishDiagnostics) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyRelatedInformation, v.RelatedInformation) - enc.BoolKeyOmitEmpty(keyTagSupport, v.TagSupport) + enc.ObjectKeyOmitEmpty(keyTagSupport, v.TagSupport) + enc.BoolKeyOmitEmpty(keyVersionSupport, v.VersionSupport) } // IsNil returns wether the structure is nil value or not. @@ -1135,13 +1960,18 @@ func (v *TextDocumentClientCapabilitiesPublishDiagnostics) UnmarshalJSONObject(d case keyRelatedInformation: return dec.Bool(&v.RelatedInformation) case keyTagSupport: - return dec.Bool(&v.TagSupport) + if v.TagSupport == nil { + v.TagSupport = &TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport{} + } + return dec.Object(v.TagSupport) + case keyVersionSupport: + return dec.Bool(&v.VersionSupport) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *TextDocumentClientCapabilitiesPublishDiagnostics) NKeys() int { return 2 } +func (v *TextDocumentClientCapabilitiesPublishDiagnostics) NKeys() int { return 3 } // compile time check whether the TextDocumentClientCapabilitiesPublishDiagnostics implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1362,10 +2192,36 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentClientCapabilities)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WindowClientCapabilities) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WindowClientCapabilities) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WindowClientCapabilities) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WindowClientCapabilities) NKeys() int { return 1 } + +// compile time check whether the WindowClientCapabilities implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WindowClientCapabilities)(nil) + _ gojay.UnmarshalerJSONObject = (*WindowClientCapabilities)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *ClientCapabilities) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKeyOmitEmpty(keyWorkspace, v.Workspace) enc.ObjectKeyOmitEmpty(keyTextDocument, v.TextDocument) + enc.ObjectKeyOmitEmpty(keyWindow, v.Window) enc.AddInterfaceKeyOmitEmpty(keyExperimental, v.Experimental) } @@ -1385,6 +2241,11 @@ func (v *ClientCapabilities) UnmarshalJSONObject(dec *gojay.Decoder, k string) e v.TextDocument = &TextDocumentClientCapabilities{} } return dec.Object(v.TextDocument) + case keyWindow: + if v.Window == nil { + v.Window = &WindowClientCapabilities{} + } + return dec.Object(v.Window) case keyExperimental: return dec.Interface(&v.Experimental) } @@ -1392,7 +2253,7 @@ func (v *ClientCapabilities) UnmarshalJSONObject(dec *gojay.Decoder, k string) e } // NKeys returns the number of keys to unmarshal. -func (v *ClientCapabilities) NKeys() int { return 3 } +func (v *ClientCapabilities) NKeys() int { return 4 } // compile time check whether the ClientCapabilities implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1403,6 +2264,7 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *InitializeResult) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyCapabilities, &v.Capabilities) + enc.ObjectKeyOmitEmpty(keyServerInfo, v.ServerInfo) } // IsNil returns wether the structure is nil value or not. @@ -1410,14 +2272,20 @@ func (v *InitializeResult) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *InitializeResult) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyCapabilities { + switch k { + case keyCapabilities: return dec.Object(&v.Capabilities) + case keyServerInfo: + if v.ServerInfo == nil { + v.ServerInfo = &ServerInfo{} + } + return dec.Object(v.ServerInfo) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *InitializeResult) NKeys() int { return 1 } +func (v *InitializeResult) NKeys() int { return 2 } // compile time check whether the InitializeResult implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1425,6 +2293,35 @@ var ( _ gojay.UnmarshalerJSONObject = (*InitializeResult)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *ServerInfo) MarshalJSONObject(enc *gojay.Encoder) { + enc.StringKey(keyName, v.Name) + enc.StringKeyOmitEmpty(keyVersion, v.Version) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *ServerInfo) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ServerInfo) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyName: + return dec.String(&v.Name) + case keyVersion: + return dec.String(&v.Version) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ServerInfo) NKeys() int { return 2 } + +// compile time check whether the ServerInfo implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*ServerInfo)(nil) + _ gojay.UnmarshalerJSONObject = (*ServerInfo)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *InitializeError) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyRetry, v.Retry) @@ -1485,6 +2382,7 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *SignatureHelpOptions) MarshalJSONObject(enc *gojay.Encoder) { enc.ArrayKeyOmitEmpty(keyTriggerCharacters, (*Strings)(&v.TriggerCharacters)) + enc.ArrayKeyOmitEmpty(keyRetriggerCharacters, (*Strings)(&v.RetriggerCharacters)) } // IsNil returns wether the structure is nil value or not. @@ -1492,19 +2390,22 @@ func (v *SignatureHelpOptions) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *SignatureHelpOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyTriggerCharacters { + switch k { + case keyTriggerCharacters: var values Strings err := dec.Array(&values) if err == nil && len(values) > 0 { v.TriggerCharacters = []string(values) } return err + case keyRetriggerCharacters: + return dec.Array((*Strings)(&v.RetriggerCharacters)) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *SignatureHelpOptions) NKeys() int { return 1 } +func (v *SignatureHelpOptions) NKeys() int { return 2 } // compile time check whether the SignatureHelpOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1512,6 +2413,31 @@ var ( _ gojay.UnmarshalerJSONObject = (*SignatureHelpOptions)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *ReferencesOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *ReferencesOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ReferencesOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ReferencesOptions) NKeys() int { return 1 } + +// compile time check whether the ReferencesOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*ReferencesOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*ReferencesOptions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *CodeActionOptions) MarshalJSONObject(enc *gojay.Encoder) { enc.ArrayKeyOmitEmpty(keyCodeActionKinds, (*CodeActionKinds)(&v.CodeActionKinds)) @@ -1739,7 +2665,7 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *TextDocumentSyncOptions) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKeyOmitEmpty(keyOpenClose, v.OpenClose) - enc.Float64KeyOmitEmpty(keyChange, v.Change) + enc.Float64KeyOmitEmpty(keyChange, float64(v.Change)) enc.BoolKeyOmitEmpty(keyWillSave, v.WillSave) enc.BoolKeyOmitEmpty(keyWillSaveWaitUntil, v.WillSaveWaitUntil) enc.ObjectKeyOmitEmpty(keySave, v.Save) @@ -1754,7 +2680,7 @@ func (v *TextDocumentSyncOptions) UnmarshalJSONObject(dec *gojay.Decoder, k stri case keyOpenClose: return dec.Bool(&v.OpenClose) case keyChange: - return dec.Float64(&v.Change) + return dec.Float64((*float64)(&v.Change)) case keyWillSave: return dec.Bool(&v.WillSave) case keyWillSaveWaitUntil: @@ -1774,6 +2700,31 @@ var ( _ gojay.UnmarshalerJSONObject = (*TextDocumentSyncOptions)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *HoverOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *HoverOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *HoverOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *HoverOptions) NKeys() int { return 1 } + +// compile time check whether the HoverOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*HoverOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*HoverOptions)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *StaticRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { enc.StringKeyOmitEmpty(keyID, v.ID) @@ -1857,28 +2808,148 @@ var ( ) // MarshalJSONObject implements gojay.MarshalerJSONObject. +//nolint:funlen,gocritic // TODO(zchee): fix gocritic:typeSwitchVar func (v *ServerCapabilities) MarshalJSONObject(enc *gojay.Encoder) { - enc.AddInterfaceKeyOmitEmpty(keyTextDocumentSync, v.TextDocumentSync) - enc.BoolKeyOmitEmpty(keyHoverProvider, v.HoverProvider) + switch v.TextDocumentSync.(type) { + case float64: + enc.Float64Key(keyTextDocumentSync, v.TextDocumentSync.(float64)) + case *TextDocumentSyncOptions: + enc.ObjectKey(keyTextDocumentSync, v.TextDocumentSync.(*TextDocumentSyncOptions)) + } + + switch v.HoverProvider.(type) { + case bool: + enc.BoolKey(keyHoverProvider, v.HoverProvider.(bool)) + case *HoverOptions: + enc.ObjectKey(keyHoverProvider, v.HoverProvider.(*HoverOptions)) + } + enc.ObjectKeyOmitEmpty(keyCompletionProvider, v.CompletionProvider) enc.ObjectKeyOmitEmpty(keySignatureHelpProvider, v.SignatureHelpProvider) - enc.BoolKeyOmitEmpty(keyDefinitionProvider, v.DefinitionProvider) - enc.AddInterfaceKeyOmitEmpty(keyTypeDefinitionProvider, v.TypeDefinitionProvider) - enc.AddInterfaceKeyOmitEmpty(keyImplementationProvider, v.ImplementationProvider) - enc.BoolKeyOmitEmpty(keyReferencesProvider, v.ReferencesProvider) - enc.BoolKeyOmitEmpty(keyDocumentHighlightProvider, v.DocumentHighlightProvider) - enc.BoolKeyOmitEmpty(keyDocumentSymbolProvider, v.DocumentSymbolProvider) - enc.BoolKeyOmitEmpty(keyWorkspaceSymbolProvider, v.WorkspaceSymbolProvider) - enc.BoolKeyOmitEmpty(keyCodeActionProvider, v.CodeActionProvider) + + switch v.DeclarationProvider.(type) { + case bool: + enc.BoolKey(keyDeclarationProvider, v.DeclarationProvider.(bool)) + case *DeclarationOptions: + enc.ObjectKey(keyDeclarationProvider, v.DeclarationProvider.(*DeclarationOptions)) + case *DeclarationRegistrationOptions: + enc.ObjectKey(keyDeclarationProvider, v.DeclarationProvider.(*DeclarationRegistrationOptions)) + } + + switch v.DefinitionProvider.(type) { + case bool: + enc.BoolKey(keyDefinitionProvider, v.DefinitionProvider.(bool)) + case *DefinitionOptions: + enc.ObjectKey(keyDefinitionProvider, v.DefinitionProvider.(*DefinitionOptions)) + } + + switch v.TypeDefinitionProvider.(type) { + case bool: + enc.BoolKey(keyTypeDefinitionProvider, v.TypeDefinitionProvider.(bool)) + case *TypeDefinitionOptions: + enc.ObjectKey(keyTypeDefinitionProvider, v.TypeDefinitionProvider.(*TypeDefinitionOptions)) + case *TypeDefinitionRegistrationOptions: + enc.ObjectKey(keyTypeDefinitionProvider, v.TypeDefinitionProvider.(*TypeDefinitionRegistrationOptions)) + } + + switch v.ImplementationProvider.(type) { + case bool: + enc.BoolKey(keyImplementationProvider, v.ImplementationProvider.(bool)) + case *ImplementationOptions: + enc.ObjectKey(keyImplementationProvider, v.ImplementationProvider.(*ImplementationOptions)) + case *ImplementationRegistrationOptions: + enc.ObjectKey(keyImplementationProvider, v.ImplementationProvider.(*ImplementationRegistrationOptions)) + } + + switch v.ReferencesProvider.(type) { + case bool: + enc.BoolKey(keyReferencesProvider, v.ReferencesProvider.(bool)) + case *ReferencesOptions: + enc.ObjectKey(keyReferencesProvider, v.ReferencesProvider.(*ReferencesOptions)) + } + + switch v.DocumentHighlightProvider.(type) { + case bool: + enc.BoolKey(keyDocumentHighlightProvider, v.DocumentHighlightProvider.(bool)) + case *DocumentHighlightOptions: + enc.ObjectKey(keyDocumentHighlightProvider, v.DocumentHighlightProvider.(*DocumentHighlightOptions)) + } + + switch v.DocumentSymbolProvider.(type) { + case bool: + enc.BoolKey(keyDocumentSymbolProvider, v.DocumentSymbolProvider.(bool)) + case *DocumentSymbolOptions: + enc.ObjectKey(keyDocumentSymbolProvider, v.DocumentSymbolProvider.(*DocumentSymbolOptions)) + } + + switch v.WorkspaceSymbolProvider.(type) { + case bool: + enc.BoolKey(keyWorkspaceSymbolProvider, v.WorkspaceSymbolProvider.(bool)) + case *WorkspaceSymbolOptions: + enc.ObjectKey(keyWorkspaceSymbolProvider, v.WorkspaceSymbolProvider.(*WorkspaceSymbolOptions)) + } + + switch v.CodeActionProvider.(type) { + case bool: + enc.BoolKey(keyCodeActionProvider, v.CodeActionProvider.(bool)) + case *CodeActionOptions: + enc.ObjectKey(keyCodeActionProvider, v.CodeActionProvider.(*CodeActionOptions)) + } + enc.ObjectKeyOmitEmpty(keyCodeLensProvider, v.CodeLensProvider) - enc.BoolKeyOmitEmpty(keyDocumentFormattingProvider, v.DocumentFormattingProvider) - enc.BoolKeyOmitEmpty(keyDocumentRangeFormattingProvider, v.DocumentRangeFormattingProvider) + + switch v.DocumentFormattingProvider.(type) { + case bool: + enc.BoolKey(keyDocumentFormattingProvider, v.DocumentFormattingProvider.(bool)) + case *DocumentFormattingOptions: + enc.ObjectKey(keyDocumentFormattingProvider, v.DocumentFormattingProvider.(*DocumentFormattingOptions)) + } + + switch v.DocumentRangeFormattingProvider.(type) { + case bool: + enc.BoolKey(keyDocumentRangeFormattingProvider, v.DocumentRangeFormattingProvider.(bool)) + case *DocumentRangeFormattingOptions: + enc.ObjectKey(keyDocumentRangeFormattingProvider, v.DocumentRangeFormattingProvider.(*DocumentRangeFormattingOptions)) + } + enc.ObjectKeyOmitEmpty(keyDocumentOnTypeFormattingProvider, v.DocumentOnTypeFormattingProvider) - enc.AddInterfaceKeyOmitEmpty(keyRenameProvider, v.RenameProvider) + + switch v.RenameProvider.(type) { + case bool: + enc.BoolKey(keyRenameProvider, v.RenameProvider.(bool)) + case *RenameOptions: + enc.ObjectKey(keyRenameProvider, v.RenameProvider.(*RenameOptions)) + } + enc.ObjectKeyOmitEmpty(keyDocumentLinkProvider, v.DocumentLinkProvider) - enc.AddInterfaceKeyOmitEmpty(keyColorProvider, v.ColorProvider) - enc.AddInterfaceKeyOmitEmpty(keyFoldingRangeProvider, v.FoldingRangeProvider) - enc.AddInterfaceKeyOmitEmpty(keySelectionRangeProvider, v.SelectionRangeProvider) + + switch v.ColorProvider.(type) { + case bool: + enc.BoolKey(keyColorProvider, v.ColorProvider.(bool)) + case *DocumentColorOptions: + enc.ObjectKey(keyColorProvider, v.ColorProvider.(*DocumentColorOptions)) + case *DocumentColorRegistrationOptions: + enc.ObjectKey(keyColorProvider, v.ColorProvider.(*DocumentColorRegistrationOptions)) + } + + switch v.FoldingRangeProvider.(type) { + case bool: + enc.BoolKey(keyFoldingRangeProvider, v.FoldingRangeProvider.(bool)) + case *FoldingRangeOptions: + enc.ObjectKey(keyFoldingRangeProvider, v.FoldingRangeProvider.(*FoldingRangeOptions)) + case *FoldingRangeRegistrationOptions: + enc.ObjectKey(keyFoldingRangeProvider, v.FoldingRangeProvider.(*FoldingRangeRegistrationOptions)) + } + + switch v.SelectionRangeProvider.(type) { + case *EnableSelectionRange: + enc.BoolKey(keySelectionRangeProvider, bool(*v.SelectionRangeProvider.(*EnableSelectionRange))) + case *SelectionRangeOptions: + enc.ObjectKey(keySelectionRangeProvider, v.SelectionRangeProvider.(*SelectionRangeOptions)) + case *SelectionRangeRegistrationOptions: + enc.ObjectKey(keySelectionRangeProvider, v.SelectionRangeProvider.(*SelectionRangeRegistrationOptions)) + } + enc.ObjectKeyOmitEmpty(keyExecuteCommandProvider, v.ExecuteCommandProvider) enc.ObjectKeyOmitEmpty(keyWorkspace, v.Workspace) enc.AddInterfaceKeyOmitEmpty(keyExperimental, v.Experimental) @@ -1894,7 +2965,7 @@ func (v *ServerCapabilities) UnmarshalJSONObject(dec *gojay.Decoder, k string) e case keyTextDocumentSync: return dec.Interface(&v.TextDocumentSync) case keyHoverProvider: - return dec.Bool(&v.HoverProvider) + return dec.Interface(&v.HoverProvider) case keyCompletionProvider: if v.CompletionProvider == nil { v.CompletionProvider = &CompletionOptions{} @@ -1905,31 +2976,33 @@ func (v *ServerCapabilities) UnmarshalJSONObject(dec *gojay.Decoder, k string) e v.SignatureHelpProvider = &SignatureHelpOptions{} } return dec.Object(v.SignatureHelpProvider) + case keyDeclarationProvider: + return dec.Interface(&v.DeclarationProvider) case keyDefinitionProvider: - return dec.Bool(&v.DefinitionProvider) + return dec.Interface(&v.DefinitionProvider) case keyTypeDefinitionProvider: return dec.Interface(&v.TypeDefinitionProvider) case keyImplementationProvider: return dec.Interface(&v.ImplementationProvider) case keyReferencesProvider: - return dec.Bool(&v.ReferencesProvider) + return dec.Interface(&v.ReferencesProvider) case keyDocumentHighlightProvider: - return dec.Bool(&v.DocumentHighlightProvider) + return dec.Interface(&v.DocumentHighlightProvider) case keyDocumentSymbolProvider: - return dec.Bool(&v.DocumentSymbolProvider) + return dec.Interface(&v.DocumentSymbolProvider) case keyWorkspaceSymbolProvider: - return dec.Bool(&v.WorkspaceSymbolProvider) + return dec.Interface(&v.WorkspaceSymbolProvider) case keyCodeActionProvider: - return dec.Bool(&v.CodeActionProvider) + return dec.Interface(&v.CodeActionProvider) case keyCodeLensProvider: if v.CodeLensProvider == nil { v.CodeLensProvider = &CodeLensOptions{} } return dec.Object(v.CodeLensProvider) case keyDocumentFormattingProvider: - return dec.Bool(&v.DocumentFormattingProvider) + return dec.Interface(&v.DocumentFormattingProvider) case keyDocumentRangeFormattingProvider: - return dec.Bool(&v.DocumentRangeFormattingProvider) + return dec.Interface(&v.DocumentRangeFormattingProvider) case keyDocumentOnTypeFormattingProvider: if v.DocumentOnTypeFormattingProvider == nil { v.DocumentOnTypeFormattingProvider = &DocumentOnTypeFormattingOptions{} @@ -1965,7 +3038,7 @@ func (v *ServerCapabilities) UnmarshalJSONObject(dec *gojay.Decoder, k string) e } // NKeys returns the number of keys to unmarshal. -func (v *ServerCapabilities) NKeys() int { return 24 } +func (v *ServerCapabilities) NKeys() int { return 25 } // compile time check whether the ServerCapabilities implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( diff --git a/general_gojay_test.go b/general_gojay_test.go index 3bbf20a7..c617ac87 100644 --- a/general_gojay_test.go +++ b/general_gojay_test.go @@ -16,6 +16,10 @@ func TestWorkspaceFolders(t *testing.T) { testWorkspaceFolders(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestClientInfo(t *testing.T) { + testClientInfo(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestInitializeParams(t *testing.T) { testInitializeParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } @@ -40,22 +44,50 @@ func TestTextDocumentClientCapabilitiesSignatureHelp(t *testing.T) { testTextDocumentClientCapabilitiesSignatureHelp(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestReferencesParams(t *testing.T) { + testReferencesParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesReferences(t *testing.T) { testTextDocumentClientCapabilitiesReferences(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestDocumentHighlightOptions(t *testing.T) { + testDocumentHighlightOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestDocumentHighlightParams(t *testing.T) { + testDocumentHighlightParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T) { testTextDocumentClientCapabilitiesDocumentHighlight(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestDocumentSymbolOptions(t *testing.T) { + testDocumentSymbolOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T) { testTextDocumentClientCapabilitiesDocumentSymbol(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestWorkspaceSymbolOptions(t *testing.T) { + testWorkspaceSymbolOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestDocumentFormattingOptions(t *testing.T) { + testDocumentFormattingOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesFormatting(t *testing.T) { testTextDocumentClientCapabilitiesFormatting(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestDocumentRangeFormattingOptions(t *testing.T) { + testDocumentRangeFormattingOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesRangeFormatting(t *testing.T) { testTextDocumentClientCapabilitiesRangeFormatting(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } @@ -64,18 +96,54 @@ func TestTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T) { testTextDocumentClientCapabilitiesOnTypeFormatting(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestDeclarationOptions(t *testing.T) { + testDeclarationOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestDeclarationRegistrationOptions(t *testing.T) { + testDeclarationRegistrationOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestDeclarationParams(t *testing.T) { + testDeclarationParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDeclaration(t *testing.T) { testTextDocumentClientCapabilitiesDeclaration(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestDefinitionOptions(t *testing.T) { + testDefinitionOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestDefinitionParams(t *testing.T) { + testDefinitionParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDefinition(t *testing.T) { testTextDocumentClientCapabilitiesDefinition(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestTypeDefinitionOptions(t *testing.T) { + testTypeDefinitionOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestTypeDefinitionRegistrationOptions(t *testing.T) { + testTypeDefinitionRegistrationOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestTypeDefinitionParams(t *testing.T) { + testTypeDefinitionParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesTypeDefinition(t *testing.T) { testTextDocumentClientCapabilitiesTypeDefinition(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestImplementationParams(t *testing.T) { + testImplementationParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesImplementation(t *testing.T) { testTextDocumentClientCapabilitiesImplementation(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } @@ -92,6 +160,14 @@ func TestTextDocumentClientCapabilitiesDocumentLink(t *testing.T) { testTextDocumentClientCapabilitiesDocumentLink(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestDocumentColorOptions(t *testing.T) { + testDocumentColorOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestDocumentColorRegistrationOptions(t *testing.T) { + testDocumentColorRegistrationOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesColorProvider(t *testing.T) { testTextDocumentClientCapabilitiesColorProvider(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } @@ -104,6 +180,14 @@ func TestTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T) { testTextDocumentClientCapabilitiesPublishDiagnostics(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestFoldingRangeOptions(t *testing.T) { + testFoldingRangeOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestFoldingRangeRegistrationOptions(t *testing.T) { + testFoldingRangeRegistrationOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestTextDocumentClientCapabilitiesFoldingRange(t *testing.T) { testTextDocumentClientCapabilitiesFoldingRange(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } diff --git a/general_json_test.go b/general_json_test.go index d6da8e0b..15bee16c 100644 --- a/general_json_test.go +++ b/general_json_test.go @@ -13,6 +13,8 @@ import ( func TestWorkspaceFolders(t *testing.T) { testWorkspaceFolders(t, json.Marshal, json.Unmarshal) } +func TestClientInfo(t *testing.T) { testClientInfo(t, json.Marshal, json.Unmarshal) } + func TestInitializeParams(t *testing.T) { testInitializeParams(t, json.Marshal, json.Unmarshal) } func TestWorkspaceClientCapabilities(t *testing.T) { @@ -35,22 +37,50 @@ func TestTextDocumentClientCapabilitiesSignatureHelp(t *testing.T) { testTextDocumentClientCapabilitiesSignatureHelp(t, json.Marshal, json.Unmarshal) } +func TestReferencesParams(t *testing.T) { + testReferencesParams(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesReferences(t *testing.T) { testTextDocumentClientCapabilitiesReferences(t, json.Marshal, json.Unmarshal) } +func TestDocumentHighlightOptions(t *testing.T) { + testDocumentHighlightOptions(t, json.Marshal, json.Unmarshal) +} + +func TestDocumentHighlightParams(t *testing.T) { + testDocumentHighlightParams(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T) { testTextDocumentClientCapabilitiesDocumentHighlight(t, json.Marshal, json.Unmarshal) } +func TestDocumentSymbolOptions(t *testing.T) { + testDocumentSymbolOptions(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T) { testTextDocumentClientCapabilitiesDocumentSymbol(t, json.Marshal, json.Unmarshal) } +func TestWorkspaceSymbolOptions(t *testing.T) { + testWorkspaceSymbolOptions(t, json.Marshal, json.Unmarshal) +} + +func TestDocumentFormattingOptions(t *testing.T) { + testDocumentFormattingOptions(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesFormatting(t *testing.T) { testTextDocumentClientCapabilitiesFormatting(t, json.Marshal, json.Unmarshal) } +func TestDocumentRangeFormattingOptions(t *testing.T) { + testDocumentRangeFormattingOptions(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesRangeFormatting(t *testing.T) { testTextDocumentClientCapabilitiesRangeFormatting(t, json.Marshal, json.Unmarshal) } @@ -59,18 +89,54 @@ func TestTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T) { testTextDocumentClientCapabilitiesOnTypeFormatting(t, json.Marshal, json.Unmarshal) } +func TestDeclarationOptions(t *testing.T) { + testDeclarationOptions(t, json.Marshal, json.Unmarshal) +} + +func TestDeclarationRegistrationOptions(t *testing.T) { + testDeclarationRegistrationOptions(t, json.Marshal, json.Unmarshal) +} + +func TestDeclarationParams(t *testing.T) { + testDeclarationParams(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDeclaration(t *testing.T) { testTextDocumentClientCapabilitiesDeclaration(t, json.Marshal, json.Unmarshal) } +func TestDefinitionOptions(t *testing.T) { + testDefinitionOptions(t, json.Marshal, json.Unmarshal) +} + +func TestDefinitionParams(t *testing.T) { + testDefinitionParams(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesDefinition(t *testing.T) { testTextDocumentClientCapabilitiesDefinition(t, json.Marshal, json.Unmarshal) } +func TestTypeDefinitionOptions(t *testing.T) { + testTypeDefinitionOptions(t, json.Marshal, json.Unmarshal) +} + +func TestTypeDefinitionRegistrationOptions(t *testing.T) { + testTypeDefinitionRegistrationOptions(t, json.Marshal, json.Unmarshal) +} + +func TestTypeDefinitionParams(t *testing.T) { + testTypeDefinitionParams(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesTypeDefinition(t *testing.T) { testTextDocumentClientCapabilitiesTypeDefinition(t, json.Marshal, json.Unmarshal) } +func TestImplementationParams(t *testing.T) { + testImplementationParams(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesImplementation(t *testing.T) { testTextDocumentClientCapabilitiesImplementation(t, json.Marshal, json.Unmarshal) } @@ -87,6 +153,14 @@ func TestTextDocumentClientCapabilitiesDocumentLink(t *testing.T) { testTextDocumentClientCapabilitiesDocumentLink(t, json.Marshal, json.Unmarshal) } +func TestDocumentColorOptions(t *testing.T) { + testDocumentColorOptions(t, json.Marshal, json.Unmarshal) +} + +func TestDocumentColorRegistrationOptions(t *testing.T) { + testDocumentColorRegistrationOptions(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesColorProvider(t *testing.T) { testTextDocumentClientCapabilitiesColorProvider(t, json.Marshal, json.Unmarshal) } @@ -99,6 +173,14 @@ func TestTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T) { testTextDocumentClientCapabilitiesPublishDiagnostics(t, json.Marshal, json.Unmarshal) } +func TestFoldingRangeOptions(t *testing.T) { + testFoldingRangeOptions(t, json.Marshal, json.Unmarshal) +} + +func TestFoldingRangeRegistrationOptions(t *testing.T) { + testFoldingRangeRegistrationOptions(t, json.Marshal, json.Unmarshal) +} + func TestTextDocumentClientCapabilitiesFoldingRange(t *testing.T) { testTextDocumentClientCapabilitiesFoldingRange(t, json.Marshal, json.Unmarshal) } diff --git a/general_test.go b/general_test.go index 0de2be99..079fcffc 100644 --- a/general_test.go +++ b/general_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "go.lsp.dev/uri" ) @@ -99,13 +100,121 @@ func testWorkspaceFolders(t *testing.T, marshal marshalFunc, unmarshal unmarshal }) } +func testClientInfo(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"name":"testClient","version":"v0.0.0"}` + wantNilAll = `{"name":"testClient"}` + ) + wantType := ClientInfo{ + Name: "testClient", + Version: "v0.0.0", + } + wantTypeNilAll := ClientInfo{ + Name: "testClient", + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field ClientInfo + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNilAll, + want: wantNilAll, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want ClientInfo + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNilAll, + want: wantTypeNilAll, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got ClientInfo + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + func testInitializeParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" const ( - want = `{"processId":25556,"rootPath":"~/go/src/go.lsp.dev/protocol","rootUri":"file:///Users/zchee/go/src/go.lsp.dev/protocol","initializationOptions":"testdata","capabilities":{},"trace":"on","workspaceFolders":[{"uri":"file:///Users/zchee/go/src/go.lsp.dev/protocol","name":"protocol"},{"uri":"file:///Users/zchee/go/src/go.lsp.dev/jsonrpc2","name":"jsonrpc2"}]}` + want = `{"workDoneToken":"` + wantWorkDoneToken + `","processId":25556,"clientInfo":{"name":"testClient","version":"v0.0.0"},"rootPath":"~/go/src/go.lsp.dev/protocol","rootUri":"file:///Users/zchee/go/src/go.lsp.dev/protocol","initializationOptions":"testdata","capabilities":{},"trace":"on","workspaceFolders":[{"uri":"file:///Users/zchee/go/src/go.lsp.dev/protocol","name":"protocol"},{"uri":"file:///Users/zchee/go/src/go.lsp.dev/jsonrpc2","name":"jsonrpc2"}]}` wantNil = `{"processId":25556,"rootUri":"file:///Users/zchee/go/src/go.lsp.dev/protocol","capabilities":{}}` ) wantType := InitializeParams{ - ProcessID: 25556, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + ProcessID: 25556, + ClientInfo: &ClientInfo{ + Name: "testClient", + Version: "v0.0.0", + }, RootPath: "~/go/src/go.lsp.dev/protocol", RootURI: uri.File("/Users/zchee/go/src/go.lsp.dev/protocol"), InitializationOptions: "testdata", @@ -207,9 +316,15 @@ func testInitializeParams(t *testing.T, marshal marshalFunc, unmarshal unmarshal t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if token := got.WorkDoneToken; token != nil { + if diff := cmp.Diff(token.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -424,7 +539,7 @@ func testTextDocumentClientCapabilitiesSynchronization(t *testing.T, marshal mar func testTextDocumentClientCapabilitiesCompletion(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["plaintext","markdown"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1]},"contextSupport":true}` + want = `{"dynamicRegistration":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["plaintext","markdown"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{"valueSet":[1]},"contextSupport":true}` wantNil = `{}` ) wantType := TextDocumentClientCapabilitiesCompletion{ @@ -438,6 +553,11 @@ func testTextDocumentClientCapabilitiesCompletion(t *testing.T, marshal marshalF }, DeprecatedSupport: true, PreselectSupport: true, + TagSupport: &TextDocumentClientCapabilitiesCompletionItemTagSupport{ + ValueSet: []CompletionItemTag{ + CompletionItemTagDeprecated, + }, + }, }, CompletionItemKind: &TextDocumentClientCapabilitiesCompletionItemKind{ ValueSet: []CompletionItemKind{TextCompletion}, @@ -634,7 +754,7 @@ func testTextDocumentClientCapabilitiesHover(t *testing.T, marshal marshalFunc, func testTextDocumentClientCapabilitiesSignatureHelp(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["plaintext","markdown"]}}` + want = `{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["plaintext","markdown"]},"contextSupport":true}` wantNil = `{}` ) wantType := TextDocumentClientCapabilitiesSignatureHelp{ @@ -645,6 +765,7 @@ func testTextDocumentClientCapabilitiesSignatureHelp(t *testing.T, marshal marsh Markdown, }, }, + ContextSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -734,13 +855,49 @@ func testTextDocumentClientCapabilitiesSignatureHelp(t *testing.T, marshal marsh }) } -func testTextDocumentClientCapabilitiesReferences(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testReferencesParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true}` - wantNil = `{}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" ) - wantType := TextDocumentClientCapabilitiesReferences{ - DynamicRegistration: true, + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","context":{"includeDeclaration":true}}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"context":{"includeDeclaration":true}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","context":{"includeDeclaration":false}}` + ) + wantType := ReferencesParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, + Context: ReferenceContext{ + IncludeDeclaration: true, + }, + } + wantTypeNilAll := ReferencesParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + Context: ReferenceContext{ + IncludeDeclaration: true, + }, } t.Run("Marshal", func(t *testing.T) { @@ -748,7 +905,7 @@ func testTextDocumentClientCapabilitiesReferences(t *testing.T, marshal marshalF tests := []struct { name string - field TextDocumentClientCapabilitiesReferences + field ReferencesParams want string wantMarshalErr bool wantErr bool @@ -762,11 +919,18 @@ func testTextDocumentClientCapabilitiesReferences(t *testing.T, marshal marshalF }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesReferences{}, - want: wantNil, + field: wantTypeNilAll, + want: wantNilAll, wantMarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -792,7 +956,7 @@ func testTextDocumentClientCapabilitiesReferences(t *testing.T, marshal marshalF tests := []struct { name string field string - want TextDocumentClientCapabilitiesReferences + want ReferencesParams wantUnmarshalErr bool wantErr bool }{ @@ -805,11 +969,18 @@ func testTextDocumentClientCapabilitiesReferences(t *testing.T, marshal marshalF }, { name: "ValidNilAll", - field: wantNil, - want: TextDocumentClientCapabilitiesReferences{}, + field: wantNilAll, + want: wantTypeNilAll, wantUnmarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -817,25 +988,37 @@ func testTextDocumentClientCapabilitiesReferences(t *testing.T, marshal marshalF t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesReferences + var got ReferencesParams if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) } -func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesReferences(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( want = `{"dynamicRegistration":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesDocumentHighlight{ + wantType := TextDocumentClientCapabilitiesReferences{ DynamicRegistration: true, } @@ -844,7 +1027,7 @@ func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal m tests := []struct { name string - field TextDocumentClientCapabilitiesDocumentHighlight + field TextDocumentClientCapabilitiesReferences want string wantMarshalErr bool wantErr bool @@ -858,7 +1041,7 @@ func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal m }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesDocumentHighlight{}, + field: TextDocumentClientCapabilitiesReferences{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -888,7 +1071,7 @@ func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal m tests := []struct { name string field string - want TextDocumentClientCapabilitiesDocumentHighlight + want TextDocumentClientCapabilitiesReferences wantUnmarshalErr bool wantErr bool }{ @@ -902,7 +1085,7 @@ func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal m { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesDocumentHighlight{}, + want: TextDocumentClientCapabilitiesReferences{}, wantUnmarshalErr: false, wantErr: false, }, @@ -913,7 +1096,7 @@ func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal m t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesDocumentHighlight + var got TextDocumentClientCapabilitiesReferences if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -926,24 +1109,16 @@ func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal m }) } -func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testDocumentHighlightOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6]},"hierarchicalDocumentSymbolSupport":true}` - wantNil = `{}` + want = `{"workDoneProgress":true}` + wantNil = `{}` + wantInvalid = `{"workDoneProgress":false}` ) - wantType := TextDocumentClientCapabilitiesDocumentSymbol{ - DynamicRegistration: true, - SymbolKind: &WorkspaceClientCapabilitiesSymbolKind{ - ValueSet: []SymbolKind{ - FileSymbol, - ModuleSymbol, - NamespaceSymbol, - PackageSymbol, - ClassSymbol, - MethodSymbol, - }, + wantType := DocumentHighlightOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, }, - HierarchicalDocumentSymbolSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -951,7 +1126,7 @@ func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal mars tests := []struct { name string - field TextDocumentClientCapabilitiesDocumentSymbol + field DocumentHighlightOptions want string wantMarshalErr bool wantErr bool @@ -965,11 +1140,18 @@ func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal mars }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesDocumentSymbol{}, + field: DocumentHighlightOptions{}, want: wantNil, wantMarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -995,7 +1177,7 @@ func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal mars tests := []struct { name string field string - want TextDocumentClientCapabilitiesDocumentSymbol + want DocumentHighlightOptions wantUnmarshalErr bool wantErr bool }{ @@ -1009,10 +1191,17 @@ func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal mars { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesDocumentSymbol{}, + want: DocumentHighlightOptions{}, wantUnmarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -1020,7 +1209,7 @@ func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal mars t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesDocumentSymbol + var got DocumentHighlightOptions if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1033,13 +1222,43 @@ func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal mars }) } -func testTextDocumentClientCapabilitiesFormatting(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testDocumentHighlightParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true}` - wantNil = `{}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" ) - wantType := TextDocumentClientCapabilitiesFormatting{ - DynamicRegistration: true, + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `"}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `"}` + ) + wantType := DocumentHighlightParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, + } + wantTypeNilAll := DocumentHighlightParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, } t.Run("Marshal", func(t *testing.T) { @@ -1047,7 +1266,7 @@ func testTextDocumentClientCapabilitiesFormatting(t *testing.T, marshal marshalF tests := []struct { name string - field TextDocumentClientCapabilitiesFormatting + field DocumentHighlightParams want string wantMarshalErr bool wantErr bool @@ -1061,11 +1280,18 @@ func testTextDocumentClientCapabilitiesFormatting(t *testing.T, marshal marshalF }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesFormatting{}, - want: wantNil, + field: wantTypeNilAll, + want: wantNilAll, wantMarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -1091,7 +1317,7 @@ func testTextDocumentClientCapabilitiesFormatting(t *testing.T, marshal marshalF tests := []struct { name string field string - want TextDocumentClientCapabilitiesFormatting + want DocumentHighlightParams wantUnmarshalErr bool wantErr bool }{ @@ -1104,11 +1330,18 @@ func testTextDocumentClientCapabilitiesFormatting(t *testing.T, marshal marshalF }, { name: "ValidNilAll", - field: wantNil, - want: TextDocumentClientCapabilitiesFormatting{}, + field: wantNilAll, + want: wantTypeNilAll, wantUnmarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -1116,25 +1349,37 @@ func testTextDocumentClientCapabilitiesFormatting(t *testing.T, marshal marshalF t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesFormatting + var got DocumentHighlightParams if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) } -func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesDocumentHighlight(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( want = `{"dynamicRegistration":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesRangeFormatting{ + wantType := TextDocumentClientCapabilitiesDocumentHighlight{ DynamicRegistration: true, } @@ -1143,7 +1388,7 @@ func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal mar tests := []struct { name string - field TextDocumentClientCapabilitiesRangeFormatting + field TextDocumentClientCapabilitiesDocumentHighlight want string wantMarshalErr bool wantErr bool @@ -1157,7 +1402,7 @@ func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal mar }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesRangeFormatting{}, + field: TextDocumentClientCapabilitiesDocumentHighlight{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -1187,7 +1432,7 @@ func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal mar tests := []struct { name string field string - want TextDocumentClientCapabilitiesRangeFormatting + want TextDocumentClientCapabilitiesDocumentHighlight wantUnmarshalErr bool wantErr bool }{ @@ -1201,7 +1446,7 @@ func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal mar { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesRangeFormatting{}, + want: TextDocumentClientCapabilitiesDocumentHighlight{}, wantUnmarshalErr: false, wantErr: false, }, @@ -1212,7 +1457,7 @@ func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal mar t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesRangeFormatting + var got TextDocumentClientCapabilitiesDocumentHighlight if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1225,13 +1470,2375 @@ func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal mar }) } -func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testDocumentSymbolOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true}` + wantInvalid = `{"workDoneProgress":false}` + wantNil = `{}` + ) + wantType := DocumentSymbolOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DocumentSymbolOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: DocumentSymbolOptions{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DocumentSymbolOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: DocumentSymbolOptions{}, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DocumentSymbolOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesDocumentSymbol(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6]},"hierarchicalDocumentSymbolSupport":true}` + wantNil = `{}` + ) + wantType := TextDocumentClientCapabilitiesDocumentSymbol{ + DynamicRegistration: true, + SymbolKind: &WorkspaceClientCapabilitiesSymbolKind{ + ValueSet: []SymbolKind{ + FileSymbol, + ModuleSymbol, + NamespaceSymbol, + PackageSymbol, + ClassSymbol, + MethodSymbol, + }, + }, + HierarchicalDocumentSymbolSupport: true, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TextDocumentClientCapabilitiesDocumentSymbol + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TextDocumentClientCapabilitiesDocumentSymbol{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TextDocumentClientCapabilitiesDocumentSymbol + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TextDocumentClientCapabilitiesDocumentSymbol{}, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TextDocumentClientCapabilitiesDocumentSymbol + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testWorkspaceSymbolOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true}` + wantInvalid = `{"workDoneProgress":false}` + wantNil = `{}` + ) + wantType := WorkspaceSymbolOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field WorkspaceSymbolOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: WorkspaceSymbolOptions{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want WorkspaceSymbolOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: WorkspaceSymbolOptions{}, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got WorkspaceSymbolOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testDocumentFormattingOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true}` + wantInvalid = `{"workDoneProgress":false}` + wantNil = `{}` + ) + wantType := DocumentFormattingOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DocumentFormattingOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: DocumentFormattingOptions{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DocumentFormattingOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: DocumentFormattingOptions{}, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DocumentFormattingOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesFormatting(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"dynamicRegistration":true}` + wantNil = `{}` + ) + wantType := TextDocumentClientCapabilitiesFormatting{ + DynamicRegistration: true, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TextDocumentClientCapabilitiesFormatting + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TextDocumentClientCapabilitiesFormatting{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TextDocumentClientCapabilitiesFormatting + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TextDocumentClientCapabilitiesFormatting{}, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TextDocumentClientCapabilitiesFormatting + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testDocumentRangeFormattingOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true}` + wantNil = `{}` + wantInvalid = `{"workDoneProgress":false}` + ) + wantType := DocumentRangeFormattingOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DocumentRangeFormattingOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: DocumentRangeFormattingOptions{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DocumentRangeFormattingOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: DocumentRangeFormattingOptions{}, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DocumentRangeFormattingOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesRangeFormatting(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"dynamicRegistration":true}` + wantNil = `{}` + ) + wantType := TextDocumentClientCapabilitiesRangeFormatting{ + DynamicRegistration: true, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TextDocumentClientCapabilitiesRangeFormatting + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TextDocumentClientCapabilitiesRangeFormatting{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TextDocumentClientCapabilitiesRangeFormatting + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TextDocumentClientCapabilitiesRangeFormatting{}, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TextDocumentClientCapabilitiesRangeFormatting + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"dynamicRegistration":true}` + wantNil = `{}` + ) + wantType := TextDocumentClientCapabilitiesOnTypeFormatting{ + DynamicRegistration: true, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TextDocumentClientCapabilitiesOnTypeFormatting + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TextDocumentClientCapabilitiesOnTypeFormatting{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TextDocumentClientCapabilitiesOnTypeFormatting + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TextDocumentClientCapabilitiesOnTypeFormatting{}, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TextDocumentClientCapabilitiesOnTypeFormatting + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testDeclarationOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true}` + wantNil = `{}` + wantInvalid = `{"workDoneProgress":false}` + ) + wantType := DeclarationOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DeclarationOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: DeclarationOptions{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DeclarationOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: DeclarationOptions{}, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DeclarationOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testDeclarationRegistrationOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true,"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}],"id":"1"}` + wantNil = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}]}` + wantInvalid = `{"workDoneProgress":false,"documentSelector":[{"language":"typescript","scheme":"file","pattern":"*.{ts,js}"}],"id":"0"}` + ) + wantType := DeclarationRegistrationOptions{ + DeclarationOptions: DeclarationOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + }, + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, + }, + }, + }, + StaticRegistrationOptions: StaticRegistrationOptions{ + ID: "1", + }, + } + wantTypeNil := DeclarationRegistrationOptions{ + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, + }, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DeclarationRegistrationOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNil, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DeclarationRegistrationOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: wantTypeNil, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DeclarationRegistrationOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testDeclarationParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `"}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `"}` + ) + wantType := DeclarationParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, + } + wantTypeNilAll := DeclarationParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DeclarationParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNilAll, + want: wantNilAll, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DeclarationParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNilAll, + want: wantTypeNilAll, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DeclarationParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"dynamicRegistration":true,"linkSupport":true}` + wantNil = `{}` + ) + wantType := TextDocumentClientCapabilitiesDeclaration{ + DynamicRegistration: true, + LinkSupport: true, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TextDocumentClientCapabilitiesDeclaration + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TextDocumentClientCapabilitiesDeclaration{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TextDocumentClientCapabilitiesDeclaration + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TextDocumentClientCapabilitiesDeclaration{}, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TextDocumentClientCapabilitiesDeclaration + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testDefinitionOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true}` + wantNil = `{}` + wantInvalid = `{"workDoneProgress":false}` + ) + wantType := DefinitionOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DefinitionOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: DefinitionOptions{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DefinitionOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: DefinitionOptions{}, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DefinitionOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testDefinitionParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `"}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `"}` + ) + wantType := DefinitionParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, + } + wantTypeNilAll := DefinitionParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field DefinitionParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNilAll, + want: wantNilAll, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want DefinitionParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNilAll, + want: wantTypeNilAll, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got DefinitionParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"dynamicRegistration":true,"linkSupport":true}` + wantNil = `{}` + ) + wantType := TextDocumentClientCapabilitiesDefinition{ + DynamicRegistration: true, + LinkSupport: true, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TextDocumentClientCapabilitiesDefinition + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TextDocumentClientCapabilitiesDefinition{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TextDocumentClientCapabilitiesDefinition + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TextDocumentClientCapabilitiesDefinition{}, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TextDocumentClientCapabilitiesDefinition + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testTypeDefinitionOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"workDoneProgress":true}` + wantNil = `{}` + wantInvalid = `{"workDoneProgress":false}` + ) + wantType := TypeDefinitionOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TypeDefinitionOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TypeDefinitionOptions{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TypeDefinitionOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TypeDefinitionOptions{}, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TypeDefinitionOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testTypeDefinitionRegistrationOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}],"workDoneProgress":true,"id":"1"}` + wantNil = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}]}` + wantInvalid = `{"documentSelector":[{"language":"typescript","scheme":"file","pattern":"*.{ts,js}"}],"workDoneProgress":false,"id":"0"}` + ) + wantType := TypeDefinitionRegistrationOptions{ + TypeDefinitionOptions: TypeDefinitionOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + }, + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, + }, + }, + }, + StaticRegistrationOptions: StaticRegistrationOptions{ + ID: "1", + }, + } + wantTypeNil := TypeDefinitionRegistrationOptions{ + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, + }, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TypeDefinitionRegistrationOptions + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNil, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TypeDefinitionRegistrationOptions + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: wantTypeNil, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TypeDefinitionRegistrationOptions + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testTypeDefinitionParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `"}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `"}` + ) + wantType := TypeDefinitionParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, + } + wantTypeNilAll := TypeDefinitionParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TypeDefinitionParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNilAll, + want: wantNilAll, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TypeDefinitionParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNilAll, + want: wantTypeNilAll, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TypeDefinitionParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"dynamicRegistration":true,"linkSupport":true}` + wantNil = `{}` + ) + wantType := TextDocumentClientCapabilitiesTypeDefinition{ + DynamicRegistration: true, + LinkSupport: true, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field TextDocumentClientCapabilitiesTypeDefinition + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: TextDocumentClientCapabilitiesTypeDefinition{}, + want: wantNil, + wantMarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want TextDocumentClientCapabilitiesTypeDefinition + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNil, + want: TextDocumentClientCapabilitiesTypeDefinition{}, + wantUnmarshalErr: false, + wantErr: false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got TextDocumentClientCapabilitiesTypeDefinition + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testImplementationParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `"}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `"}` + ) + wantType := ImplementationParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, + } + wantTypeNilAll := ImplementationParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field ImplementationParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNilAll, + want: wantNilAll, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want ImplementationParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNilAll, + want: wantTypeNilAll, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got ImplementationParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + }) + } + }) +} + +func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true}` + want = `{"dynamicRegistration":true,"linkSupport":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesOnTypeFormatting{ + wantType := TextDocumentClientCapabilitiesImplementation{ DynamicRegistration: true, + LinkSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -1239,7 +3846,7 @@ func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal ma tests := []struct { name string - field TextDocumentClientCapabilitiesOnTypeFormatting + field TextDocumentClientCapabilitiesImplementation want string wantMarshalErr bool wantErr bool @@ -1253,7 +3860,7 @@ func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal ma }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesOnTypeFormatting{}, + field: TextDocumentClientCapabilitiesImplementation{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -1283,7 +3890,7 @@ func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal ma tests := []struct { name string field string - want TextDocumentClientCapabilitiesOnTypeFormatting + want TextDocumentClientCapabilitiesImplementation wantUnmarshalErr bool wantErr bool }{ @@ -1297,7 +3904,7 @@ func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal ma { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesOnTypeFormatting{}, + want: TextDocumentClientCapabilitiesImplementation{}, wantUnmarshalErr: false, wantErr: false, }, @@ -1308,7 +3915,7 @@ func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal ma t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesOnTypeFormatting + var got TextDocumentClientCapabilitiesImplementation if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1321,14 +3928,26 @@ func testTextDocumentClientCapabilitiesOnTypeFormatting(t *testing.T, marshal ma }) } -func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"linkSupport":true}` + want = `{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.rewrite","source","source.organizeImports"]}},"isPreferredSupport":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesDeclaration{ + wantType := TextDocumentClientCapabilitiesCodeAction{ DynamicRegistration: true, - LinkSupport: true, + CodeActionLiteralSupport: &TextDocumentClientCapabilitiesCodeActionLiteralSupport{ + CodeActionKind: &TextDocumentClientCapabilitiesCodeActionKind{ + ValueSet: []CodeActionKind{ + QuickFix, + Refactor, + RefactorExtract, + RefactorRewrite, + Source, + SourceOrganizeImports, + }, + }, + }, + IsPreferredSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -1336,7 +3955,7 @@ func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshal tests := []struct { name string - field TextDocumentClientCapabilitiesDeclaration + field TextDocumentClientCapabilitiesCodeAction want string wantMarshalErr bool wantErr bool @@ -1350,7 +3969,7 @@ func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshal }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesDeclaration{}, + field: TextDocumentClientCapabilitiesCodeAction{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -1380,7 +3999,7 @@ func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshal tests := []struct { name string field string - want TextDocumentClientCapabilitiesDeclaration + want TextDocumentClientCapabilitiesCodeAction wantUnmarshalErr bool wantErr bool }{ @@ -1394,7 +4013,7 @@ func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshal { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesDeclaration{}, + want: TextDocumentClientCapabilitiesCodeAction{}, wantUnmarshalErr: false, wantErr: false, }, @@ -1405,7 +4024,7 @@ func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshal t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesDeclaration + var got TextDocumentClientCapabilitiesCodeAction if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1418,14 +4037,14 @@ func testTextDocumentClientCapabilitiesDeclaration(t *testing.T, marshal marshal }) } -func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"linkSupport":true}` + want = `{"dynamicRegistration":true,"tooltipSupport":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesDefinition{ + wantType := TextDocumentClientCapabilitiesCodeLens{ DynamicRegistration: true, - LinkSupport: true, + TooltipSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -1433,7 +4052,7 @@ func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalF tests := []struct { name string - field TextDocumentClientCapabilitiesDefinition + field TextDocumentClientCapabilitiesCodeLens want string wantMarshalErr bool wantErr bool @@ -1447,7 +4066,7 @@ func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalF }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesDefinition{}, + field: TextDocumentClientCapabilitiesCodeLens{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -1477,7 +4096,7 @@ func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalF tests := []struct { name string field string - want TextDocumentClientCapabilitiesDefinition + want TextDocumentClientCapabilitiesCodeLens wantUnmarshalErr bool wantErr bool }{ @@ -1491,7 +4110,7 @@ func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalF { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesDefinition{}, + want: TextDocumentClientCapabilitiesCodeLens{}, wantUnmarshalErr: false, wantErr: false, }, @@ -1502,7 +4121,7 @@ func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalF t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesDefinition + var got TextDocumentClientCapabilitiesCodeLens if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1515,14 +4134,14 @@ func testTextDocumentClientCapabilitiesDefinition(t *testing.T, marshal marshalF }) } -func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"linkSupport":true}` + want = `{"dynamicRegistration":true,"tooltipSupport":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesTypeDefinition{ + wantType := TextDocumentClientCapabilitiesDocumentLink{ DynamicRegistration: true, - LinkSupport: true, + TooltipSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -1530,7 +4149,7 @@ func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal mars tests := []struct { name string - field TextDocumentClientCapabilitiesTypeDefinition + field TextDocumentClientCapabilitiesDocumentLink want string wantMarshalErr bool wantErr bool @@ -1544,7 +4163,7 @@ func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal mars }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesTypeDefinition{}, + field: TextDocumentClientCapabilitiesDocumentLink{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -1574,7 +4193,7 @@ func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal mars tests := []struct { name string field string - want TextDocumentClientCapabilitiesTypeDefinition + want TextDocumentClientCapabilitiesDocumentLink wantUnmarshalErr bool wantErr bool }{ @@ -1588,7 +4207,7 @@ func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal mars { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesTypeDefinition{}, + want: TextDocumentClientCapabilitiesDocumentLink{}, wantUnmarshalErr: false, wantErr: false, }, @@ -1599,7 +4218,7 @@ func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal mars t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesTypeDefinition + var got TextDocumentClientCapabilitiesDocumentLink if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1612,14 +4231,16 @@ func testTextDocumentClientCapabilitiesTypeDefinition(t *testing.T, marshal mars }) } -func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testDocumentColorOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"linkSupport":true}` - wantNil = `{}` + want = `{"workDoneProgress":true}` + wantNil = `{}` + wantInvalid = `{"workDoneProgress":false}` ) - wantType := TextDocumentClientCapabilitiesImplementation{ - DynamicRegistration: true, - LinkSupport: true, + wantType := DocumentColorOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, } t.Run("Marshal", func(t *testing.T) { @@ -1627,7 +4248,7 @@ func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal mars tests := []struct { name string - field TextDocumentClientCapabilitiesImplementation + field DocumentColorOptions want string wantMarshalErr bool wantErr bool @@ -1641,11 +4262,18 @@ func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal mars }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesImplementation{}, + field: DocumentColorOptions{}, want: wantNil, wantMarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -1671,7 +4299,7 @@ func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal mars tests := []struct { name string field string - want TextDocumentClientCapabilitiesImplementation + want DocumentColorOptions wantUnmarshalErr bool wantErr bool }{ @@ -1685,10 +4313,17 @@ func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal mars { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesImplementation{}, + want: DocumentColorOptions{}, wantUnmarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -1696,7 +4331,7 @@ func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal mars t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesImplementation + var got DocumentColorOptions if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1709,22 +4344,38 @@ func testTextDocumentClientCapabilitiesImplementation(t *testing.T, marshal mars }) } -func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testDocumentColorRegistrationOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.rewrite","source","source.organizeImports"]}}}` - wantNil = `{}` + want = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}],"id":"1","workDoneProgress":true}` + wantNil = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}]}` + wantInvalid = `{"documentSelector":[{"language":"typescript","scheme":"file","pattern":"*.{ts,js}"}],"id":"0","workDoneProgress":false}` ) - wantType := TextDocumentClientCapabilitiesCodeAction{ - DynamicRegistration: true, - CodeActionLiteralSupport: &TextDocumentClientCapabilitiesCodeActionLiteralSupport{ - CodeActionKind: &TextDocumentClientCapabilitiesCodeActionKind{ - ValueSet: []CodeActionKind{ - QuickFix, - Refactor, - RefactorExtract, - RefactorRewrite, - Source, - SourceOrganizeImports, + wantType := DocumentColorRegistrationOptions{ + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, + }, + }, + }, + StaticRegistrationOptions: StaticRegistrationOptions{ + ID: "1", + }, + DocumentColorOptions: DocumentColorOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + }, + } + wantTypeNil := DocumentColorRegistrationOptions{ + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, }, }, }, @@ -1735,7 +4386,7 @@ func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalF tests := []struct { name string - field TextDocumentClientCapabilitiesCodeAction + field DocumentColorRegistrationOptions want string wantMarshalErr bool wantErr bool @@ -1749,11 +4400,18 @@ func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalF }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesCodeAction{}, + field: wantTypeNil, want: wantNil, wantMarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -1779,7 +4437,7 @@ func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalF tests := []struct { name string field string - want TextDocumentClientCapabilitiesCodeAction + want DocumentColorRegistrationOptions wantUnmarshalErr bool wantErr bool }{ @@ -1793,10 +4451,17 @@ func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalF { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesCodeAction{}, + want: wantTypeNil, wantUnmarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -1804,7 +4469,7 @@ func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalF t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesCodeAction + var got DocumentColorRegistrationOptions if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1817,12 +4482,12 @@ func testTextDocumentClientCapabilitiesCodeAction(t *testing.T, marshal marshalF }) } -func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( want = `{"dynamicRegistration":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesCodeLens{ + wantType := TextDocumentClientCapabilitiesColorProvider{ DynamicRegistration: true, } @@ -1831,7 +4496,7 @@ func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFun tests := []struct { name string - field TextDocumentClientCapabilitiesCodeLens + field TextDocumentClientCapabilitiesColorProvider want string wantMarshalErr bool wantErr bool @@ -1845,7 +4510,7 @@ func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFun }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesCodeLens{}, + field: TextDocumentClientCapabilitiesColorProvider{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -1875,7 +4540,7 @@ func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFun tests := []struct { name string field string - want TextDocumentClientCapabilitiesCodeLens + want TextDocumentClientCapabilitiesColorProvider wantUnmarshalErr bool wantErr bool }{ @@ -1889,7 +4554,7 @@ func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFun { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesCodeLens{}, + want: TextDocumentClientCapabilitiesColorProvider{}, wantUnmarshalErr: false, wantErr: false, }, @@ -1900,7 +4565,7 @@ func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFun t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesCodeLens + var got TextDocumentClientCapabilitiesColorProvider if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -1913,13 +4578,14 @@ func testTextDocumentClientCapabilitiesCodeLens(t *testing.T, marshal marshalFun }) } -func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true}` + want = `{"dynamicRegistration":true,"prepareSupport":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesDocumentLink{ + wantType := TextDocumentClientCapabilitiesRename{ DynamicRegistration: true, + PrepareSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -1927,7 +4593,7 @@ func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marsha tests := []struct { name string - field TextDocumentClientCapabilitiesDocumentLink + field TextDocumentClientCapabilitiesRename want string wantMarshalErr bool wantErr bool @@ -1941,7 +4607,7 @@ func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marsha }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesDocumentLink{}, + field: TextDocumentClientCapabilitiesRename{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -1971,7 +4637,7 @@ func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marsha tests := []struct { name string field string - want TextDocumentClientCapabilitiesDocumentLink + want TextDocumentClientCapabilitiesRename wantUnmarshalErr bool wantErr bool }{ @@ -1985,7 +4651,7 @@ func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marsha { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesDocumentLink{}, + want: TextDocumentClientCapabilitiesRename{}, wantUnmarshalErr: false, wantErr: false, }, @@ -1996,7 +4662,7 @@ func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marsha t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesDocumentLink + var got TextDocumentClientCapabilitiesRename if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -2009,13 +4675,20 @@ func testTextDocumentClientCapabilitiesDocumentLink(t *testing.T, marshal marsha }) } -func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true}` + want = `{"relatedInformation":true,"tagSupport":{"valueSet":[2,1]},"versionSupport":true}` wantNil = `{}` ) - wantType := TextDocumentClientCapabilitiesColorProvider{ - DynamicRegistration: true, + wantType := TextDocumentClientCapabilitiesPublishDiagnostics{ + RelatedInformation: true, + TagSupport: &TextDocumentClientCapabilitiesPublishDiagnosticsTagSupport{ + ValueSet: []DiagnosticTag{ + DiagnosticDeprecated, + DiagnosticUnnecessary, + }, + }, + VersionSupport: true, } t.Run("Marshal", func(t *testing.T) { @@ -2023,7 +4696,7 @@ func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marsh tests := []struct { name string - field TextDocumentClientCapabilitiesColorProvider + field TextDocumentClientCapabilitiesPublishDiagnostics want string wantMarshalErr bool wantErr bool @@ -2037,7 +4710,7 @@ func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marsh }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesColorProvider{}, + field: TextDocumentClientCapabilitiesPublishDiagnostics{}, want: wantNil, wantMarshalErr: false, wantErr: false, @@ -2067,7 +4740,7 @@ func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marsh tests := []struct { name string field string - want TextDocumentClientCapabilitiesColorProvider + want TextDocumentClientCapabilitiesPublishDiagnostics wantUnmarshalErr bool wantErr bool }{ @@ -2081,7 +4754,7 @@ func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marsh { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesColorProvider{}, + want: TextDocumentClientCapabilitiesPublishDiagnostics{}, wantUnmarshalErr: false, wantErr: false, }, @@ -2092,7 +4765,7 @@ func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marsh t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesColorProvider + var got TextDocumentClientCapabilitiesPublishDiagnostics if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -2105,14 +4778,16 @@ func testTextDocumentClientCapabilitiesColorProvider(t *testing.T, marshal marsh }) } -func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testFoldingRangeOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"dynamicRegistration":true,"prepareSupport":true}` - wantNil = `{}` + want = `{"workDoneProgress":true}` + wantNil = `{}` + wantInvalid = `{"workDoneProgress":false}` ) - wantType := TextDocumentClientCapabilitiesRename{ - DynamicRegistration: true, - PrepareSupport: true, + wantType := FoldingRangeOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, } t.Run("Marshal", func(t *testing.T) { @@ -2120,7 +4795,7 @@ func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, tests := []struct { name string - field TextDocumentClientCapabilitiesRename + field FoldingRangeOptions want string wantMarshalErr bool wantErr bool @@ -2134,11 +4809,18 @@ func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesRename{}, + field: FoldingRangeOptions{}, want: wantNil, wantMarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -2164,7 +4846,7 @@ func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, tests := []struct { name string field string - want TextDocumentClientCapabilitiesRename + want FoldingRangeOptions wantUnmarshalErr bool wantErr bool }{ @@ -2178,10 +4860,17 @@ func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesRename{}, + want: FoldingRangeOptions{}, wantUnmarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -2189,7 +4878,7 @@ func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesRename + var got FoldingRangeOptions if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -2202,14 +4891,41 @@ func testTextDocumentClientCapabilitiesRename(t *testing.T, marshal marshalFunc, }) } -func testTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { +func testFoldingRangeRegistrationOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"relatedInformation":true,"tagSupport":true}` - wantNil = `{}` + want = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}],"workDoneProgress":true,"id":"1"}` + wantNil = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*"}]}` + wantInvalid = `{"documentSelector":[{"language":"typescript","scheme":"file","pattern":"*.{ts,js}"}],"workDoneProgress":false,"id":"0"}` ) - wantType := TextDocumentClientCapabilitiesPublishDiagnostics{ - RelatedInformation: true, - TagSupport: true, + wantType := FoldingRangeRegistrationOptions{ + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, + }, + }, + }, + FoldingRangeOptions: FoldingRangeOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: true, + }, + }, + StaticRegistrationOptions: StaticRegistrationOptions{ + ID: "1", + }, + } + wantTypeNil := FoldingRangeRegistrationOptions{ + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: DocumentSelector{ + { + Language: "go", + Scheme: "file", + Pattern: `*`, + }, + }, + }, } t.Run("Marshal", func(t *testing.T) { @@ -2217,7 +4933,7 @@ func testTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T, marshal tests := []struct { name string - field TextDocumentClientCapabilitiesPublishDiagnostics + field FoldingRangeRegistrationOptions want string wantMarshalErr bool wantErr bool @@ -2231,11 +4947,18 @@ func testTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T, marshal }, { name: "ValidNilAll", - field: TextDocumentClientCapabilitiesPublishDiagnostics{}, + field: wantTypeNil, want: wantNil, wantMarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -2261,7 +4984,7 @@ func testTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T, marshal tests := []struct { name string field string - want TextDocumentClientCapabilitiesPublishDiagnostics + want FoldingRangeRegistrationOptions wantUnmarshalErr bool wantErr bool }{ @@ -2275,10 +4998,17 @@ func testTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T, marshal { name: "ValidNilAll", field: wantNil, - want: TextDocumentClientCapabilitiesPublishDiagnostics{}, + want: wantTypeNil, wantUnmarshalErr: false, wantErr: false, }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, } for _, tt := range tests { @@ -2286,7 +5016,7 @@ func testTextDocumentClientCapabilitiesPublishDiagnostics(t *testing.T, marshal t.Run(tt.name, func(t *testing.T) { t.Parallel() - var got TextDocumentClientCapabilitiesPublishDiagnostics + var got FoldingRangeRegistrationOptions if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { t.Fatal(err) } @@ -2617,7 +5347,7 @@ func testTextDocumentClientCapabilities(t *testing.T, marshal marshalFunc, unmar func testClientCapabilities(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"failureHandling":"FailureHandling","resourceOperations":["ResourceOperations"]},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6]}},"executeCommand":{"dynamicRegistration":true},"workspaceFolders":true,"configuration":true},"textDocument":{"synchronization":{"didSave":true,"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true},"completion":{"dynamicRegistration":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["plaintext","markdown"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1]},"contextSupport":true},"hover":{"dynamicRegistration":true,"contentFormat":["plaintext","markdown"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["plaintext","markdown"]}},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6]},"hierarchicalDocumentSymbolSupport":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"publishDiagnostics":{"relatedInformation":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":0.5,"lineFoldingOnly":true},"selectionRange":{"dynamicRegistration":true}}}` + want = `{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"failureHandling":"FailureHandling","resourceOperations":["ResourceOperations"]},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6]}},"executeCommand":{"dynamicRegistration":true},"workspaceFolders":true,"configuration":true},"textDocument":{"synchronization":{"didSave":true,"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true},"completion":{"dynamicRegistration":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["plaintext","markdown"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1]},"contextSupport":true},"hover":{"dynamicRegistration":true,"contentFormat":["plaintext","markdown"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["plaintext","markdown"]}},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6]},"hierarchicalDocumentSymbolSupport":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"publishDiagnostics":{"relatedInformation":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":0.5,"lineFoldingOnly":true},"selectionRange":{"dynamicRegistration":true}},"window":{"workDoneProgress":true}}` wantNil = `{}` ) wantType := ClientCapabilities{ @@ -2778,6 +5508,9 @@ func testClientCapabilities(t *testing.T, marshal marshalFunc, unmarshal unmarsh DynamicRegistration: true, }, }, + Window: &WindowClientCapabilities{ + WorkDoneProgress: true, + }, } t.Run("Marshal", func(t *testing.T) { @@ -2869,12 +5602,13 @@ func testClientCapabilities(t *testing.T, marshal marshalFunc, unmarshal unmarsh func testInitializeResult(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"capabilities":{"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":["Tab"]},"signatureHelpProvider":{"triggerCharacters":["C-K"]},"definitionProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{"resolveProvider":true},"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":".","moreTriggerCharacter":["f"]},"renameProvider":true,"documentLinkProvider":{"resolveProvider":true},"executeCommandProvider":{"commands":["test","command"]},"workspace":{"workspaceFolders":{"supported":true}}}}` + want = `{"capabilities":{"textDocumentSync":3,"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":["Tab"]},"signatureHelpProvider":{"triggerCharacters":["C-K"]},"declarationProvider":true,"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{"resolveProvider":true},"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":".","moreTriggerCharacter":["f"]},"renameProvider":true,"documentLinkProvider":{"resolveProvider":true},"colorProvider":true,"foldingRangeProvider":true,"selectionRangeProvider":true,"executeCommandProvider":{"commands":["test","command"]},"workspace":{"workspaceFolders":{"supported":true}},"experimental":"Awesome Experimentals"}}` wantNil = `{"capabilities":{}}` ) + enableSelectionRange := EnableSelectionRange(true) wantType := InitializeResult{ Capabilities: ServerCapabilities{ - TextDocumentSync: nil, + TextDocumentSync: float64(3), HoverProvider: true, CompletionProvider: &CompletionOptions{ ResolveProvider: true, @@ -2883,9 +5617,10 @@ func testInitializeResult(t *testing.T, marshal marshalFunc, unmarshal unmarshal SignatureHelpProvider: &SignatureHelpOptions{ TriggerCharacters: []string{"C-K"}, }, + DeclarationProvider: true, DefinitionProvider: true, - TypeDefinitionProvider: nil, - ImplementationProvider: nil, + TypeDefinitionProvider: true, + ImplementationProvider: true, ReferencesProvider: true, DocumentHighlightProvider: true, DocumentSymbolProvider: true, @@ -2904,8 +5639,8 @@ func testInitializeResult(t *testing.T, marshal marshalFunc, unmarshal unmarshal DocumentLinkProvider: &DocumentLinkOptions{ ResolveProvider: true, }, - ColorProvider: nil, - FoldingRangeProvider: nil, + ColorProvider: true, + FoldingRangeProvider: true, ExecuteCommandProvider: &ExecuteCommandOptions{ Commands: []string{"test", "command"}, }, @@ -2915,7 +5650,8 @@ func testInitializeResult(t *testing.T, marshal marshalFunc, unmarshal unmarshal ChangeNotifications: nil, }, }, - Experimental: nil, + SelectionRangeProvider: &enableSelectionRange, + Experimental: "Awesome Experimentals", }, } @@ -2999,9 +5735,21 @@ func testInitializeResult(t *testing.T, marshal marshalFunc, unmarshal unmarshal t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + cmpOpts := cmpopts.IgnoreFields(ServerCapabilities{}, "SelectionRangeProvider") // ignore SelectionRangeProvider field but assert below + if diff := cmp.Diff(got, tt.want, cmpOpts); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if srp := got.Capabilities.SelectionRangeProvider; srp != nil { + switch srp := srp.(type) { + case bool: // EnableSelectionRange + if diff := cmp.Diff(EnableSelectionRange(srp), enableSelectionRange); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + default: + t.Fatalf("srp type is %[1]T, not bool: %#[1]v\n", srp) + } + } }) } }) diff --git a/handler.go b/handler.go index 7de73810..65e58b71 100644 --- a/handler.go +++ b/handler.go @@ -5,7 +5,6 @@ package protocol import ( "context" - "encoding/json" "fmt" "go.lsp.dev/jsonrpc2" @@ -21,49 +20,6 @@ func Handlers(handler jsonrpc2.Handler) jsonrpc2.Handler { ) } -// CancelHandler handler of cancelling. -func CancelHandler(handler jsonrpc2.Handler) jsonrpc2.Handler { - handler, canceller := jsonrpc2.CancelHandler(handler) - - h := func(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error { - if req.Method() != MethodCancelRequest { - // TODO(iancottrell): See if we can generate a reply for the request to be cancelled - // at the point of cancellation rather than waiting for gopls to naturally reply. - // To do that, we need to keep track of whether a reply has been sent already and - // be careful about racing between the two paths. - // TODO(iancottrell): Add a test that watches the stream and verifies the response - // for the cancelled request flows. - reply := func(ctx context.Context, resp interface{}, err error) error { - // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest - if ctx.Err() != nil && err == nil { - err = ErrRequestCancelled - } - ctx = xcontext.Detach(ctx) - return reply(ctx, resp, err) - } - return handler(ctx, reply, req) - } - - var params CancelParams - if err := json.Unmarshal(req.Params(), ¶ms); err != nil { - return replyParseError(ctx, reply, err) - } - - switch id := params.ID.(type) { - case float64: - canceller(jsonrpc2.NewNumberID(int64(id))) - case string: - canceller(jsonrpc2.NewStringID(id)) - default: - return replyParseError(ctx, reply, fmt.Errorf("request ID %v malformed", id)) - } - - return reply(ctx, nil, nil) - } - - return h -} - // Call calls method to params and result. func Call(ctx context.Context, conn jsonrpc2.Conn, method string, params, result interface{}) error { id, err := conn.Call(ctx, method, params, result) diff --git a/handler_gojay.go b/handler_gojay.go new file mode 100644 index 00000000..52888fb9 --- /dev/null +++ b/handler_gojay.go @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: Copyright 2021 The Go Language Server Authors +// SPDX-License-Identifier: BSD-3-Clause + +// +build gojay + +package protocol + +import ( + "bytes" + "context" + "fmt" + + "go.lsp.dev/jsonrpc2" + "go.lsp.dev/pkg/xcontext" + + "go.lsp.dev/protocol/internal/gojaypool" +) + +// CancelHandler handler of cancelling. +func CancelHandler(handler jsonrpc2.Handler) jsonrpc2.Handler { + handler, canceller := jsonrpc2.CancelHandler(handler) + + h := func(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error { + if req.Method() != MethodCancelRequest { + // TODO(iancottrell): See if we can generate a reply for the request to be cancelled + // at the point of cancellation rather than waiting for gopls to naturally reply. + // To do that, we need to keep track of whether a reply has been sent already and + // be careful about racing between the two paths. + // TODO(iancottrell): Add a test that watches the stream and verifies the response + // for the cancelled request flows. + reply := func(ctx context.Context, resp interface{}, err error) error { + // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest + if ctx.Err() != nil && err == nil { + err = ErrRequestCancelled + } + ctx = xcontext.Detach(ctx) + return reply(ctx, resp, err) + } + return handler(ctx, reply, req) + } + + dec := gojaypool.BorrowSizedDecoder(bytes.NewReader(req.Params()), len(req.Params())) + defer dec.Release() + + var params CancelParams + if err := dec.DecodeObject(¶ms); err != nil { + return replyParseError(ctx, reply, err) + } + + switch id := params.ID.(type) { + case float64: + canceller(jsonrpc2.NewNumberID(int64(id))) + case string: + canceller(jsonrpc2.NewStringID(id)) + default: + return replyParseError(ctx, reply, fmt.Errorf("request ID %v malformed", id)) + } + + return reply(ctx, nil, nil) + } + + return h +} diff --git a/handler_json.go b/handler_json.go new file mode 100644 index 00000000..1536f15c --- /dev/null +++ b/handler_json.go @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: Copyright 2021 The Go Language Server Authors +// SPDX-License-Identifier: BSD-3-Clause + +// +build !gojay + +package protocol + +import ( + "context" + "encoding/json" + "fmt" + + "go.lsp.dev/jsonrpc2" + "go.lsp.dev/pkg/xcontext" +) + +// CancelHandler handler of cancelling. +func CancelHandler(handler jsonrpc2.Handler) jsonrpc2.Handler { + handler, canceller := jsonrpc2.CancelHandler(handler) + + h := func(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error { + if req.Method() != MethodCancelRequest { + // TODO(iancottrell): See if we can generate a reply for the request to be cancelled + // at the point of cancellation rather than waiting for gopls to naturally reply. + // To do that, we need to keep track of whether a reply has been sent already and + // be careful about racing between the two paths. + // TODO(iancottrell): Add a test that watches the stream and verifies the response + // for the cancelled request flows. + reply := func(ctx context.Context, resp interface{}, err error) error { + // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest + if ctx.Err() != nil && err == nil { + err = ErrRequestCancelled + } + ctx = xcontext.Detach(ctx) + return reply(ctx, resp, err) + } + return handler(ctx, reply, req) + } + + var params CancelParams + if err := json.Unmarshal(req.Params(), ¶ms); err != nil { + return replyParseError(ctx, reply, err) + } + + switch id := params.ID.(type) { + case float64: + canceller(jsonrpc2.NewNumberID(int64(id))) + case string: + canceller(jsonrpc2.NewStringID(id)) + default: + return replyParseError(ctx, reply, fmt.Errorf("request ID %v malformed", id)) + } + + return reply(ctx, nil, nil) + } + + return h +} diff --git a/keys_gojay.go b/keys_gojay.go index 37ed0e4a..086109bc 100644 --- a/keys_gojay.go +++ b/keys_gojay.go @@ -10,6 +10,7 @@ const ( keyActions = "actions" keyActiveParameter = "activeParameter" keyActiveSignature = "activeSignature" + keyActiveSignatureHelp = "activeSignatureHelp" keyAdded = "added" keyAdditionalTextEdits = "additionalTextEdits" keyAlpha = "alpha" @@ -17,6 +18,7 @@ const ( keyApplyEdit = "applyEdit" keyArguments = "arguments" keyBlue = "blue" + keyCancellable = "cancellable" keyCapabilities = "capabilities" keyCh = "ch" keyChange = "change" @@ -24,6 +26,7 @@ const ( keyChanges = "changes" keyCharacter = "character" keyChildren = "children" + keyClientInfo = "clientInfo" keyCode = "code" keyCodeAction = "codeAction" keyCodeActionKind = "codeActionKind" @@ -51,6 +54,7 @@ const ( keyContextSupport = "contextSupport" keyData = "data" keyDeclaration = "declaration" + keyDeclarationProvider = "declarationProvider" keyDefinition = "definition" keyDefinitionProvider = "definitionProvider" keyDeprecated = "deprecated" @@ -103,13 +107,18 @@ const ( keyIncludeDeclaration = "includeDeclaration" keyIncludeText = "includeText" keyInitializationOptions = "initializationOptions" + keyInsertFinalNewline = "insertFinalNewline" keyInsertSpaces = "insertSpaces" keyInsertText = "insertText" keyInsertTextFormat = "insertTextFormat" keyIsIncomplete = "isIncomplete" + keyIsPreferred = "isPreferred" + keyIsPreferredSupport = "isPreferredSupport" + keyIsRetrigger = "isRetrigger" keyItems = "items" keyKind = "kind" keyLabel = "label" + keyLabelOffsetSupport = "labelOffsetSupport" keyLanguage = "language" keyLanguageID = "languageId" keyLine = "line" @@ -132,8 +141,12 @@ const ( keyOriginSelectionRange = "originSelectionRange" keyOverwrite = "overwrite" keyParameterInformation = "parameterInformation" + keyParent = "parent" + keyPartialResultToken = "partialResultToken" keyPattern = "pattern" + keyPercentage = "percentage" keyPosition = "position" + keyPositions = "positions" keyPrepareProvider = "prepareProvider" keyPrepareSupport = "prepareSupport" keyPreselect = "preselect" @@ -158,6 +171,7 @@ const ( keyRenameProvider = "renameProvider" keyResolveProvider = "resolveProvider" keyResourceOperations = "resourceOperations" + keyRetriggerCharacters = "retriggerCharacters" keyRetry = "retry" keyRootPath = "rootPath" keyRootURI = "rootUri" @@ -167,6 +181,7 @@ const ( keySection = "section" keySelectionRange = "selectionRange" keySelectionRangeProvider = "selectionRangeProvider" + keyServerInfo = "serverInfo" keySettings = "settings" keySeverity = "severity" keySignatureHelp = "signatureHelp" @@ -185,6 +200,7 @@ const ( keySynchronization = "synchronization" keySyncKind = "syncKind" keyTabSize = "tabSize" + keyTags = "tags" keyTagSupport = "tagSupport" keyTarget = "target" keyTargetRange = "targetRange" @@ -195,10 +211,15 @@ const ( keyTextDocumentSync = "textDocumentSync" keyTextEdit = "textEdit" keyTitle = "title" + keyToken = "token" + keyTooltip = "tooltip" + keyTooltipSupport = "tooltipSupport" keyTrace = "trace" keyTriggerCharacter = "triggerCharacter" keyTriggerCharacters = "triggerCharacters" keyTriggerKind = "triggerKind" + keyTrimFinalNewlines = "trimFinalNewlines" + keyTrimTrailingWhitespace = "trimTrailingWhitespace" keyType = "type" keyTypeDefinition = "typeDefinition" keyTypeDefinitionProvider = "typeDefinitionProvider" @@ -207,9 +228,13 @@ const ( keyValue = "value" keyValueSet = "valueSet" keyVersion = "version" + keyVersionSupport = "versionSupport" keyWatchers = "watchers" keyWillSave = "willSave" keyWillSaveWaitUntil = "willSaveWaitUntil" + keyWindow = "window" + keyWorkDoneProgress = "workDoneProgress" + keyWorkDoneToken = "workDoneToken" keyWorkspace = "workspace" keyWorkspaceEdit = "workspaceEdit" keyWorkspaceFolders = "workspaceFolders" diff --git a/language.go b/language.go index 9f144f6b..86cccaac 100644 --- a/language.go +++ b/language.go @@ -13,6 +13,8 @@ import ( // CompletionParams params of Completion Request. type CompletionParams struct { TextDocumentPositionParams + WorkDoneProgressParams + PartialResultParams // Context is the completion context. This is only available if the client specifies // to send this using `ClientCapabilities.textDocument.completion.contextSupport === true` @@ -120,6 +122,11 @@ type CompletionItem struct { // characters will be ignored. CommitCharacters []string `json:"commitCharacters,omitempty"` + // Tags is the tag for this completion item. + // + // @since 3.15.0. + Tags []CompletionItemTag `json:"tags,omitempty"` + // Data an data entry field that is preserved on a completion item between // a completion and a completion resolve request. Data interface{} `json:"data,omitempty"` @@ -302,6 +309,28 @@ func (k CompletionItemKind) String() string { } } +// CompletionItemTag completion item tags are extra annotations that tweak the rendering of a completion +// item. +// +// @since 3.15.0. +type CompletionItemTag float64 + +// list of CompletionItemTag. +const ( + // CompletionItemTagDeprecated is the render a completion as obsolete, usually using a strike-out. + CompletionItemTagDeprecated CompletionItemTag = 1 +) + +// String returns a string representation of the type. +func (c CompletionItemTag) String() string { + switch c { + case CompletionItemTagDeprecated: + return "Deprecated" + default: + return strconv.FormatFloat(float64(c), 'f', -10, 64) + } +} + // CompletionRegistrationOptions CompletionRegistration options. type CompletionRegistrationOptions struct { TextDocumentRegistrationOptions @@ -321,6 +350,14 @@ type CompletionRegistrationOptions struct { ResolveProvider bool `json:"resolveProvider,omitempty"` } +// HoverParams params of Hover Request. +// +// @since 3.15.0. +type HoverParams struct { + TextDocumentPositionParams + WorkDoneProgressParams +} + // Hover is the result of a hover request. type Hover struct { // Contents is the hover's content @@ -331,6 +368,82 @@ type Hover struct { Range *Range `json:"range,omitempty"` } +// SignatureHelpParams params of SignatureHelp Request. +// +// @since 3.15.0. +type SignatureHelpParams struct { + TextDocumentPositionParams + WorkDoneProgressParams + + // context is the signature help context. + // + // This is only available if the client specifies to send this using the + // client capability `textDocument.signatureHelp.contextSupport === true`. + // + // @since 3.15.0. + Context *SignatureHelpContext `json:"context,omitempty"` +} + +// SignatureHelpTriggerKind is the how a signature help was triggered. +// +// @since 3.15.0. +type SignatureHelpTriggerKind float64 + +// list of SignatureHelpTriggerKind. +const ( + // SignatureHelpTriggerKindInvoked is the signature help was invoked manually by the user or by a command. + SignatureHelpTriggerKindInvoked SignatureHelpTriggerKind = 1 + + // SignatureHelpTriggerKindTriggerCharacter is the signature help was triggered by a trigger character. + SignatureHelpTriggerKindTriggerCharacter SignatureHelpTriggerKind = 2 + + // SignatureHelpTriggerKindContentChange is the signature help was triggered by the cursor moving or + // by the document content changing. + SignatureHelpTriggerKindContentChange SignatureHelpTriggerKind = 3 +) + +// String returns a string representation of the type. +func (s SignatureHelpTriggerKind) String() string { + switch s { + case SignatureHelpTriggerKindInvoked: + return "Invoked" + case SignatureHelpTriggerKindTriggerCharacter: + return "TriggerCharacter" + case SignatureHelpTriggerKindContentChange: + return "ContentChange" + default: + return strconv.FormatFloat(float64(s), 'f', -10, 64) + } +} + +// SignatureHelpContext is the additional information about the context in which a +// signature help request was triggered. +// +// @since 3.15.0. +type SignatureHelpContext struct { + // TriggerKind is the action that caused signature help to be triggered. + TriggerKind SignatureHelpTriggerKind `json:"triggerKind"` + + // Character that caused signature help to be triggered. + // + // This is undefined when + // TriggerKind != SignatureHelpTriggerKindTriggerCharacter + TriggerCharacter string `json:"triggerCharacter,omitempty"` + + // IsRetrigger is the `true` if signature help was already showing when it was triggered. + // + // Retriggers occur when the signature help is already active and can be + // caused by actions such as typing a trigger character, a cursor move, + // or document content changes. + IsRetrigger bool `json:"isRetrigger"` + + // ActiveSignatureHelp is the currently active SignatureHelp. + // + // The `activeSignatureHelp` has its `SignatureHelp.activeSignature` field + // updated based on the user navigating through available signatures. + ActiveSignatureHelp *SignatureHelp `json:"activeSignatureHelp,omitempty"` +} + // SignatureHelp signature help represents the signature of something // callable. There can be multiple signature but only one // active and only one active parameter. @@ -449,6 +562,9 @@ func (k DocumentHighlightKind) String() string { // DocumentSymbolParams params of Document Symbols Request. type DocumentSymbolParams struct { + WorkDoneProgressParams + PartialResultParams + // TextDocument is the text document. TextDocument TextDocumentIdentifier `json:"textDocument"` } @@ -641,6 +757,9 @@ type SymbolInformation struct { // CodeActionParams params for the CodeActionRequest. type CodeActionParams struct { + WorkDoneProgressParams + PartialResultParams + // TextDocument is the document in which the command was invoked. TextDocument TextDocumentIdentifier `json:"textDocument"` @@ -733,6 +852,15 @@ type CodeAction struct { // Diagnostics is the diagnostics that this code action resolves. Diagnostics []Diagnostic `json:"diagnostics,omitempty"` + // IsPreferred marks this as a preferred action. Preferred actions are used by the `auto fix` command and can be targeted + // by keybindings. + // + // A quick fix should be marked preferred if it properly addresses the underlying error. + // A refactoring should be marked preferred if it is the most reasonable choice of actions to take. + // + // @since 3.15.0. + IsPreferred bool `json:"isPreferred,omitempty"` + // Edit is the workspace edit this code action performs. Edit *WorkspaceEdit `json:"edit,omitempty"` @@ -751,6 +879,9 @@ type CodeActionRegistrationOptions struct { // CodeLensParams params of Code Lens Request. type CodeLensParams struct { + WorkDoneProgressParams + PartialResultParams + // TextDocument is the document to request code lens for. TextDocument TextDocumentIdentifier `json:"textDocument"` } @@ -782,6 +913,9 @@ type CodeLensRegistrationOptions struct { // DocumentLinkParams params of Document Link Request. type DocumentLinkParams struct { + WorkDoneProgressParams + PartialResultParams + // TextDocument is the document to provide document links for. TextDocument TextDocumentIdentifier `json:"textDocument"` } @@ -795,6 +929,15 @@ type DocumentLink struct { // Target is the uri this link points to. If missing a resolve request is sent later. Target uri.URI `json:"target,omitempty"` + // Tooltip is the tooltip text when you hover over this link. + // + // If a tooltip is provided, is will be displayed in a string that includes instructions on how to + // trigger the link, such as `{0} (ctrl + click)`. The specific instructions vary depending on OS, + // user settings, and localization. + // + // @since 3.15.0. + Tooltip string `json:"tooltip,omitempty"` + // Data is a data entry field that is preserved on a document link between a // DocumentLinkRequest and a DocumentLinkResolveRequest. Data interface{} `json:"data,omitempty"` @@ -802,6 +945,9 @@ type DocumentLink struct { // DocumentColorParams params of Document Color Request. type DocumentColorParams struct { + WorkDoneProgressParams + PartialResultParams + // TextDocument is the document to format. TextDocument TextDocumentIdentifier `json:"textDocument"` } @@ -832,6 +978,9 @@ type Color struct { // ColorPresentationParams params of Color Presentation Request. type ColorPresentationParams struct { + WorkDoneProgressParams + PartialResultParams + // TextDocument is the text document. TextDocument TextDocumentIdentifier `json:"textDocument"` @@ -860,6 +1009,8 @@ type ColorPresentation struct { // DocumentFormattingParams params of Document Formatting Request. type DocumentFormattingParams struct { + WorkDoneProgressParams + // Options is the format options. Options FormattingOptions `json:"options"` @@ -874,10 +1025,27 @@ type FormattingOptions struct { // TabSize size of a tab in spaces. TabSize float64 `json:"tabSize"` + + // TrimTrailingWhitespace trim trailing whitespaces on a line. + // + // @since 3.15.0. + TrimTrailingWhitespace bool `json:"trimTrailingWhitespace,omitempty"` + + // InsertFinalNewlines insert a newline character at the end of the file if one does not exist. + // + // @since 3.15.0. + InsertFinalNewline bool `json:"insertFinalNewline,omitempty"` + + // TrimFinalNewlines trim all newlines after the final newline at the end of the file. + // + // @since 3.15.0. + TrimFinalNewlines bool `json:"trimFinalNewlines,omitempty"` } // DocumentRangeFormattingParams params of Document Range Formatting Request. type DocumentRangeFormattingParams struct { + WorkDoneProgressParams + // TextDocument is the document to format. TextDocument TextDocumentIdentifier `json:"textDocument"` @@ -916,11 +1084,8 @@ type DocumentOnTypeFormattingRegistrationOptions struct { // RenameParams params of Rename Request. type RenameParams struct { - // TextDocument is the document to rename. - TextDocument TextDocumentIdentifier `json:"textDocument"` - - // Position is the position at which this request was sent. - Position Position `json:"position"` + TextDocumentPositionParams + PartialResultParams // NewName is the new name of the symbol. If the given name is not valid the // request must return a [ResponseError](#ResponseError) with an @@ -936,10 +1101,17 @@ type RenameRegistrationOptions struct { PrepareProvider bool `json:"prepareProvider,omitempty"` } +// PrepareRenameParams params of PrepareRenameParams request. +// +// @since 3.15.0. +type PrepareRenameParams struct { + TextDocumentPositionParams +} + // FoldingRangeParams params of Folding Range Request. type FoldingRangeParams struct { - // TextDocument is the text document. - TextDocument TextDocumentIdentifier `json:"textDocument"` + TextDocumentPositionParams + PartialResultParams } // FoldingRangeKind is the enum of known range kinds. diff --git a/language_gojay.go b/language_gojay.go index a09c22b1..dccf6307 100644 --- a/language_gojay.go +++ b/language_gojay.go @@ -6,12 +6,16 @@ package protocol -import "github.com/francoispqt/gojay" +import ( + "github.com/francoispqt/gojay" +) // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *CompletionParams) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyTextDocument, &v.TextDocument) enc.ObjectKey(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.ObjectKeyOmitEmpty(keyContext, v.Context) } @@ -25,6 +29,10 @@ func (v *CompletionParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) err return dec.Object(&v.TextDocument) case keyPosition: return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) case keyContext: if v.Context == nil { v.Context = &CompletionContext{} @@ -35,7 +43,7 @@ func (v *CompletionParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) err } // NKeys returns the number of keys to unmarshal. -func (v *CompletionParams) NKeys() int { return 3 } +func (v *CompletionParams) NKeys() int { return 5 } // compile time check whether the CompletionParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -135,6 +143,7 @@ func (v *CompletionItem) MarshalJSONObject(enc *gojay.Encoder) { enc.AddArrayKeyOmitEmpty(keyAdditionalTextEdits, (*TextEdits)(&v.AdditionalTextEdits)) enc.ObjectKeyOmitEmpty(keyCommand, v.Command) enc.AddArrayKeyOmitEmpty(keyCommitCharacters, (*Strings)(&v.CommitCharacters)) + enc.ArrayKeyOmitEmpty(keyTags, (*CompletionItemTags)(&v.Tags)) enc.AddInterfaceKeyOmitEmpty(keyData, v.Data) enc.BoolKeyOmitEmpty(keyDeprecated, v.Deprecated) enc.StringKeyOmitEmpty(keyDetail, v.Detail) @@ -150,7 +159,7 @@ func (v *CompletionItem) MarshalJSONObject(enc *gojay.Encoder) { } // NKeys returns the number of keys to unmarshal. -func (v *CompletionItem) NKeys() int { return 15 } +func (v *CompletionItem) NKeys() int { return 16 } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *CompletionItem) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { @@ -164,6 +173,8 @@ func (v *CompletionItem) UnmarshalJSONObject(dec *gojay.Decoder, k string) error return dec.Object(v.Command) case keyCommitCharacters: return dec.Array((*Strings)(&v.CommitCharacters)) + case keyTags: + return dec.Array((*CompletionItemTags)(&v.Tags)) case keyData: return dec.Interface(&v.Data) case keyDeprecated: @@ -204,6 +215,35 @@ var ( _ gojay.UnmarshalerJSONObject = (*CompletionItem)(nil) ) +// CompletionItemTags represents a slice of CompletionItemTag. +type CompletionItemTags []CompletionItemTag + +// MarshalJSONArray implements gojay.MarshalerJSONArray. +func (v CompletionItemTags) MarshalJSONArray(enc *gojay.Encoder) { + for i := range v { + enc.Float64(float64(v[i])) + } +} + +// IsNil implements gojay.MarshalerJSONArray. +func (v CompletionItemTags) IsNil() bool { return len(v) == 0 } + +// UnmarshalJSONArray implements gojay.UnmarshalerJSONArray. +func (v *CompletionItemTags) UnmarshalJSONArray(dec *gojay.Decoder) error { + var value CompletionItemTag + if err := dec.Float64((*float64)(&value)); err != nil { + return err + } + *v = append(*v, value) + return nil +} + +// compile time check whether the CompletionItemTags implements a gojay.MarshalerJSONArray and gojay.UnmarshalerJSONArray interfaces. +var ( + _ gojay.MarshalerJSONArray = (*CompletionItemTags)(nil) + _ gojay.UnmarshalerJSONArray = (*CompletionItemTags)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *CompletionRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { enc.ArrayKey(keyDocumentSelector, &v.DocumentSelector) @@ -236,6 +276,38 @@ var ( _ gojay.UnmarshalerJSONObject = (*CompletionRegistrationOptions)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *HoverParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *HoverParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *HoverParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *HoverParams) NKeys() int { return 3 } + +// compile time check whether the HoverParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*HoverParams)(nil) + _ gojay.UnmarshalerJSONObject = (*HoverParams)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *Hover) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyContents, &v.Contents) @@ -268,6 +340,82 @@ var ( _ gojay.UnmarshalerJSONObject = (*Hover)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *SignatureHelpParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKeyOmitEmpty(keyTextDocument, &v.TextDocument) + enc.ObjectKeyOmitEmpty(keyPosition, &v.Position) + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + enc.ObjectKeyOmitEmpty(keyContext, v.Context) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *SignatureHelpParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *SignatureHelpParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyContext: + if v.Context == nil { + v.Context = &SignatureHelpContext{} + } + return dec.Object(v.Context) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *SignatureHelpParams) NKeys() int { return 4 } + +// compile time check whether the SignatureHelpParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*SignatureHelpParams)(nil) + _ gojay.UnmarshalerJSONObject = (*SignatureHelpParams)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *SignatureHelpContext) MarshalJSONObject(enc *gojay.Encoder) { + enc.Float64Key(keyTriggerKind, float64(v.TriggerKind)) + enc.StringKeyOmitEmpty(keyTriggerCharacter, v.TriggerCharacter) + enc.BoolKey(keyIsRetrigger, v.IsRetrigger) + enc.ObjectKeyOmitEmpty(keyActiveSignatureHelp, v.ActiveSignatureHelp) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *SignatureHelpContext) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *SignatureHelpContext) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTriggerKind: + return dec.Float64((*float64)(&v.TriggerKind)) + case keyTriggerCharacter: + return dec.String(&v.TriggerCharacter) + case keyIsRetrigger: + return dec.Bool(&v.IsRetrigger) + case keyActiveSignatureHelp: + if v.ActiveSignatureHelp == nil { + v.ActiveSignatureHelp = &SignatureHelp{} + } + return dec.Object(v.ActiveSignatureHelp) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *SignatureHelpContext) NKeys() int { return 4 } + +// compile time check whether the SignatureHelpContext implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*SignatureHelpContext)(nil) + _ gojay.UnmarshalerJSONObject = (*SignatureHelpContext)(nil) +) + // SignatureInformations represents a slice of SignatureInformation. type SignatureInformations []SignatureInformation @@ -510,6 +658,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *DocumentSymbolParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.ObjectKey(keyTextDocument, &v.TextDocument) } @@ -518,14 +668,19 @@ func (v *DocumentSymbolParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *DocumentSymbolParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyTextDocument { + switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + case keyTextDocument: return dec.Object(&v.TextDocument) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *DocumentSymbolParams) NKeys() int { return 1 } +func (v *DocumentSymbolParams) NKeys() int { return 3 } // compile time check whether the DocumentSymbolParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -611,6 +766,7 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *DocumentFormattingParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) enc.ObjectKey(keyOptions, &v.Options) enc.ObjectKey(keyTextDocument, &v.TextDocument) } @@ -621,6 +777,8 @@ func (v *DocumentFormattingParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *DocumentFormattingParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) case keyOptions: return dec.Object(&v.Options) case keyTextDocument: @@ -630,7 +788,7 @@ func (v *DocumentFormattingParams) UnmarshalJSONObject(dec *gojay.Decoder, k str } // NKeys returns the number of keys to unmarshal. -func (v *DocumentFormattingParams) NKeys() int { return 2 } +func (v *DocumentFormattingParams) NKeys() int { return 3 } // compile time check whether the DocumentFormattingParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -678,6 +836,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *CodeActionParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.ObjectKey(keyTextDocument, &v.TextDocument) enc.ObjectKey(keyContext, &v.Context) enc.ObjectKey(keyRange, &v.Range) @@ -689,6 +849,10 @@ func (v *CodeActionParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *CodeActionParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) case keyTextDocument: return dec.Object(&v.TextDocument) case keyContext: @@ -700,7 +864,7 @@ func (v *CodeActionParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) err } // NKeys returns the number of keys to unmarshal. -func (v *CodeActionParams) NKeys() int { return 3 } +func (v *CodeActionParams) NKeys() int { return 5 } // compile time check whether the CodeActionParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -742,6 +906,7 @@ func (v *CodeAction) MarshalJSONObject(enc *gojay.Encoder) { enc.StringKey(keyTitle, v.Title) enc.StringKeyOmitEmpty(keyKind, string(v.Kind)) enc.ArrayKeyOmitEmpty(keyDiagnostics, Diagnostics(v.Diagnostics)) + enc.BoolKeyOmitEmpty(keyIsPreferred, v.IsPreferred) enc.ObjectKeyOmitEmpty(keyEdit, v.Edit) enc.ObjectKeyOmitEmpty(keyCommand, v.Command) } @@ -758,6 +923,8 @@ func (v *CodeAction) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { return dec.String((*string)(&v.Kind)) case keyDiagnostics: return dec.Array((*Diagnostics)(&v.Diagnostics)) + case keyIsPreferred: + return dec.Bool(&v.IsPreferred) case keyEdit: if v.Edit == nil { v.Edit = &WorkspaceEdit{} @@ -773,7 +940,7 @@ func (v *CodeAction) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { } // NKeys returns the number of keys to unmarshal. -func (v *CodeAction) NKeys() int { return 5 } +func (v *CodeAction) NKeys() int { return 6 } // compile time check whether the CodeAction implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -812,6 +979,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *CodeLensParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.ObjectKey(keyTextDocument, &v.TextDocument) } @@ -820,14 +989,19 @@ func (v *CodeLensParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *CodeLensParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyTextDocument { + switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + case keyTextDocument: return dec.Object(&v.TextDocument) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *CodeLensParams) NKeys() int { return 1 } +func (v *CodeLensParams) NKeys() int { return 3 } // compile time check whether the CodeLensParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -901,6 +1075,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *DocumentLinkParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.ObjectKey(keyTextDocument, &v.TextDocument) } @@ -909,14 +1085,19 @@ func (v *DocumentLinkParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *DocumentLinkParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyTextDocument { + switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + case keyTextDocument: return dec.Object(&v.TextDocument) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *DocumentLinkParams) NKeys() int { return 1 } +func (v *DocumentLinkParams) NKeys() int { return 3 } // compile time check whether the DocumentLinkParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -928,6 +1109,7 @@ var ( func (v *DocumentLink) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyRange, &v.Range) enc.StringKeyOmitEmpty(keyTarget, string(v.Target)) + enc.StringKeyOmitEmpty(keyTooltip, v.Tooltip) enc.AddInterfaceKeyOmitEmpty(keyData, v.Data) } @@ -941,6 +1123,8 @@ func (v *DocumentLink) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { return dec.Object(&v.Range) case keyTarget: return dec.String((*string)(&v.Target)) + case keyTooltip: + return dec.String(&v.Tooltip) case keyData: return dec.Interface(&v.Data) } @@ -948,7 +1132,7 @@ func (v *DocumentLink) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { } // NKeys returns the number of keys to unmarshal. -func (v *DocumentLink) NKeys() int { return 3 } +func (v *DocumentLink) NKeys() int { return 4 } // compile time check whether the DocumentLink implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -958,6 +1142,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *DocumentColorParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.ObjectKey(keyTextDocument, &v.TextDocument) } @@ -966,14 +1152,19 @@ func (v *DocumentColorParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *DocumentColorParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyTextDocument { + switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + case keyTextDocument: return dec.Object(&v.TextDocument) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *DocumentColorParams) NKeys() int { return 1 } +func (v *DocumentColorParams) NKeys() int { return 3 } // compile time check whether the DocumentColorParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1047,6 +1238,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *ColorPresentationParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.ObjectKey(keyTextDocument, &v.TextDocument) enc.ObjectKey(keyColor, &v.Color) enc.ObjectKey(keyRange, &v.Range) @@ -1058,6 +1251,10 @@ func (v *ColorPresentationParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *ColorPresentationParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) case keyTextDocument: return dec.Object(&v.TextDocument) case keyColor: @@ -1069,7 +1266,7 @@ func (v *ColorPresentationParams) UnmarshalJSONObject(dec *gojay.Decoder, k stri } // NKeys returns the number of keys to unmarshal. -func (v *ColorPresentationParams) NKeys() int { return 3 } +func (v *ColorPresentationParams) NKeys() int { return 5 } // compile time check whether the ColorPresentationParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1116,6 +1313,9 @@ var ( func (v *FormattingOptions) MarshalJSONObject(enc *gojay.Encoder) { enc.BoolKey(keyInsertSpaces, v.InsertSpaces) enc.Float64Key(keyTabSize, v.TabSize) + enc.BoolKeyOmitEmpty(keyTrimTrailingWhitespace, v.TrimTrailingWhitespace) + enc.BoolKeyOmitEmpty(keyInsertFinalNewline, v.InsertFinalNewline) + enc.BoolKeyOmitEmpty(keyTrimFinalNewlines, v.TrimFinalNewlines) } // IsNil returns wether the structure is nil value or not. @@ -1128,12 +1328,18 @@ func (v *FormattingOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) er return dec.Bool(&v.InsertSpaces) case keyTabSize: return dec.Float64(&v.TabSize) + case keyTrimTrailingWhitespace: + return dec.Bool(&v.TrimTrailingWhitespace) + case keyInsertFinalNewline: + return dec.Bool(&v.InsertFinalNewline) + case keyTrimFinalNewlines: + return dec.Bool(&v.TrimFinalNewlines) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *FormattingOptions) NKeys() int { return 2 } +func (v *FormattingOptions) NKeys() int { return 5 } // compile time check whether the FormattingOptions implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1143,6 +1349,7 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *DocumentRangeFormattingParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) enc.ObjectKey(keyTextDocument, &v.TextDocument) enc.ObjectKey(keyRange, &v.Range) enc.ObjectKey(keyOptions, &v.Options) @@ -1154,6 +1361,8 @@ func (v *DocumentRangeFormattingParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *DocumentRangeFormattingParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) case keyTextDocument: return dec.Object(&v.TextDocument) case keyRange: @@ -1165,7 +1374,7 @@ func (v *DocumentRangeFormattingParams) UnmarshalJSONObject(dec *gojay.Decoder, } // NKeys returns the number of keys to unmarshal. -func (v *DocumentRangeFormattingParams) NKeys() int { return 3 } +func (v *DocumentRangeFormattingParams) NKeys() int { return 4 } // compile time check whether the DocumentRangeFormattingParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1244,6 +1453,7 @@ var ( func (v *RenameParams) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyTextDocument, &v.TextDocument) enc.ObjectKey(keyPosition, &v.Position) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.StringKey(keyNewName, v.NewName) } @@ -1257,6 +1467,8 @@ func (v *RenameParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { return dec.Object(&v.TextDocument) case keyPosition: return dec.Object(&v.Position) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) case keyNewName: return dec.String(&v.NewName) } @@ -1264,7 +1476,7 @@ func (v *RenameParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { } // NKeys returns the number of keys to unmarshal. -func (v *RenameParams) NKeys() int { return 3 } +func (v *RenameParams) NKeys() int { return 4 } // compile time check whether the RenameParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -1301,9 +1513,40 @@ var ( _ gojay.UnmarshalerJSONObject = (*RenameRegistrationOptions)(nil) ) +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *PrepareRenameParams) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKey(keyTextDocument, &v.TextDocument) + enc.ObjectKey(keyPosition, &v.Position) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *PrepareRenameParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *PrepareRenameParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *PrepareRenameParams) NKeys() int { return 2 } + +// compile time check whether the PrepareRenameParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*PrepareRenameParams)(nil) + _ gojay.UnmarshalerJSONObject = (*PrepareRenameParams)(nil) +) + // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *FoldingRangeParams) MarshalJSONObject(enc *gojay.Encoder) { enc.ObjectKey(keyTextDocument, &v.TextDocument) + enc.ObjectKey(keyPosition, &v.Position) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) } // IsNil returns wether the structure is nil value or not. @@ -1311,14 +1554,19 @@ func (v *FoldingRangeParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *FoldingRangeParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyTextDocument { + switch k { + case keyTextDocument: return dec.Object(&v.TextDocument) + case keyPosition: + return dec.Object(&v.Position) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *FoldingRangeParams) NKeys() int { return 1 } +func (v *FoldingRangeParams) NKeys() int { return 3 } // compile time check whether the FoldingRangeParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( diff --git a/language_gojay_test.go b/language_gojay_test.go index a1bb80f4..30847b70 100644 --- a/language_gojay_test.go +++ b/language_gojay_test.go @@ -30,8 +30,16 @@ func TestCompletionRegistrationOptions(t *testing.T) { testCompletionRegistrationOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestHoverParams(t *testing.T) { + testHoverParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestHover(t *testing.T) { testHover(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestSignatureHelpParams(t *testing.T) { + testSignatureHelpParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestSignatureHelp(t *testing.T) { testSignatureHelp(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } func TestSignatureInformation(t *testing.T) { @@ -140,6 +148,10 @@ func TestRenameRegistrationOptions(t *testing.T) { testRenameRegistrationOptions(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } +func TestPrepareRenameParams(t *testing.T) { + testPrepareRenameParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + func TestFoldingRangeParams(t *testing.T) { testFoldingRangeParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } diff --git a/language_json_test.go b/language_json_test.go index 6fa58b78..a5c9d8ae 100644 --- a/language_json_test.go +++ b/language_json_test.go @@ -29,8 +29,16 @@ func TestCompletionRegistrationOptions(t *testing.T) { testCompletionRegistrationOptions(t, json.Marshal, json.Unmarshal) } +func TestHoverParams(t *testing.T) { + testHoverParams(t, json.Marshal, json.Unmarshal) +} + func TestHover(t *testing.T) { testHover(t, json.Marshal, json.Unmarshal) } +func TestSignatureHelpParams(t *testing.T) { + testSignatureHelpParams(t, json.Marshal, json.Unmarshal) +} + func TestSignatureHelp(t *testing.T) { testSignatureHelp(t, json.Marshal, json.Unmarshal) } func TestSignatureInformation(t *testing.T) { @@ -133,6 +141,10 @@ func TestRenameRegistrationOptions(t *testing.T) { testRenameRegistrationOptions(t, json.Marshal, json.Unmarshal) } +func TestPrepareRenameParams(t *testing.T) { + testPrepareRenameParams(t, json.Marshal, json.Unmarshal) +} + func TestFoldingRangeParams(t *testing.T) { testFoldingRangeParams(t, json.Marshal, json.Unmarshal) } diff --git a/language_test.go b/language_test.go index 84fbde15..f56a3beb 100644 --- a/language_test.go +++ b/language_test.go @@ -9,14 +9,19 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "go.lsp.dev/uri" ) func testCompletionParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":25,"character":1},"context":{"triggerCharacter":".","triggerKind":1}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":2,"character":0},"context":{"triggerCharacter":".","triggerKind":1}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","context":{"triggerCharacter":".","triggerKind":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":2,"character":0},"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","context":{"triggerCharacter":".","triggerKind":1}}` ) wantType := CompletionParams{ TextDocumentPositionParams: TextDocumentPositionParams{ @@ -28,6 +33,12 @@ func testCompletionParams(t *testing.T, marshal marshalFunc, unmarshal unmarshal Character: 1, }, }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, Context: &CompletionContext{ TriggerCharacter: ".", TriggerKind: Invoked, @@ -107,9 +118,21 @@ func testCompletionParams(t *testing.T, marshal marshalFunc, unmarshal unmarshal t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -247,7 +270,7 @@ func testCompletionContext(t *testing.T, marshal marshalFunc, unmarshal unmarsha func testCompletionList(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"isIncomplete":true,"items":[{"detail":"string","documentation":"Detail a human-readable string with additional information about this item, like type or symbol information.","filterText":"Detail","insertTextFormat":2,"kind":5,"label":"Detail","preselect":true,"sortText":"00000","textEdit":{"range":{"start":{"line":255,"character":4},"end":{"line":255,"character":10}},"newText":"Detail: ${1:},"}}]}` + want = `{"isIncomplete":true,"items":[{"tags":[1],"detail":"string","documentation":"Detail a human-readable string with additional information about this item, like type or symbol information.","filterText":"Detail","insertTextFormat":2,"kind":5,"label":"Detail","preselect":true,"sortText":"00000","textEdit":{"range":{"start":{"line":255,"character":4},"end":{"line":255,"character":10}},"newText":"Detail: ${1:},"}}]}` wantInvalid = `{"isIncomplete":false,"items":[]}` ) wantType := CompletionList{ @@ -257,16 +280,19 @@ func testCompletionList(t *testing.T, marshal marshalFunc, unmarshal unmarshalFu AdditionalTextEdits: nil, Command: nil, CommitCharacters: nil, - Deprecated: false, - Detail: "string", - Documentation: "Detail a human-readable string with additional information about this item, like type or symbol information.", - FilterText: "Detail", - InsertText: "", - InsertTextFormat: TextFormatSnippet, - Kind: FieldCompletion, - Label: "Detail", - Preselect: true, - SortText: "00000", + Tags: []CompletionItemTag{ + CompletionItemTagDeprecated, + }, + Deprecated: false, + Detail: "string", + Documentation: "Detail a human-readable string with additional information about this item, like type or symbol information.", + FilterText: "Detail", + InsertText: "", + InsertTextFormat: TextFormatSnippet, + Kind: FieldCompletion, + Label: "Detail", + Preselect: true, + SortText: "00000", TextEdit: &TextEdit{ Range: Range{ Start: Position{ @@ -401,7 +427,7 @@ func TestInsertTextFormat_String(t *testing.T) { func testCompletionItem(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"additionalTextEdits":[{"range":{"start":{"line":255,"character":4},"end":{"line":255,"character":10}},"newText":"Detail: ${1:},"}],"command":{"title":"exec echo","command":"echo","arguments":["hello"]},"commitCharacters":["a"],"data":"testData","deprecated":true,"detail":"string","documentation":"Detail a human-readable string with additional information about this item, like type or symbol information.","filterText":"Detail","insertText":"testInsert","insertTextFormat":2,"kind":5,"label":"Detail","preselect":true,"sortText":"00000","textEdit":{"range":{"start":{"line":255,"character":4},"end":{"line":255,"character":10}},"newText":"Detail: ${1:},"}}` + want = `{"additionalTextEdits":[{"range":{"start":{"line":255,"character":4},"end":{"line":255,"character":10}},"newText":"Detail: ${1:},"}],"command":{"title":"exec echo","command":"echo","arguments":["hello"]},"commitCharacters":["a"],"tags":[1],"data":"testData","deprecated":true,"detail":"string","documentation":"Detail a human-readable string with additional information about this item, like type or symbol information.","filterText":"Detail","insertText":"testInsert","insertTextFormat":2,"kind":5,"label":"Detail","preselect":true,"sortText":"00000","textEdit":{"range":{"start":{"line":255,"character":4},"end":{"line":255,"character":10}},"newText":"Detail: ${1:},"}}` wantNilAll = `{"label":"Detail"}` wantInvalid = `{"items":[]}` ) @@ -427,6 +453,9 @@ func testCompletionItem(t *testing.T, marshal marshalFunc, unmarshal unmarshalFu Arguments: []interface{}{"hello"}, }, CommitCharacters: []string{"a"}, + Tags: []CompletionItemTag{ + CompletionItemTagDeprecated, + }, Data: "testData", Deprecated: true, Detail: "string", @@ -700,6 +729,35 @@ func TestCompletionItemKind_String(t *testing.T) { } } +func TestCompletionItemTag_String(t *testing.T) { + tests := []struct { + name string + k CompletionItemTag + want string + }{ + { + name: "Deprecated", + k: CompletionItemTagDeprecated, + want: "Deprecated", + }, + { + name: "Unknown", + k: CompletionItemTag(0), + want: "0", + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + if got := tt.k.String(); got != tt.want { + t.Errorf("CompletionItemTag.String() = %v, want %v", got, tt.want) + } + }) + } +} + func testCompletionRegistrationOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( want = `{"documentSelector":[{"language":"go","scheme":"file","pattern":"*.go"}],"triggerCharacters":["."],"resolveProvider":true}` @@ -800,6 +858,149 @@ func testCompletionRegistrationOptions(t *testing.T, marshal marshalFunc, unmars }) } +func testHoverParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + invalidWorkDoneToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `"}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + invalidWorkDoneToken + `"}` + ) + wantType := HoverParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + } + wantTypeNilAll := HoverParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field HoverParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNilAll, + want: wantNilAll, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want HoverParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNilAll, + want: wantTypeNilAll, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got HoverParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{})); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + }) + } + }) +} + func testHover(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( want = `{"contents":{"kind":"markdown","value":"example value"},"range":{"start":{"line":255,"character":4},"end":{"line":255,"character":10}}}` @@ -903,6 +1104,208 @@ func testHover(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { }) } +func testSignatureHelpParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + invalidWorkDoneToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1},"workDoneToken":"` + wantWorkDoneToken + `","context":{"triggerKind":1,"triggerCharacter":".","isRetrigger":true,"activeSignatureHelp":{"signatures":[{"documentationFormat":["markdown"],"parameterInformation":{"label":"test label","documentation":"test documentation"}}],"activeParameter":10,"activeSignature":5}}}` + wantNilAll = `{"textDocument":{"uri":"file:///path/to/basic.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/basic_gen.go"},"position":{"line":2,"character":1},"workDoneToken":"` + invalidWorkDoneToken + `","context":{"triggerKind":0,"triggerCharacter":"aaa","isRetrigger":false,"activeSignatureHelp":{"signatures":[{"documentationFormat":["markdown"],"parameterInformation":{"label":"test label","documentation":"test documentation"}}],"activeParameter":1,"activeSignature":0}}}` + ) + wantType := SignatureHelpParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + Context: &SignatureHelpContext{ + TriggerKind: SignatureHelpTriggerKindInvoked, + TriggerCharacter: ".", + IsRetrigger: true, + ActiveSignatureHelp: &SignatureHelp{ + Signatures: []SignatureInformation{ + { + DocumentationFormat: []MarkupKind{ + Markdown, + }, + ParameterInformation: &ParameterInformation{ + Label: "test label", + Documentation: "test documentation", + }, + }, + }, + ActiveParameter: 10, + ActiveSignature: 5, + }, + }, + } + wantTypeNilAll := SignatureHelpParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/basic.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field SignatureHelpParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantTypeNilAll, + want: wantNilAll, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + field string + want SignatureHelpParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "ValidNilAll", + field: wantNilAll, + want: wantTypeNilAll, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got SignatureHelpParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{})); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + }) + } + }) +} + +func TestSignatureHelpTriggerKind_String(t *testing.T) { + tests := []struct { + name string + k SignatureHelpTriggerKind + want string + }{ + { + name: "Invoked", + k: SignatureHelpTriggerKindInvoked, + want: "Invoked", + }, + { + name: "TriggerCharacter", + k: SignatureHelpTriggerKindTriggerCharacter, + want: "TriggerCharacter", + }, + { + name: "ContentChange", + k: SignatureHelpTriggerKindContentChange, + want: "ContentChange", + }, + { + name: "Unknown", + k: SignatureHelpTriggerKind(0), + want: "0", + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + if got := tt.k.String(); got != tt.want { + t.Errorf("SignatureHelpTriggerKind.String() = %v, want %v", got, tt.want) + } + }) + } +} + func testSignatureHelp(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( want = `{"signatures":[{"documentationFormat":["markdown"],"parameterInformation":{"label":"test label","documentation":"test documentation"}}],"activeParameter":10,"activeSignature":5}` @@ -1641,14 +2044,24 @@ func TestDocumentHighlightKind_String(t *testing.T) { func testDocumentSymbolParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/nottest.go"}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" ) wantType := DocumentSymbolParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, TextDocument: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, } + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","textDocument":{"uri":"file:///path/to/test.go"}}` + wantInvalid = `{"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","textDocument":{"uri":"file:///path/to/nottest.go"}}` + ) t.Run("Marshal", func(t *testing.T) { tests := []struct { @@ -1723,9 +2136,21 @@ func testDocumentSymbolParams(t *testing.T, marshal marshalFunc, unmarshal unmar t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -2167,10 +2592,20 @@ func testSymbolInformation(t *testing.T, marshal marshalFunc, unmarshal unmarsha func testCodeActionParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"},"context":{"diagnostics":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"only":["quickfix"]},"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":6}}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/test.go"},"context":{"diagnostics":[{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"only":["quickfix"]},"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","textDocument":{"uri":"file:///path/to/test.go"},"context":{"diagnostics":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"only":["quickfix"]},"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":6}}}` + wantInvalid = `{"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","textDocument":{"uri":"file:///path/to/test.go"},"context":{"diagnostics":[{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"only":["quickfix"]},"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}}}` ) wantType := CodeActionParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, TextDocument: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, @@ -2300,9 +2735,21 @@ func testCodeActionParams(t *testing.T, marshal marshalFunc, unmarshal unmarshal t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -2497,8 +2944,8 @@ func testCodeActionContext(t *testing.T, marshal marshalFunc, unmarshal unmarsha func testCodeAction(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"title":"Refactoring","kind":"refactor.rewrite","diagnostics":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"edit":{"changes":{"file:///path/to/test.go":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"newText":"foo bar"}]},"documentChanges":[{"textDocument":{"uri":"file:///path/to/test.go","version":10},"edits":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"newText":"foo bar"}]}]},"command":{"title":"rewrite","command":"rewriter","arguments":["-w"]}}` - wantInvalid = `{"title":"Refactoring","kind":"refactor","diagnostics":[{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"edit":{"changes":{"file:///path/to/test.go":[{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"newText":"foo bar"}]},"documentChanges":[{"textDocument":{"uri":"file:///path/to/test.go","version":10},"edits":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"newText":"foo bar"}]}]},"command":{"title":"rewrite","command":"rewriter","arguments":["-w"]}}` + want = `{"title":"Refactoring","kind":"refactor.rewrite","diagnostics":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"isPreferred":true,"edit":{"changes":{"file:///path/to/test.go":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"newText":"foo bar"}]},"documentChanges":[{"textDocument":{"uri":"file:///path/to/test.go","version":10},"edits":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"newText":"foo bar"}]}]},"command":{"title":"rewrite","command":"rewriter","arguments":["-w"]}}` + wantInvalid = `{"title":"Refactoring","kind":"refactor","diagnostics":[{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"severity":1,"code":"foo/bar","source":"test foo bar","message":"foo bar","relatedInformation":[{"location":{"uri":"file:///path/to/test.go","range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}},"message":"test.go"}]}],"isPreferred":false,"edit":{"changes":{"file:///path/to/test.go":[{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"newText":"foo bar"}]},"documentChanges":[{"textDocument":{"uri":"file:///path/to/test.go","version":10},"edits":[{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"newText":"foo bar"}]}]},"command":{"title":"rewrite","command":"rewriter","arguments":["-w"]}}` ) wantType := CodeAction{ Title: "Refactoring", @@ -2539,6 +2986,7 @@ func testCodeAction(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) }, }, }, + IsPreferred: true, Edit: &WorkspaceEdit{ Changes: map[uri.URI][]TextEdit{ uri.File("/path/to/test.go"): { @@ -2563,7 +3011,7 @@ func testCodeAction(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) TextDocumentIdentifier: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, Edits: []TextEdit{ { @@ -2782,10 +3230,20 @@ func testCodeActionRegistrationOptions(t *testing.T, marshal marshalFunc, unmars func testCodeLensParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","textDocument":{"uri":"file:///path/to/test.go"}}` + wantInvalid = `{"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","textDocument":{"uri":"file:///path/to/invalid.go"}}` ) wantType := CodeLensParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, TextDocument: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, @@ -2864,9 +3322,21 @@ func testCodeLensParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFu t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -3141,11 +3611,21 @@ func testCodeLensRegistrationOptions(t *testing.T, marshal marshalFunc, unmarsha func testDocumentLinkParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","textDocument":{"uri":"file:///path/to/test.go"}}` wantNilAll = `{"textDocument":{"uri":"file:///path/to/test.go"}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"}}` + wantInvalid = `{"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","textDocument":{"uri":"file:///path/to/invalid.go"}}` ) wantType := DocumentLinkParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, TextDocument: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, @@ -3224,9 +3704,21 @@ func testDocumentLinkParams(t *testing.T, marshal marshalFunc, unmarshal unmarsh t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -3234,9 +3726,9 @@ func testDocumentLinkParams(t *testing.T, marshal marshalFunc, unmarshal unmarsh func testDocumentLink(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"target":"file:///path/to/test.go","data":"testData"}` + want = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"target":"file:///path/to/test.go","tooltip":"testTooltip","data":"testData"}` wantNilAll = `{"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}}` - wantInvalid = `{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"target":"file:///path/to/test.go","data":"testData"}` + wantInvalid = `{"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"target":"file:///path/to/test.go","tooltip":"invalidTooltip","data":"testData"}` ) wantType := DocumentLink{ Range: Range{ @@ -3249,8 +3741,9 @@ func testDocumentLink(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc Character: 3, }, }, - Target: uri.File("/path/to/test.go"), - Data: "testData", + Target: uri.File("/path/to/test.go"), + Tooltip: "testTooltip", + Data: "testData", } wantTypeNilAll := DocumentLink{ Range: Range{ @@ -3362,10 +3855,20 @@ func testDocumentLink(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc func testDocumentColorParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","textDocument":{"uri":"file:///path/to/test.go"}}` + wantInvalid = `{"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","textDocument":{"uri":"file:///path/to/invalid.go"}}` ) wantType := DocumentColorParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, TextDocument: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, @@ -3444,9 +3947,21 @@ func testDocumentColorParams(t *testing.T, marshal marshalFunc, unmarshal unmars t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -3652,10 +4167,20 @@ func testColor(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { func testColorPresentationParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"},"color":{"alpha":1,"blue":0.2,"green":0.3,"red":0.4},"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/test.go"},"color":{"alpha":0,"blue":0.4,"green":0.3,"red":0.2},"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","textDocument":{"uri":"file:///path/to/test.go"},"color":{"alpha":1,"blue":0.2,"green":0.3,"red":0.4},"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}}}` + wantInvalid = `{"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","textDocument":{"uri":"file:///path/to/test.go"},"color":{"alpha":0,"blue":0.4,"green":0.3,"red":0.2},"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}}}` ) wantType := ColorPresentationParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, TextDocument: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, @@ -3750,9 +4275,21 @@ func testColorPresentationParams(t *testing.T, marshal marshalFunc, unmarshal un t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -3896,10 +4433,17 @@ func testColorPresentation(t *testing.T, marshal marshalFunc, unmarshal unmarsha func testDocumentFormattingParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"options":{"insertSpaces":true,"tabSize":4},"textDocument":{"uri":"file:///path/to/test.go"}}` - wantInvalid = `{"options":{"insertSpaces":false,"tabSize":2},"textDocument":{"uri":"file:///path/to/invalid.go"}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + invalidWorkDoneToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","options":{"insertSpaces":true,"tabSize":4},"textDocument":{"uri":"file:///path/to/test.go"}}` + wantInvalid = `{"workDoneToken":"` + invalidWorkDoneToken + `","options":{"insertSpaces":false,"tabSize":2},"textDocument":{"uri":"file:///path/to/invalid.go"}}` ) wantType := DocumentFormattingParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, Options: FormattingOptions{ InsertSpaces: true, TabSize: 4, @@ -3982,9 +4526,15 @@ func testDocumentFormattingParams(t *testing.T, marshal marshalFunc, unmarshal u t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -3992,12 +4542,15 @@ func testDocumentFormattingParams(t *testing.T, marshal marshalFunc, unmarshal u func testFormattingOptions(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"insertSpaces":true,"tabSize":4}` - wantInvalid = `{"insertSpaces":false,"tabSize":2}` + want = `{"insertSpaces":true,"tabSize":4,"trimTrailingWhitespace":true,"insertFinalNewline":true,"trimFinalNewlines":true}` + wantInvalid = `{"insertSpaces":false,"tabSize":2,"trimTrailingWhitespace":false,"insertFinalNewline":false,"trimFinalNewlines":false}` ) wantType := FormattingOptions{ - InsertSpaces: true, - TabSize: 4, + InsertSpaces: true, + TabSize: 4, + TrimTrailingWhitespace: true, + InsertFinalNewline: true, + TrimFinalNewlines: true, } t.Run("Marshal", func(t *testing.T) { @@ -4083,10 +4636,17 @@ func testFormattingOptions(t *testing.T, marshal marshalFunc, unmarshal unmarsha func testDocumentRangeFormattingParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"},"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"options":{"insertSpaces":true,"tabSize":4}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"},"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"options":{"insertSpaces":false,"tabSize":2}}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + invalidWorkDoneToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","textDocument":{"uri":"file:///path/to/test.go"},"range":{"start":{"line":25,"character":1},"end":{"line":27,"character":3}},"options":{"insertSpaces":true,"tabSize":4}}` + wantInvalid = `{"workDoneToken":"` + invalidWorkDoneToken + `","textDocument":{"uri":"file:///path/to/invalid.go"},"range":{"start":{"line":2,"character":1},"end":{"line":3,"character":2}},"options":{"insertSpaces":false,"tabSize":2}}` ) wantType := DocumentRangeFormattingParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, TextDocument: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, @@ -4179,9 +4739,15 @@ func testDocumentRangeFormattingParams(t *testing.T, marshal marshalFunc, unmars t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -4395,16 +4961,25 @@ func testDocumentOnTypeFormattingRegistrationOptions(t *testing.T, marshal marsh func testRenameParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":25,"character":1},"newName":"newNameSymbol"}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"},"position":{"line":2,"character":1},"newName":"invalidSymbol"}` + wantPartialResultToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + invalidPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":25,"character":1},"partialResultToken":"` + wantPartialResultToken + `","newName":"newNameSymbol"}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"},"position":{"line":2,"character":1},"partialResultToken":"` + invalidPartialResultToken + `","newName":"invalidSymbol"}` ) wantType := RenameParams{ - TextDocument: TextDocumentIdentifier{ - URI: uri.File("/path/to/test.go"), + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/test.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, }, - Position: Position{ - Line: 25, - Character: 1, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), }, NewName: "newNameSymbol", } @@ -4482,9 +5057,15 @@ func testRenameParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -4625,14 +5206,125 @@ func testRenameRegistrationOptions(t *testing.T, marshal marshalFunc, unmarshal }) } +func testPrepareRenameParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + want = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":25,"character":1}}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"},"position":{"line":2,"character":0}}` + ) + wantType := PrepareRenameParams{ + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/test.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + } + + t.Run("Marshal", func(t *testing.T) { + tests := []struct { + name string + field PrepareRenameParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + tests := []struct { + name string + field string + want PrepareRenameParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got PrepareRenameParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(PartialResultParams{})); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + func testFoldingRangeParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"textDocument":{"uri":"file:///path/to/test.go"}}` - wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"}}` + wantPartialResultToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + invalidPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"textDocument":{"uri":"file:///path/to/test.go"},"position":{"line":25,"character":1},"partialResultToken":"` + wantPartialResultToken + `"}` + wantInvalid = `{"textDocument":{"uri":"file:///path/to/invalid.go"},"position":{"line":2,"character":0},"partialResultToken":"` + invalidPartialResultToken + `"}` ) wantType := FoldingRangeParams{ - TextDocument: TextDocumentIdentifier{ - URI: uri.File("/path/to/test.go"), + TextDocumentPositionParams: TextDocumentPositionParams{ + TextDocument: TextDocumentIdentifier{ + URI: uri.File("/path/to/test.go"), + }, + Position: Position{ + Line: 25, + Character: 1, + }, + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), }, } @@ -4709,9 +5401,15 @@ func testFoldingRangeParams(t *testing.T, marshal marshalFunc, unmarshal unmarsh t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) diff --git a/progress.go b/progress.go new file mode 100644 index 00000000..4de1c4b7 --- /dev/null +++ b/progress.go @@ -0,0 +1,198 @@ +// Copyright 2021 The Go Language Server Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package protocol + +import ( + "encoding/json" + "fmt" +) + +// ProgressToken is the progress token provided by the client or server. +// +// @since 3.15.0. +type ProgressToken struct { + name string + number int64 +} + +// compile time check whether the ProgressToken implements a fmt.Formatter, fmt.Stringer, json.Marshaler and json.Unmarshaler interfaces. +var ( + _ fmt.Formatter = (*ProgressToken)(nil) + _ fmt.Stringer = (*ProgressToken)(nil) + _ json.Marshaler = (*ProgressToken)(nil) + _ json.Unmarshaler = (*ProgressToken)(nil) +) + +// NewProgressToken returns a new ProgressToken. +func NewProgressToken(s string) *ProgressToken { + return &ProgressToken{name: s} +} + +// NewNumberProgressToken returns a new number ProgressToken. +func NewNumberProgressToken(n int64) *ProgressToken { + return &ProgressToken{number: n} +} + +// Format writes the ProgressToken to the formatter. +// +// If the rune is q the representation is non ambiguous, +// string forms are quoted. +func (v ProgressToken) Format(f fmt.State, r rune) { + const numF = `%d` + strF := `%s` + if r == 'q' { + strF = `%q` + } + + switch { + case v.name != "": + fmt.Fprintf(f, strF, v.name) + default: + fmt.Fprintf(f, numF, v.number) + } +} + +// String returns a string representation of the type. +func (v ProgressToken) String() string { + return fmt.Sprint(v) +} + +// MarshalJSON implements json.Marshaler. +func (v *ProgressToken) MarshalJSON() ([]byte, error) { + if v.name != "" { + return json.Marshal(v.name) + } + return json.Marshal(v.number) +} + +// UnmarshalJSON implements json.Unmarshaler. +func (v *ProgressToken) UnmarshalJSON(data []byte) error { + *v = ProgressToken{} + if err := json.Unmarshal(data, &v.number); err == nil { + return nil + } + return json.Unmarshal(data, &v.name) +} + +// ProgressParams params of Progress netification. +// +// @since 3.15.0. +type ProgressParams struct { + // Token is the progress token provided by the client or server. + Token ProgressToken `json:"token"` + + // Value is the progress data. + Value interface{} `json:"value"` +} + +// WorkDoneProgressKind kind of WorkDoneProgress. +// +// @since 3.15.0. +type WorkDoneProgressKind string + +// list of WorkDoneProgressKind. +const ( + WorkDoneProgressKindBegin WorkDoneProgressKind = "begin" + WorkDoneProgressKindReport WorkDoneProgressKind = "report" + WorkDoneProgressKindEnd WorkDoneProgressKind = "end" +) + +// WorkDoneProgressBegin is the to start progress reporting a "$/progress" notification. +// +// @since 3.15.0. +type WorkDoneProgressBegin struct { + // Kind is the kind of WorkDoneProgressBegin. + // + // It must be WorkDoneProgressKindBegin. + Kind WorkDoneProgressKind `json:"kind"` + + // Title mandatory title of the progress operation. Used to briefly inform about + // the kind of operation being performed. + // + // Examples: "Indexing" or "Linking dependencies". + Title string `json:"title"` + + // Cancellable controls if a cancel button should show to allow the user to cancel the + // long running operation. Clients that don't support cancellation are allowed + // to ignore the setting. + Cancellable bool `json:"cancellable,omitempty"` + + // Message is optional, more detailed associated progress message. Contains + // complementary information to the `title`. + // + // Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". + // If unset, the previous progress message (if any) is still valid. + Message string `json:"message,omitempty"` + + // Percentage is optional progress percentage to display (value 100 is considered 100%). + // If not provided infinite progress is assumed and clients are allowed + // to ignore the `percentage` value in subsequent in report notifications. + // + // The value should be steadily rising. Clients are free to ignore values + // that are not following this rule. + Percentage float64 `json:"percentage,omitempty"` +} + +// WorkDoneProgressReport is the reporting progress is done. +// +// @since 3.15.0. +type WorkDoneProgressReport struct { + // Kind is the kind of WorkDoneProgressReport. + // + // It must be WorkDoneProgressKindReport. + Kind WorkDoneProgressKind `json:"kind"` + + // Cancellable controls enablement state of a cancel button. + // + // Clients that don't support cancellation or don't support controlling the button's + // enablement state are allowed to ignore the property. + Cancellable bool `json:"cancellable,omitempty"` + + // Message is optional, more detailed associated progress message. Contains + // complementary information to the `title`. + // + // Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". + // If unset, the previous progress message (if any) is still valid. + Message string `json:"message,omitempty"` + + // Percentage is optional progress percentage to display (value 100 is considered 100%). + // If not provided infinite progress is assumed and clients are allowed + // to ignore the `percentage` value in subsequent in report notifications. + // + // The value should be steadily rising. Clients are free to ignore values + // that are not following this rule. + Percentage float64 `json:"percentage,omitempty"` +} + +// WorkDoneProgressEnd is the signaling the end of a progress reporting is done. +// +// @since 3.15.0. +type WorkDoneProgressEnd struct { + // Kind is the kind of WorkDoneProgressEnd. + // + // It must be WorkDoneProgressKindEnd. + Kind WorkDoneProgressKind `json:"kind"` + + // Message is optional, a final message indicating to for example indicate the outcome + // of the operation. + Message string `json:"message,omitempty"` +} + +// WorkDoneProgressParams is a parameter property of report work done progress. +// +// @since 3.15.0. +type WorkDoneProgressParams struct { + // WorkDoneToken an optional token that a server can use to report work done progress. + WorkDoneToken *ProgressToken `json:"workDoneToken,omitempty"` +} + +// PartialResultParams is the parameter literal used to pass a partial result token. +// +// @since 3.15.0. +type PartialResultParams struct { + // PartialResultToken an optional token that a server can use to report partial results + // (for example, streaming) to the client. + PartialResultToken *ProgressToken `json:"partialResultToken,omitempty"` +} diff --git a/progress_gojay.go b/progress_gojay.go new file mode 100644 index 00000000..e1ac332e --- /dev/null +++ b/progress_gojay.go @@ -0,0 +1,250 @@ +// Copyright 2021 The Go Language Server Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build gojay + +package protocol + +import ( + "github.com/francoispqt/gojay" +) + +func encodeProgressToken(enc *gojay.Encoder, key string, v *ProgressToken) { + if v == nil { + return + } + switch { + case v.name != "": + enc.StringKeyOmitEmpty(key, v.name) + default: + enc.Int64KeyOmitEmpty(key, v.number) + } +} + +func decodeProgressToken(dec *gojay.Decoder, k, key string, v *ProgressToken) error { + if v == nil || k != key { + return nil + } + switch { + case v.name != "": + return dec.String(&v.name) + default: + return dec.Int64(&v.number) + } +} + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *ProgressToken) MarshalJSONObject(enc *gojay.Encoder) { + switch { + case v.name != "": + enc.String(v.name) + case v.number > 0: + enc.Int64(v.number) + } +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *ProgressToken) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ProgressToken) UnmarshalJSONObject(dec *gojay.Decoder, _ string) error { + if err := dec.String(&v.name); err == nil { + return nil + } + return dec.Int64(&v.number) +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ProgressToken) NKeys() int { return 0 } + +// compile time check whether the ProgressParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*ProgressParams)(nil) + _ gojay.UnmarshalerJSONObject = (*ProgressParams)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *ProgressParams) MarshalJSONObject(enc *gojay.Encoder) { + switch { + case v.Token.name != "": + enc.StringKeyOmitEmpty(keyToken, v.Token.name) + default: + enc.Int64KeyOmitEmpty(keyToken, v.Token.number) + } + enc.AddInterfaceKey(keyValue, v.Value) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *ProgressParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *ProgressParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyToken: + switch { + case v.Token.name != "": + return dec.String(&v.Token.name) + default: + return dec.Int64(&v.Token.number) + } + case keyValue: + return dec.Interface(&v.Value) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *ProgressParams) NKeys() int { return 2 } + +// compile time check whether the ProgressParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*ProgressParams)(nil) + _ gojay.UnmarshalerJSONObject = (*ProgressParams)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressBegin) MarshalJSONObject(enc *gojay.Encoder) { + enc.StringKey(keyKind, string(v.Kind)) + enc.StringKey(keyTitle, v.Title) + enc.BoolKeyOmitEmpty(keyCancellable, v.Cancellable) + enc.StringKeyOmitEmpty(keyMessage, v.Message) + enc.Float64KeyOmitEmpty(keyPercentage, v.Percentage) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressBegin) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressBegin) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyKind: + return dec.String((*string)(&v.Kind)) + case keyTitle: + return dec.String(&v.Title) + case keyCancellable: + return dec.Bool(&v.Cancellable) + case keyMessage: + return dec.String(&v.Message) + case keyPercentage: + return dec.Float(&v.Percentage) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressBegin) NKeys() int { return 5 } + +// compile time check whether the WorkDoneProgressBegin implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WorkDoneProgressBegin)(nil) + _ gojay.UnmarshalerJSONObject = (*WorkDoneProgressBegin)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressReport) MarshalJSONObject(enc *gojay.Encoder) { + enc.StringKey(keyKind, string(v.Kind)) + enc.BoolKeyOmitEmpty(keyCancellable, v.Cancellable) + enc.StringKeyOmitEmpty(keyMessage, v.Message) + enc.Float64KeyOmitEmpty(keyPercentage, v.Percentage) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressReport) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressReport) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyKind: + return dec.String((*string)(&v.Kind)) + case keyCancellable: + return dec.Bool(&v.Cancellable) + case keyMessage: + return dec.String(&v.Message) + case keyPercentage: + return dec.Float(&v.Percentage) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressReport) NKeys() int { return 4 } + +// compile time check whether the WorkDoneProgressReport implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WorkDoneProgressReport)(nil) + _ gojay.UnmarshalerJSONObject = (*WorkDoneProgressReport)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressEnd) MarshalJSONObject(enc *gojay.Encoder) { + enc.StringKey(keyKind, string(v.Kind)) + enc.StringKeyOmitEmpty(keyMessage, v.Message) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressEnd) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressEnd) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyKind: + return dec.String((*string)(&v.Kind)) + case keyMessage: + return dec.String(&v.Message) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressEnd) NKeys() int { return 2 } + +// compile time check whether the WorkDoneProgressEnd implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WorkDoneProgressEnd)(nil) + _ gojay.UnmarshalerJSONObject = (*WorkDoneProgressEnd)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressParams) NKeys() int { return 1 } + +// compile time check whether the WorkDoneProgressParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WorkDoneProgressParams)(nil) + _ gojay.UnmarshalerJSONObject = (*WorkDoneProgressParams)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *PartialResultParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *PartialResultParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *PartialResultParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *PartialResultParams) NKeys() int { return 1 } + +// compile time check whether the PartialResultParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*PartialResultParams)(nil) + _ gojay.UnmarshalerJSONObject = (*PartialResultParams)(nil) +) diff --git a/selectionrange.go b/selectionrange.go new file mode 100644 index 00000000..e77b3a4e --- /dev/null +++ b/selectionrange.go @@ -0,0 +1,105 @@ +// Copyright 2021 The Go Language Server Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package protocol + +// SelectionRange represents a selection range represents a part of a selection hierarchy. +// +// A selection range may have a parent selection range that contains it. +// +// @since 3.15.0. +type SelectionRange struct { + // Range is the Range of this selection range. + Range Range `json:"range"` + + // Parent is the parent selection range containing this range. Therefore `parent.range` must contain this Range. + Parent *SelectionRange `json:"parent,omitempty"` +} + +// EnableSelectionRange is the whether the selection range. +type EnableSelectionRange bool + +// compile time check whether the EnableSelectionRange implements a SelectionRangeProviderOptions interface. +var _ SelectionRangeProviderOptions = (*EnableSelectionRange)(nil) + +// Value implements SelectionRangeProviderOptions interface. +func (v EnableSelectionRange) Value() interface{} { + return bool(v) +} + +// NewEnableSelectionRange returns the new EnableSelectionRange underlying types SelectionRangeProviderOptions. +func NewEnableSelectionRange(enable bool) SelectionRangeProviderOptions { + v := EnableSelectionRange(enable) + return &v +} + +// SelectionRangeOptions is the server capability of selection range. +type SelectionRangeOptions struct { + WorkDoneProgressOptions +} + +// compile time check whether the EnableSelectionRange implements a SelectionRangeProviderOptions interface. +var _ SelectionRangeProviderOptions = (*EnableSelectionRange)(nil) + +// Value implements SelectionRangeProviderOptions interface. +func (v *SelectionRangeOptions) Value() interface{} { + return v +} + +// NewSelectionRangeOptions returns the new SelectionRangeOptions underlying types SelectionRangeProviderOptions. +func NewSelectionRangeOptions(enableWorkDoneProgress bool) SelectionRangeProviderOptions { + v := SelectionRangeOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: enableWorkDoneProgress, + }, + } + return &v +} + +// SelectionRangeRegistrationOptions is the server capability of selection range registration. +type SelectionRangeRegistrationOptions struct { + SelectionRangeOptions + TextDocumentRegistrationOptions + StaticRegistrationOptions +} + +// compile time check whether the SelectionRangeRegistrationOptions implements a SelectionRangeProviderOptions interface. +var _ SelectionRangeProviderOptions = (*SelectionRangeRegistrationOptions)(nil) + +// Value implements SelectionRangeProviderOptions interface. +func (v *SelectionRangeRegistrationOptions) Value() interface{} { + return v +} + +// NewSelectionRangeRegistrationOptions returns the new SelectionRangeRegistrationOptions underlying types SelectionRangeProviderOptions. +func NewSelectionRangeRegistrationOptions(enableWorkDoneProgress bool, selector DocumentSelector, id string) SelectionRangeProviderOptions { + v := SelectionRangeRegistrationOptions{ + SelectionRangeOptions: SelectionRangeOptions{ + WorkDoneProgressOptions: WorkDoneProgressOptions{ + WorkDoneProgress: enableWorkDoneProgress, + }, + }, + TextDocumentRegistrationOptions: TextDocumentRegistrationOptions{ + DocumentSelector: selector, + }, + StaticRegistrationOptions: StaticRegistrationOptions{ + ID: id, + }, + } + return &v +} + +// SelectionRangeParams represents a parameter literal used in selection range requests. +// +// @since 3.15.0. +type SelectionRangeParams struct { + WorkDoneProgressParams + PartialResultParams + + // TextDocument is the text document. + TextDocument TextDocumentIdentifier `json:"textDocument"` + + // Positions is the positions inside the text document. + Positions []Position `json:"positions"` +} diff --git a/selectionrange_gojay.go b/selectionrange_gojay.go new file mode 100644 index 00000000..ca5be597 --- /dev/null +++ b/selectionrange_gojay.go @@ -0,0 +1,164 @@ +// Copyright 2021 The Go Language Server Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build gojay + +package protocol + +import ( + "github.com/francoispqt/gojay" +) + +// SelectionRangeProviderOptions selection range provider options interface. +type SelectionRangeProviderOptions interface { + Value() interface{} + gojay.MarshalerJSONObject + gojay.UnmarshalerJSONObject +} + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *SelectionRange) MarshalJSONObject(enc *gojay.Encoder) { + enc.ObjectKey(keyRange, &v.Range) + enc.ObjectKeyOmitEmpty(keyParent, v.Parent) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *SelectionRange) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *SelectionRange) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyRange: + return dec.Object(&v.Range) + case keyParent: + return dec.Object(v.Parent) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *SelectionRange) NKeys() int { return 2 } + +// compile time check whether the SelectionRange implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*SelectionRange)(nil) + _ gojay.UnmarshalerJSONObject = (*SelectionRange)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *EnableSelectionRange) MarshalJSONObject(enc *gojay.Encoder) { + enc.Bool(v.Value().(bool)) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *EnableSelectionRange) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *EnableSelectionRange) UnmarshalJSONObject(dec *gojay.Decoder, _ string) error { + return dec.Bool((*bool)(v)) +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *EnableSelectionRange) NKeys() int { return 0 } + +// compile time check whether the EnableSelectionRange implements a SelectionRangeProviderOptions, gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ SelectionRangeProviderOptions = (*EnableSelectionRange)(nil) + _ gojay.MarshalerJSONObject = (*EnableSelectionRange)(nil) + _ gojay.UnmarshalerJSONObject = (*EnableSelectionRange)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *SelectionRangeOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *SelectionRangeOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *SelectionRangeOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyWorkDoneProgress { + return dec.Bool(&v.WorkDoneProgress) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *SelectionRangeOptions) NKeys() int { return 1 } + +// compile time check whether the SelectionRangeOptions implements a SelectionRangeProviderOptions, gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ SelectionRangeProviderOptions = (*SelectionRangeOptions)(nil) + _ gojay.MarshalerJSONObject = (*SelectionRangeOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*SelectionRangeOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *SelectionRangeRegistrationOptions) MarshalJSONObject(enc *gojay.Encoder) { + enc.BoolKeyOmitEmpty(keyWorkDoneProgress, v.WorkDoneProgress) + enc.ArrayKey(keyDocumentSelector, &v.DocumentSelector) + enc.StringKeyOmitEmpty(keyID, v.ID) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *SelectionRangeRegistrationOptions) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *SelectionRangeRegistrationOptions) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyWorkDoneProgress: + return dec.Bool(&v.WorkDoneProgress) + case keyDocumentSelector: + return dec.Array(&v.DocumentSelector) + case keyID: + return dec.String(&v.ID) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *SelectionRangeRegistrationOptions) NKeys() int { return 3 } + +// compile time check whether the SelectionRangeRegistrationOptions implements a SelectionRangeProviderOptions, gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ SelectionRangeProviderOptions = (*SelectionRangeRegistrationOptions)(nil) + _ gojay.MarshalerJSONObject = (*SelectionRangeRegistrationOptions)(nil) + _ gojay.UnmarshalerJSONObject = (*SelectionRangeRegistrationOptions)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *SelectionRangeParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) + enc.ObjectKey(keyTextDocument, &v.TextDocument) + enc.ArrayKey(keyPositions, (*Positions)(&v.Positions)) +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *SelectionRangeParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *SelectionRangeParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + case keyTextDocument: + return dec.Object(&v.TextDocument) + case keyPositions: + return dec.Array((*Positions)(&v.Positions)) + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *SelectionRangeParams) NKeys() int { return 4 } + +// compile time check whether the SelectionRangeParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*SelectionRangeParams)(nil) + _ gojay.UnmarshalerJSONObject = (*SelectionRangeParams)(nil) +) diff --git a/selectionrange_json.go b/selectionrange_json.go new file mode 100644 index 00000000..85235bb1 --- /dev/null +++ b/selectionrange_json.go @@ -0,0 +1,10 @@ +// Copyright 2021 The Go Language Server Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !gojay + +package protocol + +// SelectionRangeProviderOptions selection range provider options interface. +type SelectionRangeProviderOptions interface{} diff --git a/server.go b/server.go index 28487676..360f8dc6 100644 --- a/server.go +++ b/server.go @@ -27,14 +27,16 @@ type Server interface { Initialized(ctx context.Context, params *InitializedParams) (err error) Shutdown(ctx context.Context) (err error) Exit(ctx context.Context) (err error) + WorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) error + WorkDoneProgressCancel(ctx context.Context, params *WorkDoneProgressCancelParams) error CodeAction(ctx context.Context, params *CodeActionParams) (result []CodeAction, err error) CodeLens(ctx context.Context, params *CodeLensParams) (result []CodeLens, err error) CodeLensResolve(ctx context.Context, params *CodeLens) (result *CodeLens, err error) ColorPresentation(ctx context.Context, params *ColorPresentationParams) (result []ColorPresentation, err error) Completion(ctx context.Context, params *CompletionParams) (result *CompletionList, err error) CompletionResolve(ctx context.Context, params *CompletionItem) (result *CompletionItem, err error) - Declaration(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) - Definition(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) + Declaration(ctx context.Context, params *DeclarationParams) (result []Location /* Declaration | DeclarationLink[] | null */, err error) + Definition(ctx context.Context, params *DefinitionParams) (result []Location /* Definition | DefinitionLink[] | null */, err error) DidChange(ctx context.Context, params *DidChangeTextDocumentParams) (err error) DidChangeConfiguration(ctx context.Context, params *DidChangeConfigurationParams) (err error) DidChangeWatchedFiles(ctx context.Context, params *DidChangeWatchedFilesParams) (err error) @@ -43,29 +45,32 @@ type Server interface { DidOpen(ctx context.Context, params *DidOpenTextDocumentParams) (err error) DidSave(ctx context.Context, params *DidSaveTextDocumentParams) (err error) DocumentColor(ctx context.Context, params *DocumentColorParams) (result []ColorInformation, err error) - DocumentHighlight(ctx context.Context, params *TextDocumentPositionParams) (result []DocumentHighlight, err error) + DocumentHighlight(ctx context.Context, params *DocumentHighlightParams) (result []DocumentHighlight, err error) DocumentLink(ctx context.Context, params *DocumentLinkParams) (result []DocumentLink, err error) DocumentLinkResolve(ctx context.Context, params *DocumentLink) (result *DocumentLink, err error) - DocumentSymbol(ctx context.Context, params *DocumentSymbolParams) (result []DocumentSymbol, err error) + DocumentSymbol(ctx context.Context, params *DocumentSymbolParams) (result []interface{} /* SymbolInformation[] | DocumentSymbol[] | null */, err error) ExecuteCommand(ctx context.Context, params *ExecuteCommandParams) (result interface{}, err error) FoldingRanges(ctx context.Context, params *FoldingRangeParams) (result []FoldingRange, err error) Formatting(ctx context.Context, params *DocumentFormattingParams) (result []TextEdit, err error) - Hover(ctx context.Context, params *TextDocumentPositionParams) (result *Hover, err error) - Implementation(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) + Hover(ctx context.Context, params *HoverParams) (result *Hover, err error) + Implementation(ctx context.Context, params *ImplementationParams) (result []Location, err error) OnTypeFormatting(ctx context.Context, params *DocumentOnTypeFormattingParams) (result []TextEdit, err error) - PrepareRename(ctx context.Context, params *TextDocumentPositionParams) (result *Range, err error) + PrepareRename(ctx context.Context, params *PrepareRenameParams) (result *Range, err error) RangeFormatting(ctx context.Context, params *DocumentRangeFormattingParams) (result []TextEdit, err error) References(ctx context.Context, params *ReferenceParams) (result []Location, err error) Rename(ctx context.Context, params *RenameParams) (result *WorkspaceEdit, err error) - SignatureHelp(ctx context.Context, params *TextDocumentPositionParams) (result *SignatureHelp, err error) + SignatureHelp(ctx context.Context, params *SignatureHelpParams) (result *SignatureHelp, err error) Symbols(ctx context.Context, params *WorkspaceSymbolParams) (result []SymbolInformation, err error) - TypeDefinition(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) + TypeDefinition(ctx context.Context, params *TypeDefinitionParams) (result []Location, err error) WillSave(ctx context.Context, params *WillSaveTextDocumentParams) (err error) WillSaveWaitUntil(ctx context.Context, params *WillSaveTextDocumentParams) (result []TextEdit, err error) Request(ctx context.Context, method string, params interface{}) (interface{}, error) } const ( + // MethodProgress method name of "$/progress". + MethodProgress = "$/progress" + // MethodInitialize method name of "initialize". MethodInitialize = "initialize" @@ -78,6 +83,12 @@ const ( // MethodExit method name of "exit". MethodExit = "exit" + // MethodWorkDoneProgressCreate method name of "window/workDoneProgress/create". + MethodWorkDoneProgressCreate = "window/workDoneProgress/create" + + // MethodWorkDoneProgressCancel method name of "window/workDoneProgress/cancel". + MethodWorkDoneProgressCancel = "window/workDoneProgress/cancel" + // MethodCancelRequest method name of "$/cancelRequest". MethodCancelRequest = "$/cancelRequest" @@ -255,6 +266,23 @@ func (s *server) Exit(ctx context.Context) (err error) { return s.Conn.Notify(ctx, MethodExit, nil) } +// WorkDoneProgressCreate sends the request is sent from the server to the client to ask the client to create a work done progress. +func (s *server) WorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) (err error) { + s.logger.Debug("call " + MethodWorkDoneProgressCreate) + defer s.logger.Debug("end "+MethodWorkDoneProgressCreate, zap.Error(err)) + + return s.Conn.Notify(ctx, MethodWorkDoneProgressCreate, params) +} + +// WorkDoneProgressCancel is the sends notification from the client to the server to cancel a progress initiated on the +// server side using the "window/workDoneProgress/create". +func (s *server) WorkDoneProgressCancel(ctx context.Context, params *WorkDoneProgressCancelParams) (err error) { + s.logger.Debug("call " + MethodWorkDoneProgressCancel) + defer s.logger.Debug("end "+MethodWorkDoneProgressCancel, zap.Error(err)) + + return s.Conn.Notify(ctx, MethodWorkDoneProgressCancel, params) +} + // CodeAction sends the request is from the client to the server to compute commands for a given text document and range. // // These commands are typically code fixes to either fix problems or to beautify/refactor code. The result of a `textDocument/codeAction` @@ -353,7 +381,7 @@ func (s *server) CompletionResolve(ctx context.Context, params *CompletionItem) // The result type LocationLink[] got introduce with version 3.14.0 and depends in the corresponding client capability `clientCapabilities.textDocument.declaration.linkSupport`. // // Since version 3.14.0. -func (s *server) Declaration(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) { +func (s *server) Declaration(ctx context.Context, params *DeclarationParams) (result []Location, err error) { s.logger.Debug("call " + MethodTextDocumentDeclaration) defer s.logger.Debug("end "+MethodTextDocumentDeclaration, zap.Error(err)) @@ -368,7 +396,7 @@ func (s *server) Declaration(ctx context.Context, params *TextDocumentPositionPa // The result type `[]LocationLink` got introduce with version 3.14.0 and depends in the corresponding client capability `clientCapabilities.textDocument.definition.linkSupport`. // // Since version 3.14.0. -func (s *server) Definition(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) { +func (s *server) Definition(ctx context.Context, params *DefinitionParams) (result []Location, err error) { s.logger.Debug("call " + MethodTextDocumentDefinition) defer s.logger.Debug("end "+MethodTextDocumentDefinition, zap.Error(err)) @@ -390,8 +418,8 @@ func (s *server) DidChange(ctx context.Context, params *DidChangeTextDocumentPar // DidChangeConfiguration sends the notification from the client to the server to signal the change of configuration settings. func (s *server) DidChangeConfiguration(ctx context.Context, params *DidChangeConfigurationParams) (err error) { - s.logger.Debug("call " + MethodTextDocumentDeclaration) - defer s.logger.Debug("end "+MethodTextDocumentDeclaration, zap.Error(err)) + s.logger.Debug("call " + MethodWorkspaceDidChangeConfiguration) + defer s.logger.Debug("end "+MethodWorkspaceDidChangeConfiguration, zap.Error(err)) return s.Conn.Notify(ctx, MethodWorkspaceDidChangeConfiguration, params) } @@ -484,7 +512,7 @@ func (s *server) DocumentColor(ctx context.Context, params *DocumentColorParams) // However we kept ‘textDocument/documentHighlight’ and ‘textDocument/references’ separate requests since the first one is allowed to be more fuzzy. // // Symbol matches usually have a `DocumentHighlightKind` of `Read` or `Write` whereas fuzzy or textual matches use `Text` as the kind. -func (s *server) DocumentHighlight(ctx context.Context, params *TextDocumentPositionParams) (result []DocumentHighlight, err error) { +func (s *server) DocumentHighlight(ctx context.Context, params *DocumentHighlightParams) (result []DocumentHighlight, err error) { s.logger.Debug("call " + MethodTextDocumentDocumentHighlight) defer s.logger.Debug("end "+MethodTextDocumentDocumentHighlight, zap.Error(err)) @@ -520,7 +548,7 @@ func (s *server) DocumentLinkResolve(ctx context.Context, params *DocumentLink) // DocumentSymbol sends the request from the client to the server to return a flat list of all symbols found in a given text document. // // Neither the symbol’s location range nor the symbol’s container name should be used to infer a hierarchy. -func (s *server) DocumentSymbol(ctx context.Context, params *DocumentSymbolParams) (result []DocumentSymbol, err error) { +func (s *server) DocumentSymbol(ctx context.Context, params *DocumentSymbolParams) (result []interface{}, err error) { s.logger.Debug("call " + MethodTextDocumentDocumentSymbol) defer s.logger.Debug("end "+MethodTextDocumentDocumentSymbol, zap.Error(err)) @@ -569,7 +597,7 @@ func (s *server) Formatting(ctx context.Context, params *DocumentFormattingParam } // Hover sends the request is from the client to the server to request hover information at a given text document position. -func (s *server) Hover(ctx context.Context, params *TextDocumentPositionParams) (_ *Hover, err error) { +func (s *server) Hover(ctx context.Context, params *HoverParams) (_ *Hover, err error) { s.logger.Debug("call " + MethodTextDocumentHover) defer s.logger.Debug("end "+MethodTextDocumentHover, zap.Error(err)) @@ -583,7 +611,7 @@ func (s *server) Hover(ctx context.Context, params *TextDocumentPositionParams) // Implementation sends the request from the client to the server to resolve the implementation location of a symbol at a given text document position. // // The result type `[]LocationLink` got introduce with version 3.14.0 and depends in the corresponding client capability `clientCapabilities.implementation.typeDefinition.linkSupport`. -func (s *server) Implementation(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) { +func (s *server) Implementation(ctx context.Context, params *ImplementationParams) (result []Location, err error) { s.logger.Debug("call " + MethodTextDocumentImplementation) defer s.logger.Debug("end "+MethodTextDocumentImplementation, zap.Error(err)) @@ -607,7 +635,7 @@ func (s *server) OnTypeFormatting(ctx context.Context, params *DocumentOnTypeFor // PrepareRename sends the request from the client to the server to setup and test the validity of a rename operation at a given location. // // Since version 3.12.0. -func (s *server) PrepareRename(ctx context.Context, params *TextDocumentPositionParams) (result *Range, err error) { +func (s *server) PrepareRename(ctx context.Context, params *PrepareRenameParams) (result *Range, err error) { s.logger.Debug("call " + MethodTextDocumentPrepareRename) defer s.logger.Debug("end "+MethodTextDocumentPrepareRename, zap.Error(err)) @@ -651,7 +679,7 @@ func (s *server) Rename(ctx context.Context, params *RenameParams) (result *Work } // SignatureHelp sends the request from the client to the server to request signature information at a given cursor position. -func (s *server) SignatureHelp(ctx context.Context, params *TextDocumentPositionParams) (_ *SignatureHelp, err error) { +func (s *server) SignatureHelp(ctx context.Context, params *SignatureHelpParams) (_ *SignatureHelp, err error) { s.logger.Debug("call " + MethodTextDocumentSignatureHelp) defer s.logger.Debug("end "+MethodTextDocumentSignatureHelp, zap.Error(err)) @@ -678,7 +706,7 @@ func (s *server) Symbols(ctx context.Context, params *WorkspaceSymbolParams) (re // The result type `[]LocationLink` got introduce with version 3.14.0 and depends in the corresponding client capability `clientCapabilities.textDocument.typeDefinition.linkSupport`. // // Since version 3.6.0. -func (s *server) TypeDefinition(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) { +func (s *server) TypeDefinition(ctx context.Context, params *TypeDefinitionParams) (result []Location, err error) { s.logger.Debug("call " + MethodTextDocumentTypeDefinition) defer s.logger.Debug("end "+MethodTextDocumentTypeDefinition, zap.Error(err)) diff --git a/server_gojay.go b/server_gojay.go index 7b4b3260..110ccb5a 100644 --- a/server_gojay.go +++ b/server_gojay.go @@ -160,7 +160,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentDeclaration: // request defer logger.Debug(MethodTextDocumentDeclaration, zap.Error(err)) - var params TextDocumentPositionParams + var params DeclarationParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -170,7 +170,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentDefinition: // request defer logger.Debug(MethodTextDocumentDefinition, zap.Error(err)) - var params TextDocumentPositionParams + var params DefinitionParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -260,7 +260,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentDocumentHighlight: // request defer logger.Debug(MethodTextDocumentDocumentHighlight, zap.Error(err)) - var params TextDocumentPositionParams + var params DocumentHighlightParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -330,7 +330,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentHover: // request defer logger.Debug(MethodTextDocumentHover, zap.Error(err)) - var params TextDocumentPositionParams + var params HoverParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -340,7 +340,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentImplementation: // request defer logger.Debug(MethodTextDocumentImplementation, zap.Error(err)) - var params TextDocumentPositionParams + var params ImplementationParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -360,7 +360,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentPrepareRename: // request defer logger.Debug(MethodTextDocumentPrepareRename, zap.Error(err)) - var params TextDocumentPositionParams + var params PrepareRenameParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -401,7 +401,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentSignatureHelp: // request defer logger.Debug(MethodTextDocumentSignatureHelp, zap.Error(err)) - var params TextDocumentPositionParams + var params SignatureHelpParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -421,7 +421,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentTypeDefinition: // request defer logger.Debug(MethodTextDocumentTypeDefinition, zap.Error(err)) - var params TextDocumentPositionParams + var params TypeDefinitionParams if err := dec.DecodeObject(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } diff --git a/server_json.go b/server_json.go index 770f3956..a48d14f3 100644 --- a/server_json.go +++ b/server_json.go @@ -157,7 +157,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentDeclaration: // request defer logger.Debug(MethodTextDocumentDeclaration, zap.Error(err)) - var params TextDocumentPositionParams + var params DeclarationParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -167,7 +167,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentDefinition: // request defer logger.Debug(MethodTextDocumentDefinition, zap.Error(err)) - var params TextDocumentPositionParams + var params DefinitionParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -257,7 +257,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentDocumentHighlight: // request defer logger.Debug(MethodTextDocumentDocumentHighlight, zap.Error(err)) - var params TextDocumentPositionParams + var params DocumentHighlightParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -327,7 +327,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentHover: // request defer logger.Debug(MethodTextDocumentHover, zap.Error(err)) - var params TextDocumentPositionParams + var params HoverParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -337,7 +337,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentImplementation: // request defer logger.Debug(MethodTextDocumentImplementation, zap.Error(err)) - var params TextDocumentPositionParams + var params ImplementationParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -357,7 +357,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentPrepareRename: // request defer logger.Debug(MethodTextDocumentPrepareRename, zap.Error(err)) - var params TextDocumentPositionParams + var params PrepareRenameParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -397,7 +397,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentSignatureHelp: // request defer logger.Debug(MethodTextDocumentSignatureHelp, zap.Error(err)) - var params TextDocumentPositionParams + var params SignatureHelpParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } @@ -417,7 +417,7 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case MethodTextDocumentTypeDefinition: // request defer logger.Debug(MethodTextDocumentTypeDefinition, zap.Error(err)) - var params TextDocumentPositionParams + var params TypeDefinitionParams if err := dec.Decode(¶ms); err != nil { return true, replyParseError(ctx, reply, err) } diff --git a/text_test.go b/text_test.go index d7bc3cb1..00d93472 100644 --- a/text_test.go +++ b/text_test.go @@ -117,7 +117,7 @@ func testDidChangeTextDocumentParams(t *testing.T, marshal marshalFunc, unmarsha TextDocumentIdentifier: TextDocumentIdentifier{ URI: uri.File("/path/to/test.go"), }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, ContentChanges: []TextDocumentContentChangeEvent{ { diff --git a/util.go b/util.go index b9a6e1db..9d932039 100644 --- a/util.go +++ b/util.go @@ -11,7 +11,7 @@ func ToURI(s string) uri.URI { return uri.File(s) } -// Uint64Ptr converts i to uint64 pointer. -func Uint64Ptr(i uint64) *uint64 { +// NewVersion returns the uint64 pointer converted i. +func NewVersion(i uint64) *uint64 { return &i } diff --git a/util_test.go b/util_test.go index d078abbe..4a513d2c 100644 --- a/util_test.go +++ b/util_test.go @@ -33,7 +33,7 @@ func TestToURI(t *testing.T) { } } -func TestUint64Ptr(t *testing.T) { +func TestNewVersion(t *testing.T) { tests := []struct { name string i uint64 @@ -45,9 +45,9 @@ func TestUint64Ptr(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - want := Uint64Ptr(tt.i) - if got := Uint64Ptr(tt.i); *got != *want { - t.Errorf("Uint64Ptr(%v) = %v, want %v", tt.i, *got, *want) + want := NewVersion(tt.i) + if got := NewVersion(tt.i); *got != *want { + t.Errorf("NewVersion(%v) = %v, want %v", tt.i, *got, *want) } }) } diff --git a/version.go b/version.go index 379119af..0d34e8f1 100644 --- a/version.go +++ b/version.go @@ -5,4 +5,4 @@ package protocol // Version is the version of the language-server-protocol specification being implemented. -const Version = "3.15.0-next.6" +const Version = "3.15.3" diff --git a/window.go b/window.go index 52f719aa..e2149afc 100644 --- a/window.go +++ b/window.go @@ -94,3 +94,19 @@ type LogMessageParams struct { // Type is the message type. See {@link MessageType} Type MessageType `json:"type"` } + +// WorkDoneProgressCreateParams params of WorkDoneProgressCreate request. +// +// @since 3.15.0. +type WorkDoneProgressCreateParams struct { + // Token is the token to be used to report progress. + Token ProgressToken `json:"token"` +} + +// WorkDoneProgressCreateParams params of WorkDoneProgressCancel request. +// +// @since 3.15.0. +type WorkDoneProgressCancelParams struct { + // Token is the token to be used to report progress. + Token ProgressToken `json:"token"` +} diff --git a/window_gojay.go b/window_gojay.go index bf0944ae..f5135d73 100644 --- a/window_gojay.go +++ b/window_gojay.go @@ -6,7 +6,9 @@ package protocol -import "github.com/francoispqt/gojay" +import ( + "github.com/francoispqt/gojay" +) // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *ShowMessageParams) MarshalJSONObject(enc *gojay.Encoder) { @@ -151,3 +153,73 @@ var ( _ gojay.MarshalerJSONObject = (*LogMessageParams)(nil) _ gojay.UnmarshalerJSONObject = (*LogMessageParams)(nil) ) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressCreateParams) MarshalJSONObject(enc *gojay.Encoder) { + switch { + case v.Token.name != "": + enc.StringKey(keyToken, v.Token.name) + default: + enc.Int64Key(keyToken, v.Token.number) + } +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressCreateParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressCreateParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyToken { + switch { + case v.Token.name != "": + return dec.String(&v.Token.name) + default: + return dec.Int64(&v.Token.number) + } + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressCreateParams) NKeys() int { return 1 } + +// compile time check whether the WorkDoneProgressCreateParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WorkDoneProgressCreateParams)(nil) + _ gojay.UnmarshalerJSONObject = (*WorkDoneProgressCreateParams)(nil) +) + +// MarshalJSONObject implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressCancelParams) MarshalJSONObject(enc *gojay.Encoder) { + switch { + case v.Token.name != "": + enc.StringKey(keyToken, v.Token.name) + default: + enc.Int64Key(keyToken, v.Token.number) + } +} + +// IsNil implements gojay.MarshalerJSONObject. +func (v *WorkDoneProgressCancelParams) IsNil() bool { return v == nil } + +// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressCancelParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { + if k == keyToken { + switch { + case v.Token.name != "": + return dec.String(&v.Token.name) + default: + return dec.Int64(&v.Token.number) + } + } + return nil +} + +// NKeys implements gojay.UnmarshalerJSONObject. +func (v *WorkDoneProgressCancelParams) NKeys() int { return 1 } + +// compile time check whether the WorkDoneProgressCancelParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. +var ( + _ gojay.MarshalerJSONObject = (*WorkDoneProgressCancelParams)(nil) + _ gojay.UnmarshalerJSONObject = (*WorkDoneProgressCancelParams)(nil) +) diff --git a/window_gojay_test.go b/window_gojay_test.go index fa7a47b1..87e34d05 100644 --- a/window_gojay_test.go +++ b/window_gojay_test.go @@ -27,3 +27,11 @@ func TestMessageActionItem(t *testing.T) { func TestLogMessageParams(t *testing.T) { testLogMessageParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) } + +func TestWorkDoneProgressCreateParams(t *testing.T) { + testWorkDoneProgressCreateParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} + +func TestWorkDoneProgressCancelParams(t *testing.T) { + testWorkDoneProgressCancelParams(t, gojay.Marshal, gojay.Unsafe.Unmarshal) +} diff --git a/window_json_test.go b/window_json_test.go index 71525c19..1c3a1513 100644 --- a/window_json_test.go +++ b/window_json_test.go @@ -24,3 +24,11 @@ func TestMessageActionItem(t *testing.T) { func TestLogMessageParams(t *testing.T) { testLogMessageParams(t, json.Marshal, json.Unmarshal) } + +func TestWorkDoneProgressCreateParams(t *testing.T) { + testWorkDoneProgressCreateParams(t, json.Marshal, json.Unmarshal) +} + +func TestWorkDoneProgressCancelParams(t *testing.T) { + testWorkDoneProgressCancelParams(t, json.Marshal, json.Unmarshal) +} diff --git a/window_test.go b/window_test.go index e3defc3e..bf3753dd 100644 --- a/window_test.go +++ b/window_test.go @@ -5,6 +5,8 @@ package protocol import ( + "fmt" + "strconv" "testing" "github.com/google/go-cmp/cmp" @@ -422,6 +424,196 @@ func testLogMessageParams(t *testing.T, marshal marshalFunc, unmarshal unmarshal }) } +func testWorkDoneProgressCreateParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantToken = int64(1569) + invalidToken = int64(1348) + ) + var ( + want = `{"token":` + strconv.FormatInt(wantToken, 10) + `}` + wantInvalid = `{"token":` + strconv.FormatInt(invalidToken, 10) + `}` + ) + token := NewNumberProgressToken(wantToken) + wantType := WorkDoneProgressCreateParams{ + Token: *token, + } + + t.Run("Marshal", func(t *testing.T) { + tests := []struct { + name string + field WorkDoneProgressCreateParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + tests := []struct { + name string + field string + want WorkDoneProgressCreateParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got WorkDoneProgressCreateParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(fmt.Sprint(got.Token), strconv.FormatInt(wantToken, 10)); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + +func testWorkDoneProgressCancelParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { + const ( + wantToken = int64(1569) + invalidToken = int64(1348) + ) + var ( + want = `{"token":` + strconv.FormatInt(wantToken, 10) + `}` + wantInvalid = `{"token":` + strconv.FormatInt(invalidToken, 10) + `}` + ) + token := NewNumberProgressToken(wantToken) + wantType := WorkDoneProgressCancelParams{ + Token: *token, + } + + t.Run("Marshal", func(t *testing.T) { + tests := []struct { + name string + field WorkDoneProgressCancelParams + want string + wantMarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: wantType, + want: want, + wantMarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantType, + want: wantInvalid, + wantMarshalErr: false, + wantErr: true, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := marshal(&tt.field) + if (err != nil) != tt.wantMarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) + + t.Run("Unmarshal", func(t *testing.T) { + tests := []struct { + name string + field string + want WorkDoneProgressCancelParams + wantUnmarshalErr bool + wantErr bool + }{ + { + name: "Valid", + field: want, + want: wantType, + wantUnmarshalErr: false, + wantErr: false, + }, + { + name: "Invalid", + field: wantInvalid, + want: wantType, + wantUnmarshalErr: false, + wantErr: true, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var got WorkDoneProgressCancelParams + if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr { + t.Fatal(err) + } + + if diff := cmp.Diff(fmt.Sprint(got.Token), strconv.FormatInt(wantToken, 10)); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + }) + } + }) +} + func TestMessageType_String(t *testing.T) { tests := []struct { name string diff --git a/workspace.go b/workspace.go index 91d4c9c8..e1618aec 100644 --- a/workspace.go +++ b/workspace.go @@ -155,12 +155,19 @@ func (k WatchKind) String() string { // WorkspaceSymbolParams is the parameters of a Workspace Symbol Request. type WorkspaceSymbolParams struct { - // Query a non-empty query string + WorkDoneProgressParams + PartialResultParams + + // Query a query string to filter symbols by. + // + // Clients may send an empty string here to request all symbols. Query string `json:"query"` } // ExecuteCommandParams params of Execute a command. type ExecuteCommandParams struct { + WorkDoneProgressParams + // Command is the identifier of the actual command handler. Command string `json:"command"` diff --git a/workspace_gojay.go b/workspace_gojay.go index 3d6babe7..9c2d88d5 100644 --- a/workspace_gojay.go +++ b/workspace_gojay.go @@ -373,6 +373,8 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *WorkspaceSymbolParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) + encodeProgressToken(enc, keyPartialResultToken, v.PartialResultToken) enc.StringKey(keyQuery, v.Query) } @@ -381,14 +383,19 @@ func (v *WorkspaceSymbolParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *WorkspaceSymbolParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { - if k == keyQuery { + switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) + case keyPartialResultToken: + return decodeProgressToken(dec, k, keyPartialResultToken, v.PartialResultToken) + case keyQuery: return dec.String(&v.Query) } return nil } // NKeys returns the number of keys to unmarshal. -func (v *WorkspaceSymbolParams) NKeys() int { return 1 } +func (v *WorkspaceSymbolParams) NKeys() int { return 3 } // compile time check whether the WorkspaceSymbolParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( @@ -398,6 +405,7 @@ var ( // MarshalJSONObject implements gojay.MarshalerJSONObject. func (v *ExecuteCommandParams) MarshalJSONObject(enc *gojay.Encoder) { + encodeProgressToken(enc, keyWorkDoneToken, v.WorkDoneToken) enc.StringKey(keyCommand, v.Command) enc.ArrayKeyOmitEmpty(keyArguments, (*Interfaces)(&v.Arguments)) } @@ -408,6 +416,8 @@ func (v *ExecuteCommandParams) IsNil() bool { return v == nil } // UnmarshalJSONObject implements gojay's UnmarshalerJSONObject. func (v *ExecuteCommandParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { + case keyWorkDoneToken: + return decodeProgressToken(dec, k, keyWorkDoneToken, v.WorkDoneToken) case keyCommand: return dec.String(&v.Command) case keyArguments: @@ -417,7 +427,7 @@ func (v *ExecuteCommandParams) UnmarshalJSONObject(dec *gojay.Decoder, k string) } // NKeys returns the number of keys to unmarshal. -func (v *ExecuteCommandParams) NKeys() int { return 2 } +func (v *ExecuteCommandParams) NKeys() int { return 3 } // compile time check whether the ExecuteCommandParams implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces. var ( diff --git a/workspace_test.go b/workspace_test.go index 2dc9f71b..5a436875 100644 --- a/workspace_test.go +++ b/workspace_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "go.lsp.dev/uri" ) @@ -1048,10 +1049,20 @@ func TestWatchKind_String(t *testing.T) { func testWorkspaceSymbolParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"query":"testQuery"}` - wantInvalid = `{"query":"invalidQuery"}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + wantPartialResultToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","partialResultToken":"` + wantPartialResultToken + `","query":"testQuery"}` + wantInvalid = `{"workDoneToken":"` + wantPartialResultToken + `","partialResultToken":"` + wantWorkDoneToken + `","query":"invalidQuery"}` ) wantType := WorkspaceSymbolParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, + PartialResultParams: PartialResultParams{ + PartialResultToken: NewProgressToken(wantPartialResultToken), + }, Query: "testQuery", } @@ -1128,9 +1139,21 @@ func testWorkspaceSymbolParams(t *testing.T, marshal marshalFunc, unmarshal unma t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } + + if partialResultToken := got.PartialResultToken; partialResultToken != nil { + if diff := cmp.Diff(partialResultToken.String(), wantPartialResultToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -1138,11 +1161,18 @@ func testWorkspaceSymbolParams(t *testing.T, marshal marshalFunc, unmarshal unma func testExecuteCommandParams(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) { const ( - want = `{"command":"testCommand","arguments":["testArguments"]}` + wantWorkDoneToken = "156edea9-9d8d-422f-b7ee-81a84594afbb" + invalidWorkDoneToken = "dd134d84-c134-4d7a-a2a3-f8af3ef4a568" + ) + const ( + want = `{"workDoneToken":"` + wantWorkDoneToken + `","command":"testCommand","arguments":["testArguments"]}` wantNilAll = `{"command":"testCommand"}` - wantInvalid = `{"command":"invalidCommand","arguments":["invalidArguments"]}` + wantInvalid = `{"workDoneToken":"` + invalidWorkDoneToken + `","command":"invalidCommand","arguments":["invalidArguments"]}` ) wantType := ExecuteCommandParams{ + WorkDoneProgressParams: WorkDoneProgressParams{ + WorkDoneToken: NewProgressToken(wantWorkDoneToken), + }, Command: "testCommand", Arguments: []interface{}{ "testArguments", @@ -1239,9 +1269,15 @@ func testExecuteCommandParams(t *testing.T, marshal marshalFunc, unmarshal unmar t.Fatal(err) } - if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr { + if diff := cmp.Diff(got, tt.want, cmpopts.IgnoreTypes(WorkDoneProgressParams{}, PartialResultParams{})); (diff != "") != tt.wantErr { t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) } + + if workDoneToken := got.WorkDoneToken; workDoneToken != nil { + if diff := cmp.Diff(workDoneToken.String(), wantWorkDoneToken); (diff != "") != tt.wantErr { + t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff) + } + } }) } }) @@ -1372,7 +1408,7 @@ func testApplyWorkspaceEditParams(t *testing.T, marshal marshalFunc, unmarshal u TextDocumentIdentifier: TextDocumentIdentifier{ URI: uri.File("/path/to/basic.go"), }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, Edits: []TextEdit{ { @@ -1418,7 +1454,7 @@ func testApplyWorkspaceEditParams(t *testing.T, marshal marshalFunc, unmarshal u TextDocumentIdentifier: TextDocumentIdentifier{ URI: uri.File("/path/to/basic.go"), }, - Version: Uint64Ptr(10), + Version: NewVersion(10), }, Edits: []TextEdit{ {