From 615f9a6b8157525b81924a50cf3b81b3a129cf07 Mon Sep 17 00:00:00 2001 From: pjw Date: Mon, 29 Nov 2021 21:09:08 -0500 Subject: [PATCH] internal/lsp/protocol: bring the LSP stubs up to date There are no changes, other than generated code, to gopls. The vscode typescript implementation includes 3 new and undocumented RPCs: InlineValues, InlineValuesRefresh, and ResolveWorkspaceSymbol. There are some places that need work, marked by //PJW: comments in code.ts. Change-Id: I20e4c6792ae37323bb9c887ffefbe81930ef62fe Reviewed-on: https://go-review.googlesource.com/c/tools/+/367845 Trust: Peter Weinberger Reviewed-by: Robert Findley --- internal/lsp/protocol/tsclient.go | 10 +- internal/lsp/protocol/tsprotocol.go | 514 ++++++++++++++++++--- internal/lsp/protocol/tsserver.go | 59 ++- internal/lsp/protocol/typescript/README.md | 2 +- internal/lsp/protocol/typescript/code.ts | 27 +- internal/lsp/protocol/typescript/util.ts | 4 +- internal/lsp/server_gen.go | 12 + 7 files changed, 532 insertions(+), 96 deletions(-) diff --git a/internal/lsp/protocol/tsclient.go b/internal/lsp/protocol/tsclient.go index 646beb073a5..87bd313c5c6 100644 --- a/internal/lsp/protocol/tsclient.go +++ b/internal/lsp/protocol/tsclient.go @@ -6,8 +6,8 @@ package protocol // Package protocol contains data types and code for LSP jsonrpcs // generated automatically from vscode-languageserver-node -// commit: 10b56de150ad67c3c330da8e2df53ebf2cf347c4 -// last fetched Wed Sep 29 2021 12:31:31 GMT-0400 (Eastern Daylight Time) +// commit: d959faf4be476a6e0a08d5612e91fcac14ff9929 +// last fetched Mon Nov 29 2021 15:51:05 GMT-0500 (Eastern Standard Time) // Code generated (see typescript/README.md) DO NOT EDIT. @@ -26,7 +26,7 @@ type Client interface { PublishDiagnostics(context.Context, *PublishDiagnosticsParams) error Progress(context.Context, *ProgressParams) error WorkspaceFolders(context.Context) ([]WorkspaceFolder /*WorkspaceFolder[] | null*/, error) - Configuration(context.Context, *ParamConfiguration) ([]interface{}, error) + Configuration(context.Context, *ParamConfiguration) ([]LSPAny, error) WorkDoneProgressCreate(context.Context, *WorkDoneProgressCreateParams) error ShowDocument(context.Context, *ShowDocumentParams) (*ShowDocumentResult, error) RegisterCapability(context.Context, *RegistrationParams) error @@ -160,8 +160,8 @@ func (s *clientDispatcher) WorkspaceFolders(ctx context.Context) ([]WorkspaceFol return result, nil } -func (s *clientDispatcher) Configuration(ctx context.Context, params *ParamConfiguration) ([]interface{}, error) { - var result []interface{} +func (s *clientDispatcher) Configuration(ctx context.Context, params *ParamConfiguration) ([]LSPAny, error) { + var result []LSPAny if err := s.sender.Call(ctx, "workspace/configuration", params, &result); err != nil { return nil, err } diff --git a/internal/lsp/protocol/tsprotocol.go b/internal/lsp/protocol/tsprotocol.go index f587d0f1cb7..857b142d128 100644 --- a/internal/lsp/protocol/tsprotocol.go +++ b/internal/lsp/protocol/tsprotocol.go @@ -4,8 +4,8 @@ // Package protocol contains data types and code for LSP jsonrpcs // generated automatically from vscode-languageserver-node -// commit: 10b56de150ad67c3c330da8e2df53ebf2cf347c4 -// last fetched Wed Sep 29 2021 12:31:31 GMT-0400 (Eastern Daylight Time) +// commit: d959faf4be476a6e0a08d5612e91fcac14ff9929 +// last fetched Mon Nov 29 2021 15:51:05 GMT-0500 (Eastern Standard Time) package protocol // Code generated (see typescript/README.md) DO NOT EDIT. @@ -145,7 +145,7 @@ type CallHierarchyItem struct { * A data entry field that is preserved between a call hierarchy prepare and * incoming calls or outgoing calls requests. */ - Data interface{} `json:"data,omitempty"` + Data LSPAny `json:"data,omitempty"` } /** @@ -359,7 +359,7 @@ type CodeAction struct { * * @since 3.16.0 */ - Data interface{} `json:"data,omitempty"` + Data LSPAny `json:"data,omitempty"` } /** @@ -382,13 +382,7 @@ type CodeActionClientCapabilities struct { * The code action kind is support with the following value * set. */ - CodeActionKind struct { - /** - * The code action kind values the client supports. When this - * property exists the client also guarantees that it will - * handle values outside its set gracefully and falls back - * to a default value when unknown. - */ + CodeActionKind struct { /** * The code action kind values the client supports. When this * property exists the client also guarantees that it will * handle values outside its set gracefully and falls back * to a default value when unknown. */ ValueSet []CodeActionKind `json:"valueSet"` } `json:"codeActionKind"` } `json:"codeActionLiteralSupport,omitempty"` @@ -456,6 +450,12 @@ type CodeActionContext struct { * can omit computing them. */ Only []CodeActionKind `json:"only,omitempty"` + /** + * The reason why code actions were requested. + * + * @since 3.17.0 + */ + TriggerKind CodeActionTriggerKind `json:"triggerKind,omitempty"` } /** @@ -504,6 +504,13 @@ type CodeActionParams struct { PartialResultParams } +/** + * The reason why code actions were requested. + * + * @since 3.17.0 - proposed state + */ +type CodeActionTriggerKind float64 + /** * Structure to capture a description for an error code. * @@ -537,7 +544,7 @@ type CodeLens struct { * a [CodeLensRequest](#CodeLensRequest) and a [CodeLensResolveRequest] * (#CodeLensResolveRequest) */ - Data interface{} `json:"data,omitempty"` + Data LSPAny `json:"data,omitempty"` } /** @@ -738,10 +745,7 @@ type CompletionClientCapabilities struct { * * @since 3.15.0 */ - TagSupport struct { - /** - * The tags supported by the client. - */ + TagSupport struct { /** * The tags supported by the client. */ ValueSet []CompletionItemTag `json:"valueSet"` } `json:"tagSupport,omitempty"` /** @@ -758,10 +762,7 @@ type CompletionClientCapabilities struct { * * @since 3.16.0 */ - ResolveSupport struct { - /** - * The properties that a client can resolve lazily. - */ + ResolveSupport struct { /** * The properties that a client can resolve lazily. */ Properties []string `json:"properties"` } `json:"resolveSupport,omitempty"` /** @@ -800,7 +801,7 @@ type CompletionClientCapabilities struct { * when accepting a completion item that uses multi line * text in either `insertText` or `textEdit`. * - * @since 3.17.0 + * @since 3.17.0 - proposed state */ InsertTextMode InsertTextMode `json:"insertTextMode,omitempty"` /** @@ -808,6 +809,25 @@ type CompletionClientCapabilities struct { * `textDocument/completion` request. */ ContextSupport bool `json:"contextSupport,omitempty"` + /** + * The client supports the following `CompletionList` specific + * capabilities. + * + * @since 3.17.0 - proposed state + */ + CompletionList struct { + /** + * The client supports the the following itemDefaults on + * a completion list. + * + * The value lists the supported property names of the + * `CompletionList.itemDefaults` object. If omitted + * no properties are supported. + * + * @since 3.17.0 - proposed state + */ + ItemDefaults []string `json:"itemDefaults,omitempty"` + } `json:"completionList,omitempty"` } /** @@ -908,6 +928,8 @@ type CompletionItem struct { * The format of the insert text. The format applies to both the `insertText` property * and the `newText` property of a provided `textEdit`. If omitted defaults to * `InsertTextFormat.PlainText`. + * + * Please note that the insertTextFormat doesn't apply to `additionalTextEdits`. */ InsertTextFormat InsertTextFormat `json:"insertTextFormat,omitempty"` /** @@ -963,7 +985,7 @@ type CompletionItem struct { * A data entry field that is preserved on a completion item between a * [CompletionRequest](#CompletionRequest) and a [CompletionResolveRequest](#CompletionResolveRequest). */ - Data interface{} `json:"data,omitempty"` + Data LSPAny `json:"data,omitempty"` } /** @@ -1006,6 +1028,47 @@ type CompletionList struct { * This list it not complete. Further typing results in recomputing this list. */ IsIncomplete bool `json:"isIncomplete"` + /** + * In many cases the items of an actual completion result share the same + * value for properties like `commitCharacters` or the range of a text + * edit. A completion list can therefore define item defaults which will + * be used if a completion item itself doesn't specify the value. + * + * If a completion list specifies a default value and a completion item + * also specifies a corresponding value the one from the item is used. + * + * Servers are only allowed to return default values if the client + * signals support for this via the `completionList.itemDefaults` + * capability. + * + * @since 3.17.0 - proposed state + */ + ItemDefaults struct { + /** + * A default commit character set. + * + * @since 3.17.0 - proposed state + */ + CommitCharacters []string `json:"commitCharacters,omitempty"` + /** + * A default edit range + * + * @since 3.17.0 - proposed state + */ + EditRange Range/*Range | { insert: Range; replace: Range; }*/ `json:"editRange,omitempty"` + /** + * A default insert text format + * + * @since 3.17.0 - proposed state + */ + InsertTextFormat InsertTextFormat `json:"insertTextFormat,omitempty"` + /** + * A default insert text mode + * + * @since 3.17.0 - proposed state + */ + InsertTextMode InsertTextMode `json:"insertTextMode,omitempty"` + } `json:"itemDefaults,omitempty"` /** * The completion items. */ @@ -1323,6 +1386,7 @@ type Diagnostic struct { Code interface{}/*integer | string*/ `json:"code,omitempty"` /** * An optional property to describe the error code. + * Requires the code field (above) to be present/not null. * * @since 3.16.0 */ @@ -1354,7 +1418,7 @@ type Diagnostic struct { * * @since 3.16.0 */ - Data interface{} `json:"data,omitempty"` + Data LSPAny `json:"data,omitempty"` } /** @@ -1399,7 +1463,7 @@ type DidChangeConfigurationParams struct { /** * The actual changed settings */ - Settings interface{} `json:"settings"` + Settings LSPAny `json:"settings"` } /** @@ -1697,7 +1761,7 @@ type DocumentLink struct { * A data entry field that is preserved on a document link between a * DocumentLinkRequest and a DocumentLinkResolveRequest. */ - Data interface{} `json:"data,omitempty"` + Data LSPAny `json:"data,omitempty"` } /** @@ -1851,7 +1915,7 @@ type DocumentSymbol struct { */ Kind SymbolKind `json:"kind"` /** - * Tags for this completion item. + * Tags for this document symbol. * * @since 3.16.0 */ @@ -2378,7 +2442,7 @@ type GeneralClientCapabilities struct { /** * The list of requests for which the client * will retry the request if it receives a - * response with error code `ContentModified`` + * response with error code `ContentModified` */ RetryOnContentModified []string `json:"retryOnContentModified"` } `json:"staleRequestSupport,omitempty"` @@ -2530,11 +2594,11 @@ type InitializeParams struct { /** * User provided initialization options. */ - InitializationOptions interface{} `json:"initializationOptions,omitempty"` + InitializationOptions LSPAny `json:"initializationOptions,omitempty"` /** * The initial trace setting. If omitted trace is disabled ('off'). */ - Trace string/*'off' | 'messages' | 'verbose'*/ `json:"trace,omitempty"` + Trace string/* 'off' | 'messages' | 'compact' | 'verbose' */ `json:"trace,omitempty"` /** * The actual configured workspace folders. */ @@ -2569,6 +2633,158 @@ type InitializeResult struct { type InitializedParams struct { } +/** + * Inline value information can be provided by different means: + * - directly as a text value (class InlineValueText). + * - as a name to use for a variable lookup (class InlineValueVariableLookup) + * - as an evaluatable expression (class InlineValueEvaluatableExpression) + * The InlineValue types combines all inline value types into one type. + * + * @since 3.17.0 - proposed state + */ +type InlineValue = interface{} /* InlineValueText | InlineValueVariableLookup | InlineValueEvaluatableExpression*/ + +/** + * Provide an inline value through an expression evaluation. + * If only a range is specified, the expression will be extracted from the underlying document. + * An optional expression can be used to override the extracted expression. + * + * @since 3.17.0 - proposed state + */ +type InlineValueEvaluatableExpression struct { + /** + * The document range for which the inline value applies. + * The range is used to extract the evaluatable expression from the underlying document. + */ + Range Range `json:"range"` + /** + * If specified the expression overrides the extracted expression. + */ + Expression string `json:"expression,omitempty"` +} + +/** + * Provide inline value as text. + * + * @since 3.17.0 - proposed state + */ +type InlineValueText struct { + /** + * The document range for which the inline value applies. + */ + Range Range `json:"range"` + /** + * The text of the inline value. + */ + Text string `json:"text"` +} + +/** + * Provide inline value through a variable lookup. + * If only a range is specified, the variable name will be extracted from the underlying document. + * An optional variable name can be used to override the extracted name. + * + * @since 3.17.0 - proposed state + */ +type InlineValueVariableLookup struct { + /** + * The document range for which the inline value applies. + * The range is used to extract the variable name from the underlying document. + */ + Range Range `json:"range"` + /** + * If specified the name of the variable to look up. + */ + VariableName string `json:"variableName,omitempty"` + /** + * How to perform the lookup. + */ + CaseSensitiveLookup bool `json:"caseSensitiveLookup"` +} + +/** + * Client capabilities specific to inline values. + * + * @since 3.17.0 - proposed state + */ +type InlineValuesClientCapabilities struct { + /** + * Whether implementation supports dynamic registration for inline value providers. + */ + DynamicRegistration bool `json:"dynamicRegistration,omitempty"` +} + +/** + * @since 3.17.0 - proposed state + */ +type InlineValuesContext struct { + /** + * The document range where execution has stopped. + * Typically the end position of the range denotes the line where the inline values are shown. + */ + StoppedLocation Range `json:"stoppedLocation"` +} + +/** + * Inline values options used during static registration. + * + * @since 3.17.0 - proposed state + */ +type InlineValuesOptions struct { + WorkDoneProgressOptions +} + +/** + * A parameter literal used in inline values requests. + * + * @since 3.17.0 - proposed state + */ +type InlineValuesParams struct { + /** + * The text document. + */ + TextDocument TextDocumentIdentifier `json:"textDocument"` + /** + * The visible document range for which inline values should be computed. + */ + ViewPort Range `json:"viewPort"` + /** + * Additional information about the context in which inline values were + * requested. + */ + Context InlineValuesContext `json:"context"` + WorkDoneProgressParams +} + +/** + * Inline value options used during static or dynamic registration. + * + * @since 3.17.0 - proposed state + */ +type InlineValuesRegistrationOptions struct { + InlineValuesOptions + TextDocumentRegistrationOptions + StaticRegistrationOptions +} + +/** + * Client workspace capabilities specific to inline values. + * + * @since 3.17.0 - proposed state + */ +type InlineValuesWorkspaceClientCapabilities struct { + /** + * Whether the client implementation supports a refresh request sent from the + * server to the client. + * + * Note that this event is global and will force the client to refresh all + * inline values currently shown. It should be used with absolute care and is + * useful for situation where a server for example detect a project wide + * change that requires such a calculation. + */ + RefreshSupport bool `json:"refreshSupport,omitempty"` +} + /** * A special text edit to provide an insert and a replace operation. * @@ -2603,6 +2819,27 @@ type InsertTextFormat float64 */ type InsertTextMode float64 +/** + * The LSP any type + * + * @since 3.17.0 + */ +type LSPAny = interface{} /* LSPObject | LSPArray | string | int32 | uint32 | Decimal | bool | float64*/ + +/** + * LSP arrays. + * + * @since 3.17.0 + */ +type LSPArray = []LSPAny + +/** + * LSP object definition. + * + * @since 3.17.0 + */ +type LSPObject = map[string]interface{} /*[key: string]: LSPAny*/ + /** * Client capabilities for the linked editing range request. * @@ -2722,6 +2959,13 @@ type MarkdownClientCapabilities struct { * The version of the parser. */ Version string `json:"version,omitempty"` + /** + * A list of HTML tags that the client allows / supports in + * Markdown. + * + * @since 3.17.0 + */ + AllowedTags []string `json:"allowedTags,omitempty"` } /** @@ -3107,7 +3351,7 @@ type Registration struct { /** * Options necessary for the registration. */ - RegisterOptions interface{} `json:"registerOptions,omitempty"` + RegisterOptions LSPAny `json:"registerOptions,omitempty"` } type RegistrationParams struct { @@ -3432,6 +3676,28 @@ type SemanticTokensClientCapabilities struct { * Whether the client supports tokens that can span multiple lines. */ MultilineTokenSupport bool `json:"multilineTokenSupport,omitempty"` + /** + * Whether the client allows the server to actively cancel a + * semantic token request, e.g. supports returning + * LSPErrorCodes.ServerCancelled. If a server does the client + * needs to retrigger the request. + * + * @since 3.17.0 + */ + ServerCancelSupport bool `json:"serverCancelSupport,omitempty"` + /** + * Whether the client uses semantic tokens to augment existing + * syntax tokens. If set to `true` client side created syntax + * tokens and semantic tokens are both used for colorization. If + * set to `false` the client only uses the returned semantic tokens + * for colorization. + * + * If the value is `undefined` then the client behavior is not + * specified. + * + * @since 3.17.0 + */ + AugmentsSyntaxTokens bool `json:"augmentsSyntaxTokens,omitempty"` } /** @@ -3699,6 +3965,12 @@ type ServerCapabilities struct { * @since 3.17.0 - proposed state */ TypeHierarchyProvider interface{}/* bool | TypeHierarchyOptions | TypeHierarchyRegistrationOptions*/ `json:"typeHierarchyProvider,omitempty"` + /** + * The server provides inline values. + * + * @since 3.17.0 - proposed state + */ + InlineValuesProvider interface{}/* bool | InlineValuesOptions | InlineValuesOptions | InlineValuesRegistrationOptions*/ `json:"inlineValuesProvider,omitempty"` /** * Experimental server capabilities. */ @@ -3823,15 +4095,27 @@ type SignatureHelp struct { */ Signatures []SignatureInformation `json:"signatures"` /** - * The active signature. Set to `null` if no - * signatures exist. + * The active signature. If omitted or the value lies outside the + * range of `signatures` the value defaults to zero or is ignored if + * the `SignatureHelp` has no signatures. + * + * Whenever possible implementors should make an active decision about + * the active signature and shouldn't rely on a default value. + * + * In future version of the protocol this property might become + * mandatory to better express this. */ - ActiveSignature uint32/*uinteger | null*/ `json:"activeSignature"` + ActiveSignature uint32 `json:"activeSignature,omitempty"` /** - * The active parameter of the active signature. Set to `null` - * if the active signature has no parameters. + * The active parameter of the active signature. If omitted or the value + * lies outside the range of `signatures[activeSignature].parameters` + * defaults to 0 if the active signature has parameters. If + * the active signature has no parameters it is ignored. + * In future version of the protocol this property might become + * mandatory to better express the active parameter if the + * active signature does have any. */ - ActiveParameter uint32/*uinteger | null*/ `json:"activeParameter"` + ActiveParameter uint32 `json:"activeParameter,omitempty"` } /** @@ -3855,13 +4139,7 @@ type SignatureHelpClientCapabilities struct { /** * Client capabilities specific to parameter information. */ - ParameterInformation struct { - /** - * The client supports processing label offsets instead of a - * simple label string. - * - * @since 3.14.0 - */ + ParameterInformation struct { /** * The client supports processing label offsets instead of a * simple label string. * * @since 3.14.0 */ LabelOffsetSupport bool `json:"labelOffsetSupport,omitempty"` } `json:"parameterInformation,omitempty"` /** @@ -4188,6 +4466,12 @@ type TextDocumentClientCapabilities struct { * @since 3.17.0 - proposed state */ TypeHierarchy TypeHierarchyClientCapabilities `json:"typeHierarchy,omitempty"` + /** + * Capabilities specific to the `textDocument/inlineValues` request. + * + * @since 3.17.0 - proposed state + */ + InlineValues InlineValuesClientCapabilities `json:"inlineValues,omitempty"` } /** @@ -4369,7 +4653,7 @@ type TextEdit struct { type TokenFormat = string -type TraceValues = string /*'off' | 'messages' | 'verbose'*/ +type TraceValues = string /* 'off' | 'messages' | 'compact' | 'verbose' */ /** * Since 3.6.0 @@ -4458,7 +4742,7 @@ type TypeHierarchyItem struct { * type hierarchy in the server, helping improve the performance on * resolving supertypes and subtypes. */ - Data interface{} `json:"data,omitempty"` + Data LSPAny `json:"data,omitempty"` } /** @@ -4767,6 +5051,13 @@ type WorkspaceClientCapabilities struct { * Since 3.16.0 */ FileOperations FileOperationClientCapabilities `json:"fileOperations,omitempty"` + /** + * Capabilities specific to the inline values requests scoped to the + * workspace. + * + * @since 3.17.0. + */ + InlineValues InlineValuesWorkspaceClientCapabilities `json:"inlineValues,omitempty"` } /** @@ -4822,7 +5113,7 @@ type WorkspaceEdit struct { /** * Holds changes to existing resources. */ - Changes map[string][]TextEdit/*[uri: string]: TextEdit[];*/ `json:"changes,omitempty"` + Changes map[DocumentURI]interface{}/*[uri: DocumentUri]: TextEdit[];*/ `json:"changes,omitempty"` /** * Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes * are either an array of `TextDocumentEdit`s to express changes to n different text documents @@ -4844,7 +5135,7 @@ type WorkspaceEdit struct { * * @since 3.16.0 */ - ChangeAnnotations map[string]ChangeAnnotationIdentifier/*[id: string * ChangeAnnotationIdentifier *]: ChangeAnnotation;*/ `json:"changeAnnotations,omitempty"` + ChangeAnnotations map[string]ChangeAnnotationIdentifier/*[id: ChangeAnnotationIdentifier]: ChangeAnnotation;*/ `json:"changeAnnotations,omitempty"` } type WorkspaceEditClientCapabilities struct { @@ -4957,6 +5248,25 @@ type WorkspaceFullDocumentDiagnosticReport struct { FullDocumentDiagnosticReport } +/** + * A special workspace symbol that supports locations without a range + * + * @since 3.17.0 - proposed state + */ +type WorkspaceSymbol struct { + /** + * The location of the symbol. + * + * See SymbolInformation#location for more details. + */ + Location Location/*Location | { uri: DocumentUri; }*/ `json:"location"` + /** + * A data entry field that is preserved on a workspace symbol between a + * workspace symbol request and a workspace symbol resolve request. + */ + Data LSPAny `json:"data,omitempty"` +} + /** * Client capabilities for a [WorkspaceSymbolRequest](#WorkspaceSymbolRequest). */ @@ -4993,12 +5303,33 @@ type WorkspaceSymbolClientCapabilities struct { */ ValueSet []SymbolTag `json:"valueSet"` } `json:"tagSupport,omitempty"` + /** + * The client support partial workspace symbols. The client will send the + * request `workspaceSymbol/resolve` to the server to resolve additional + * properties. + * + * @since 3.17.0 - proposedState + */ + ResolveSupport struct { + /** + * The properties that a client can resolve lazily. Usually + * `location.range` + */ + Properties []string `json:"properties"` + } `json:"resolveSupport,omitempty"` } /** * Server capabilities for a [WorkspaceSymbolRequest](#WorkspaceSymbolRequest). */ type WorkspaceSymbolOptions struct { + /** + * The server provides support to resolve additional + * information for a workspace symbol. + * + * @since 3.17.0 - proposed state + */ + ResolveProvider bool `json:"resolveProvider,omitempty"` WorkDoneProgressOptions } @@ -5109,32 +5440,45 @@ const ( * @since 3.15.0 */ - SourceFixAll CodeActionKind = "source.fixAll" - TextCompletion CompletionItemKind = 1 - MethodCompletion CompletionItemKind = 2 - FunctionCompletion CompletionItemKind = 3 - ConstructorCompletion CompletionItemKind = 4 - FieldCompletion CompletionItemKind = 5 - VariableCompletion CompletionItemKind = 6 - ClassCompletion CompletionItemKind = 7 - InterfaceCompletion CompletionItemKind = 8 - ModuleCompletion CompletionItemKind = 9 - PropertyCompletion CompletionItemKind = 10 - UnitCompletion CompletionItemKind = 11 - ValueCompletion CompletionItemKind = 12 - EnumCompletion CompletionItemKind = 13 - KeywordCompletion CompletionItemKind = 14 - SnippetCompletion CompletionItemKind = 15 - ColorCompletion CompletionItemKind = 16 - FileCompletion CompletionItemKind = 17 - ReferenceCompletion CompletionItemKind = 18 - FolderCompletion CompletionItemKind = 19 - EnumMemberCompletion CompletionItemKind = 20 - ConstantCompletion CompletionItemKind = 21 - StructCompletion CompletionItemKind = 22 - EventCompletion CompletionItemKind = 23 - OperatorCompletion CompletionItemKind = 24 - TypeParameterCompletion CompletionItemKind = 25 + SourceFixAll CodeActionKind = "source.fixAll" + /** + * Code actions were explicitly requested by the user or by an extension. + */ + + CodeActionInvoked CodeActionTriggerKind = 1 + /** + * Code actions were requested automatically. + * + * This typically happens when current selection in a file changes, but can + * also be triggered when file content changes. + */ + + CodeActionAutomatic CodeActionTriggerKind = 2 + TextCompletion CompletionItemKind = 1 + MethodCompletion CompletionItemKind = 2 + FunctionCompletion CompletionItemKind = 3 + ConstructorCompletion CompletionItemKind = 4 + FieldCompletion CompletionItemKind = 5 + VariableCompletion CompletionItemKind = 6 + ClassCompletion CompletionItemKind = 7 + InterfaceCompletion CompletionItemKind = 8 + ModuleCompletion CompletionItemKind = 9 + PropertyCompletion CompletionItemKind = 10 + UnitCompletion CompletionItemKind = 11 + ValueCompletion CompletionItemKind = 12 + EnumCompletion CompletionItemKind = 13 + KeywordCompletion CompletionItemKind = 14 + SnippetCompletion CompletionItemKind = 15 + ColorCompletion CompletionItemKind = 16 + FileCompletion CompletionItemKind = 17 + ReferenceCompletion CompletionItemKind = 18 + FolderCompletion CompletionItemKind = 19 + EnumMemberCompletion CompletionItemKind = 20 + ConstantCompletion CompletionItemKind = 21 + StructCompletion CompletionItemKind = 22 + EventCompletion CompletionItemKind = 23 + OperatorCompletion CompletionItemKind = 24 + TypeParameterCompletion CompletionItemKind = 25 /** * Render a completion as obsolete, usually using a strike-out. */ @@ -5553,6 +5897,14 @@ type Workspace2Gn struct { */ FileOperations *FileOperationClientCapabilities `json:"fileOperations,omitempty"` + /** + * Capabilities specific to the inline values requests scoped to the + * workspace. + * + * @since 3.17.0. + */ + InlineValues InlineValuesWorkspaceClientCapabilities `json:"inlineValues,omitempty"` + /** * The client has support for workspace folders * @@ -5623,6 +5975,14 @@ type Workspace3Gn struct { */ FileOperations *FileOperationClientCapabilities `json:"fileOperations,omitempty"` + /** + * Capabilities specific to the inline values requests scoped to the + * workspace. + * + * @since 3.17.0. + */ + InlineValues InlineValuesWorkspaceClientCapabilities `json:"inlineValues,omitempty"` + /** * The client has support for workspace folders * @@ -5720,6 +6080,14 @@ type Workspace6Gn struct { */ FileOperations *FileOperationClientCapabilities `json:"fileOperations,omitempty"` + /** + * Capabilities specific to the inline values requests scoped to the + * workspace. + * + * @since 3.17.0. + */ + InlineValues InlineValuesWorkspaceClientCapabilities `json:"inlineValues,omitempty"` + /** * The client has support for workspace folders * diff --git a/internal/lsp/protocol/tsserver.go b/internal/lsp/protocol/tsserver.go index dec6d418969..26ca4db671c 100644 --- a/internal/lsp/protocol/tsserver.go +++ b/internal/lsp/protocol/tsserver.go @@ -6,8 +6,8 @@ package protocol // Package protocol contains data types and code for LSP jsonrpcs // generated automatically from vscode-languageserver-node -// commit: 10b56de150ad67c3c330da8e2df53ebf2cf347c4 -// last fetched Wed Sep 29 2021 12:31:31 GMT-0400 (Eastern Daylight Time) +// commit: d959faf4be476a6e0a08d5612e91fcac14ff9929 +// last fetched Mon Nov 29 2021 15:51:05 GMT-0500 (Eastern Standard Time) // Code generated (see typescript/README.md) DO NOT EDIT. @@ -58,6 +58,8 @@ type Server interface { PrepareTypeHierarchy(context.Context, *TypeHierarchyPrepareParams) ([]TypeHierarchyItem /*TypeHierarchyItem[] | null*/, error) Supertypes(context.Context, *TypeHierarchySupertypesParams) ([]TypeHierarchyItem /*TypeHierarchyItem[] | null*/, error) Subtypes(context.Context, *TypeHierarchySubtypesParams) ([]TypeHierarchyItem /*TypeHierarchyItem[] | null*/, error) + InlineValues(context.Context, *InlineValuesParams) ([]InlineValue /*InlineValue[] | null*/, error) + InlineValuesRefresh(context.Context) error Initialize(context.Context, *ParamInitialize) (*InitializeResult, error) Shutdown(context.Context) error WillSaveWaitUntil(context.Context, *WillSaveTextDocumentParams) ([]TextEdit /*TextEdit[] | null*/, error) @@ -71,7 +73,8 @@ type Server interface { DocumentSymbol(context.Context, *DocumentSymbolParams) ([]interface{} /*SymbolInformation[] | DocumentSymbol[] | null*/, error) CodeAction(context.Context, *CodeActionParams) ([]CodeAction /*(Command | CodeAction)[] | null*/, error) ResolveCodeAction(context.Context, *CodeAction) (*CodeAction, error) - Symbol(context.Context, *WorkspaceSymbolParams) ([]SymbolInformation /*SymbolInformation[] | null*/, error) + Symbol(context.Context, *WorkspaceSymbolParams) ([]SymbolInformation /*SymbolInformation[] | WorkspaceSymbol[] | null*/, error) + ResolveWorkspaceSymbol(context.Context, *WorkspaceSymbol) (*WorkspaceSymbol, error) CodeLens(context.Context, *CodeLensParams) ([]CodeLens /*CodeLens[] | null*/, error) ResolveCodeLens(context.Context, *CodeLens) (*CodeLens, error) CodeLensRefresh(context.Context) error @@ -82,7 +85,7 @@ type Server interface { OnTypeFormatting(context.Context, *DocumentOnTypeFormattingParams) ([]TextEdit /*TextEdit[] | null*/, error) Rename(context.Context, *RenameParams) (*WorkspaceEdit /*WorkspaceEdit | null*/, error) PrepareRename(context.Context, *PrepareRenameParams) (*Range /*Range | { range: Range, placeholder: string } | { defaultBehavior: boolean } | null*/, error) - ExecuteCommand(context.Context, *ExecuteCommandParams) (interface{} /*any | null*/, error) + ExecuteCommand(context.Context, *ExecuteCommandParams) (interface{} /* LSPAny | void | float64*/, error) Diagnostic(context.Context, *string) (*string, error) DiagnosticWorkspace(context.Context, *WorkspaceDiagnosticParams) (*WorkspaceDiagnosticReport, error) DiagnosticRefresh(context.Context) error @@ -352,6 +355,19 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, } resp, err := server.Subtypes(ctx, ¶ms) return true, reply(ctx, resp, err) + case "textDocument/inlineValues": // req + var params InlineValuesParams + if err := json.Unmarshal(r.Params(), ¶ms); err != nil { + return true, sendParseError(ctx, reply, err) + } + resp, err := server.InlineValues(ctx, ¶ms) + return true, reply(ctx, resp, err) + case "workspace/inlineValues/refresh": // req + if len(r.Params()) > 0 { + return true, reply(ctx, nil, errors.Errorf("%w: expected no params", jsonrpc2.ErrInvalidParams)) + } + err := server.InlineValuesRefresh(ctx) + return true, reply(ctx, nil, err) case "initialize": // req var params ParamInitialize if err := json.Unmarshal(r.Params(), ¶ms); err != nil { @@ -451,6 +467,13 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, } resp, err := server.Symbol(ctx, ¶ms) return true, reply(ctx, resp, err) + case "workspaceSymbol/resolve": // req + var params WorkspaceSymbol + if err := json.Unmarshal(r.Params(), ¶ms); err != nil { + return true, sendParseError(ctx, reply, err) + } + resp, err := server.ResolveWorkspaceSymbol(ctx, ¶ms) + return true, reply(ctx, resp, err) case "textDocument/codeLens": // req var params CodeLensParams if err := json.Unmarshal(r.Params(), ¶ms); err != nil { @@ -788,6 +811,18 @@ func (s *serverDispatcher) Subtypes(ctx context.Context, params *TypeHierarchySu return result, nil } +func (s *serverDispatcher) InlineValues(ctx context.Context, params *InlineValuesParams) ([]InlineValue /*InlineValue[] | null*/, error) { + var result []InlineValue /*InlineValue[] | null*/ + if err := s.sender.Call(ctx, "textDocument/inlineValues", params, &result); err != nil { + return nil, err + } + return result, nil +} + +func (s *serverDispatcher) InlineValuesRefresh(ctx context.Context) error { + return s.sender.Call(ctx, "workspace/inlineValues/refresh", nil, nil) +} + func (s *serverDispatcher) Initialize(ctx context.Context, params *ParamInitialize) (*InitializeResult, error) { var result *InitializeResult if err := s.sender.Call(ctx, "initialize", params, &result); err != nil { @@ -888,14 +923,22 @@ func (s *serverDispatcher) ResolveCodeAction(ctx context.Context, params *CodeAc return result, nil } -func (s *serverDispatcher) Symbol(ctx context.Context, params *WorkspaceSymbolParams) ([]SymbolInformation /*SymbolInformation[] | null*/, error) { - var result []SymbolInformation /*SymbolInformation[] | null*/ +func (s *serverDispatcher) Symbol(ctx context.Context, params *WorkspaceSymbolParams) ([]SymbolInformation /*SymbolInformation[] | WorkspaceSymbol[] | null*/, error) { + var result []SymbolInformation /*SymbolInformation[] | WorkspaceSymbol[] | null*/ if err := s.sender.Call(ctx, "workspace/symbol", params, &result); err != nil { return nil, err } return result, nil } +func (s *serverDispatcher) ResolveWorkspaceSymbol(ctx context.Context, params *WorkspaceSymbol) (*WorkspaceSymbol, error) { + var result *WorkspaceSymbol + if err := s.sender.Call(ctx, "workspaceSymbol/resolve", params, &result); err != nil { + return nil, err + } + return result, nil +} + func (s *serverDispatcher) CodeLens(ctx context.Context, params *CodeLensParams) ([]CodeLens /*CodeLens[] | null*/, error) { var result []CodeLens /*CodeLens[] | null*/ if err := s.sender.Call(ctx, "textDocument/codeLens", params, &result); err != nil { @@ -972,8 +1015,8 @@ func (s *serverDispatcher) PrepareRename(ctx context.Context, params *PrepareRen return result, nil } -func (s *serverDispatcher) ExecuteCommand(ctx context.Context, params *ExecuteCommandParams) (interface{} /*any | null*/, error) { - var result interface{} /*any | null*/ +func (s *serverDispatcher) ExecuteCommand(ctx context.Context, params *ExecuteCommandParams) (interface{} /* LSPAny | void | float64*/, error) { + var result interface{} /* LSPAny | void | float64*/ if err := s.sender.Call(ctx, "workspace/executeCommand", params, &result); err != nil { return nil, err } diff --git a/internal/lsp/protocol/typescript/README.md b/internal/lsp/protocol/typescript/README.md index 61ba187c672..74bcd1883d1 100644 --- a/internal/lsp/protocol/typescript/README.md +++ b/internal/lsp/protocol/typescript/README.md @@ -48,7 +48,7 @@ the generated files and stored in the variable `gitHash` in `go.ts`. It is check 3. (There's a good chance that soon you will be asked to upgrade your new npm. `sudo npm install -g npm` is the command.) 4. For either system, node and nvm should now be available. Running `node -v` and `npm -v` should produce version numbers. 5. `npm install typescript` - 1. This will likely give warning messages that indicate you've failed to set up a project. Ignore them. + 1. This may give warning messages that indicate you've failed to set up a project. Ignore them. 2. Your home directory will now have new directories `.npm` and `node_modules` (and a `package_lock.json` file) 3. The typescript executable `tsc` will be in `node_modules/.bin`, so put that directory in your path. 4. `tsc -v` should print "Version 4.2.4" (or later). If not you may (as I did) have an obsolete tsc earlier in your path. diff --git a/internal/lsp/protocol/typescript/code.ts b/internal/lsp/protocol/typescript/code.ts index a2620582cf3..d7342aed878 100644 --- a/internal/lsp/protocol/typescript/code.ts +++ b/internal/lsp/protocol/typescript/code.ts @@ -532,6 +532,7 @@ function cleanData() { // middle pass function sameType(a: ts.TypeNode, b: ts.TypeNode): boolean { if (a.kind !== b.kind) return false; if (a.kind === ts.SyntaxKind.BooleanKeyword) return true; + if (a.kind === ts.SyntaxKind.StringKeyword) return true; if (ts.isTypeReferenceNode(a) && ts.isTypeReferenceNode(b) && a.typeName.getText() === b.typeName.getText()) return true; if (ts.isArrayTypeNode(a) && ts.isArrayTypeNode(b)) return sameType(a.elementType, b.elementType); @@ -540,7 +541,7 @@ function sameType(a: ts.TypeNode, b: ts.TypeNode): boolean { if (a.members.length === 1) return a.members[0].name.getText() === b.members[0].name.getText(); if (loc(a) === loc(b)) return true; } - throw new Error(`546 sameType? ${strKind(a)} ${strKind(b)}`); + throw new Error(`544 sameType? ${strKind(a)} ${strKind(b)} ${a.getText()}`); } type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; @@ -721,6 +722,7 @@ function goInterface(d: Data, nm: string) { const f = function (n: ts.ExpressionWithTypeArguments) { if (!ts.isIdentifier(n.expression)) throw new Error(`Interface ${nm} heritage ${strKind(n.expression)} `); + if (n.expression.getText() === 'Omit') return; // Type modification type ans = ans.concat(goName(n.expression.getText()), '\n'); }; d.as.forEach((n: ts.HeritageClause) => n.types.forEach(f)); @@ -896,9 +898,11 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string { return `*TextEdit ${help}`; } if (a == 'TypeReference') { - if (nm == 'edits') return `${goType(n.types[0], '715')} ${help}`; + if (nm == 'edits') return `${goType(n.types[0], '901')} ${help}`; if (a == b) return `interface{} ${help}`; if (nm == 'code') return `interface{} ${help}`; + if (nm == 'editRange') return `${goType(n.types[0], '904')} ${help}`; + if (nm === 'location') return `${goType(n.types[0], '905')} ${help}`; } if (a == 'StringKeyword') return `string ${help}`; if (a == 'TypeLiteral' && nm == 'TextDocumentContentChangeEvent') { @@ -915,6 +919,7 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string { const aa = strKind(n.types[0]); const bb = strKind(n.types[1]); const cc = strKind(n.types[2]); + if (nm === 'workspace/symbol') return `${goType(n.types[0], '930')} ${help}`; if (nm == 'DocumentFilter') { // not really a union. the first is enough, up to a missing // omitempty but avoid repetitious comments @@ -942,9 +947,11 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string { case 4: if (nm == 'documentChanges') return `TextDocumentEdit ${help} `; if (nm == 'textDocument/prepareRename') return `Range ${help} `; - // eslint-disable-next-line no-fallthrough + break; + case 8: // LSPany + break; default: - throw new Error(`goUnionType len=${n.types.length} nm=${nm}`); + throw new Error(`957 goUnionType len=${n.types.length} nm=${nm} ${n.getText()}`); } // Result will be interface{} with a comment @@ -1048,7 +1055,7 @@ function isStructType(te: ts.TypeNode): boolean { case 'TypeReference': { if (!ts.isTypeReferenceNode(te)) throw new Error(`1047 impossible ${strKind(te)}`); const d = seenTypes.get(goName(te.typeName.getText())); - if (d === undefined) return false; + if (d === undefined || d.properties.length == 0) return false; if (d.properties.length > 1) return true; // alias or interface with a single property (The alias is Uinteger, which we ignore later) if (d.alias) return false; @@ -1067,6 +1074,8 @@ function goTypeLiteral(n: ts.TypeLiteralNode, nm: string): string { if (ts.isPropertySignature(nx)) { let json = u.JSON(nx); let typ = goType(nx.type, nx.name.getText()); + // }/*\n*/`json:v` is not legal, the comment is a newline + typ = typ.replace(/\n\t*/g, ' '); // PJW: try to do this only when needed const v = getComments(nx) || ''; starred.forEach(([a, b]) => { if (a != nm || b != typ.toLowerCase()) return; @@ -1080,12 +1089,16 @@ function goTypeLiteral(n: ts.TypeLiteralNode, nm: string): string { const comment = nx.getText().replace(/[/]/g, ''); if (nx.getText() == '[uri: string]: TextEdit[];') { res = 'map[string][]TextEdit'; - } else if (nx.getText() == '[id: string /* ChangeAnnotationIdentifier */]: ChangeAnnotation;') { + } else if (nx.getText().startsWith('[id: ChangeAnnotationIdentifier]')) { res = 'map[string]ChangeAnnotationIdentifier'; } else if (nx.getText().startsWith('[uri: string')) { res = 'map[string]interface{}'; + } else if (nx.getText().startsWith('[uri: DocumentUri')) { + res = 'map[DocumentURI]interface{}'; //PJW make this more precise + } else if (nx.getText().startsWith('[key: string')) { + res = 'map[string]interface{}'; } else { - throw new Error(`1088 handle ${nx.getText()} ${loc(nx)}`); + throw new Error(`1100 handle ${nx.getText()} ${loc(nx)}`); } res += ` /*${comment}*/`; ans.push(res); diff --git a/internal/lsp/protocol/typescript/util.ts b/internal/lsp/protocol/typescript/util.ts index 84fdcf35373..165ba9becde 100644 --- a/internal/lsp/protocol/typescript/util.ts +++ b/internal/lsp/protocol/typescript/util.ts @@ -15,7 +15,7 @@ export const fnames = [ `${dir}/${srcDir}/protocol/src/browser/main.ts`, `${dir}${srcDir}/types/src/main.ts`, `${dir}${srcDir}/jsonrpc/src/node/main.ts` ]; -export const gitHash = '10b56de150ad67c3c330da8e2df53ebf2cf347c4'; +export const gitHash = 'd959faf4be476a6e0a08d5612e91fcac14ff9929'; let outFname = 'tsprotocol.go'; let fda: number, fdb: number, fde: number; // file descriptors @@ -112,7 +112,7 @@ export function constName(nm: string, type: string): string { let pref = new Map([ ['DiagnosticSeverity', 'Severity'], ['WatchKind', 'Watch'], ['SignatureHelpTriggerKind', 'Sig'], ['CompletionItemTag', 'Compl'], - ['Integer', 'INT_'], ['Uinteger', 'UINT_'] + ['Integer', 'INT_'], ['Uinteger', 'UINT_'], ['CodeActionTriggerKind', 'CodeAction'] ]); // typeName->prefix let suff = new Map([ ['CompletionItemKind', 'Completion'], ['InsertTextFormat', 'TextFormat'], diff --git a/internal/lsp/server_gen.go b/internal/lsp/server_gen.go index 3ed395246b9..85d84cfdb1c 100644 --- a/internal/lsp/server_gen.go +++ b/internal/lsp/server_gen.go @@ -144,6 +144,14 @@ func (s *Server) Initialized(ctx context.Context, params *protocol.InitializedPa return s.initialized(ctx, params) } +func (s *Server) InlineValues(context.Context, *protocol.InlineValuesParams) ([]protocol.InlineValue, error) { + return nil, notImplemented("InlineValues") +} + +func (s *Server) InlineValuesRefresh(context.Context) error { + return notImplemented("InlineValuesRefresh") +} + func (s *Server) LinkedEditingRange(context.Context, *protocol.LinkedEditingRangeParams) (*protocol.LinkedEditingRanges, error) { return nil, notImplemented("LinkedEditingRange") } @@ -208,6 +216,10 @@ func (s *Server) ResolveDocumentLink(context.Context, *protocol.DocumentLink) (* return nil, notImplemented("ResolveDocumentLink") } +func (s *Server) ResolveWorkspaceSymbol(context.Context, *protocol.WorkspaceSymbol) (*protocol.WorkspaceSymbol, error) { + return nil, notImplemented("ResolveWorkspaceSymbol") +} + func (s *Server) SelectionRange(context.Context, *protocol.SelectionRangeParams) ([]protocol.SelectionRange, error) { return nil, notImplemented("SelectionRange") }