diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2025-02-23 08:20:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-23 08:20:19 -0800 |
commit | 9304a417af9998a8164c2b66d6033f9586d36c56 (patch) | |
tree | 0ee67cbcf8e165cabdd28a58f0621d2444664b76 | |
parent | 0c9c140f91c97dfacf8648a5fee90b06d8c50bbc (diff) | |
parent | e4c1f6667b146cfe33df49e5c5984d4d303c5aec (diff) | |
download | rneovim-9304a417af9998a8164c2b66d6033f9586d36c56.tar.gz rneovim-9304a417af9998a8164c2b66d6033f9586d36c56.tar.bz2 rneovim-9304a417af9998a8164c2b66d6033f9586d36c56.zip |
Merge #32503 feat(lsp): use the meta model to generate server capability map
-rw-r--r-- | runtime/lua/vim/lsp.lua | 49 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/_meta/protocol.lua | 230 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/client.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/protocol.lua | 77 | ||||
-rw-r--r-- | scripts/gen_lsp.lua | 131 |
5 files changed, 382 insertions, 107 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index a45f9adeb6..cbec06df02 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -38,55 +38,6 @@ lsp._resolve_to_request = { [ms.inlayHint_resolve] = ms.textDocument_inlayHint, } --- maps request name to the required server_capability in the client. -lsp._request_name_to_capability = { - [ms.callHierarchy_incomingCalls] = { 'callHierarchyProvider' }, - [ms.callHierarchy_outgoingCalls] = { 'callHierarchyProvider' }, - [ms.codeAction_resolve] = { 'codeActionProvider', 'resolveProvider' }, - [ms.codeLens_resolve] = { 'codeLensProvider', 'resolveProvider' }, - [ms.documentLink_resolve] = { 'documentLinkProvider', 'resolveProvider' }, - [ms.inlayHint_resolve] = { 'inlayHintProvider', 'resolveProvider' }, - [ms.textDocument_codeAction] = { 'codeActionProvider' }, - [ms.textDocument_codeLens] = { 'codeLensProvider' }, - [ms.textDocument_completion] = { 'completionProvider' }, - [ms.textDocument_declaration] = { 'declarationProvider' }, - [ms.textDocument_definition] = { 'definitionProvider' }, - [ms.textDocument_diagnostic] = { 'diagnosticProvider' }, - [ms.textDocument_didClose] = { 'textDocumentSync', 'openClose' }, - [ms.textDocument_didOpen] = { 'textDocumentSync', 'openClose' }, - [ms.textDocument_documentColor] = { 'colorProvider' }, - [ms.textDocument_documentHighlight] = { 'documentHighlightProvider' }, - [ms.textDocument_documentLink] = { 'documentLinkProvider' }, - [ms.textDocument_documentSymbol] = { 'documentSymbolProvider' }, - [ms.textDocument_foldingRange] = { 'foldingRangeProvider' }, - [ms.textDocument_formatting] = { 'documentFormattingProvider' }, - [ms.textDocument_hover] = { 'hoverProvider' }, - [ms.textDocument_implementation] = { 'implementationProvider' }, - [ms.textDocument_inlayHint] = { 'inlayHintProvider' }, - [ms.textDocument_inlineValue] = { 'inlineValueProvider' }, - [ms.textDocument_linkedEditingRange] = { 'linkedEditingRangeProvider' }, - [ms.textDocument_moniker] = { 'monikerProvider' }, - [ms.textDocument_onTypeFormatting] = { 'documentOnTypeFormattingProvider' }, - [ms.textDocument_prepareCallHierarchy] = { 'callHierarchyProvider' }, - [ms.textDocument_prepareRename] = { 'renameProvider', 'prepareProvider' }, - [ms.textDocument_prepareTypeHierarchy] = { 'typeHierarchyProvider' }, - [ms.textDocument_rangeFormatting] = { 'documentRangeFormattingProvider' }, - [ms.textDocument_rangesFormatting] = { 'documentRangeFormattingProvider', 'rangesSupport' }, - [ms.textDocument_references] = { 'referencesProvider' }, - [ms.textDocument_rename] = { 'renameProvider' }, - [ms.textDocument_selectionRange] = { 'selectionRangeProvider' }, - [ms.textDocument_semanticTokens_full] = { 'semanticTokensProvider' }, - [ms.textDocument_semanticTokens_full_delta] = { 'semanticTokensProvider' }, - [ms.textDocument_signatureHelp] = { 'signatureHelpProvider' }, - [ms.textDocument_typeDefinition] = { 'typeDefinitionProvider' }, - [ms.textDocument_willSaveWaitUntil] = { 'textDocumentSync', 'willSaveWaitUntil' }, - [ms.textDocument_willSave] = { 'textDocumentSync', 'willSave' }, - [ms.typeHierarchy_subtypes] = { 'typeHierarchyProvider' }, - [ms.typeHierarchy_supertypes] = { 'typeHierarchyProvider' }, - [ms.workspace_executeCommand] = { 'executeCommandProvider' }, - [ms.workspace_symbol] = { 'workspaceSymbolProvider' }, -} - -- TODO improve handling of scratch buffers with LSP attached. ---@private diff --git a/runtime/lua/vim/lsp/_meta/protocol.lua b/runtime/lua/vim/lsp/_meta/protocol.lua index d83c40a09f..442efe9f03 100644 --- a/runtime/lua/vim/lsp/_meta/protocol.lua +++ b/runtime/lua/vim/lsp/_meta/protocol.lua @@ -775,6 +775,42 @@ error('Cannot require a meta file') ---@proposed ---@class lsp.InlineCompletionRegistrationOptions: lsp.InlineCompletionOptions, lsp.TextDocumentRegistrationOptions, lsp.StaticRegistrationOptions +---Parameters for the `workspace/textDocumentContent` request. +--- +---@since 3.18.0 +---@proposed +---@class lsp.TextDocumentContentParams +--- +---The uri of the text document. +---@field uri lsp.DocumentUri + +---Result of the `workspace/textDocumentContent` request. +--- +---@since 3.18.0 +---@proposed +---@class lsp.TextDocumentContentResult +--- +---The text content of the text document. Please note, that the content of +---any subsequent open notifications for the text document might differ +---from the returned content due to whitespace and line ending +---normalizations done on the client +---@field text string + +---Text document content provider registration options. +--- +---@since 3.18.0 +---@proposed +---@class lsp.TextDocumentContentRegistrationOptions: lsp.TextDocumentContentOptions, lsp.StaticRegistrationOptions + +---Parameters for the `workspace/textDocumentContent/refresh` request. +--- +---@since 3.18.0 +---@proposed +---@class lsp.TextDocumentContentRefreshParams +--- +---The uri of the text document to refresh. +---@field uri lsp.DocumentUri + ---@class lsp.RegistrationParams --- ---@field registrations lsp.Registration[] @@ -1113,7 +1149,9 @@ error('Cannot require a meta file') ---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. +---also specifies a corresponding value, the rules for combining these are +---defined by `applyKinds` (if the client supports it), defaulting to +---ApplyKind.Replace. --- ---Servers are only allowed to return default values if the client ---signals support for this via the `completionList.itemDefaults` @@ -1122,6 +1160,25 @@ error('Cannot require a meta file') ---@since 3.17.0 ---@field itemDefaults? lsp.CompletionItemDefaults --- +---Specifies how fields from a completion item should be combined with those +---from `completionList.itemDefaults`. +--- +---If unspecified, all fields will be treated as ApplyKind.Replace. +--- +---If a field's value is ApplyKind.Replace, the value from a completion item +---(if provided and not `null`) will always be used instead of the value +---from `completionItem.itemDefaults`. +--- +---If a field's value is ApplyKind.Merge, the values will be merged using +---the rules defined against each field below. +--- +---Servers are only allowed to return `applyKind` if the client +---signals support for this via the `completionList.applyKindSupport` +---capability. +--- +---@since 3.18.0 +---@field applyKind? lsp.CompletionItemApplyKinds +--- ---The completion items. ---@field items lsp.CompletionItem[] @@ -1381,6 +1438,11 @@ error('Cannot require a meta file') --- ---@since 3.16.0 ---@field data? lsp.LSPAny +--- +---Tags for this code action. +--- +---@since 3.18.0 - proposed +---@field tags? lsp.CodeActionTag[] ---Registration options for a {@link CodeActionRequest}. ---@class lsp.CodeActionRegistrationOptions: lsp.TextDocumentRegistrationOptions, lsp.CodeActionOptions @@ -1842,18 +1904,12 @@ error('Cannot require a meta file') ---@class lsp.Position --- ---Line position in a document (zero-based). ---- ----If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document. ----If a line number is negative, it defaults to 0. ---@field line uinteger --- ---Character offset on a line in a document (zero-based). --- ---The meaning of this offset is determined by the negotiated ---`PositionEncodingKind`. ---- ----If the character value is greater than the line length it defaults back to the ----line length. ---@field character uinteger ---@class lsp.SelectionRangeOptions: lsp.WorkDoneProgressOptions @@ -2360,6 +2416,15 @@ error('Cannot require a meta file') ---@proposed ---@class lsp.InlineCompletionOptions: lsp.WorkDoneProgressOptions +---Text document content provider options. +--- +---@since 3.18.0 +---@proposed +---@class lsp.TextDocumentContentOptions +--- +---The schemes for which the server provides content. +---@field schemes string[] + ---General parameters to register for a notification or to register a provider. ---@class lsp.Registration --- @@ -2720,7 +2785,9 @@ error('Cannot require a meta file') ---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. +---also specifies a corresponding value, the rules for combining these are +---defined by `applyKinds` (if the client supports it), defaulting to +---ApplyKind.Replace. --- ---Servers are only allowed to return default values if the client ---signals support for this via the `completionList.itemDefaults` @@ -2754,6 +2821,66 @@ error('Cannot require a meta file') ---@since 3.17.0 ---@field data? lsp.LSPAny +---Specifies how fields from a completion item should be combined with those +---from `completionList.itemDefaults`. +--- +---If unspecified, all fields will be treated as ApplyKind.Replace. +--- +---If a field's value is ApplyKind.Replace, the value from a completion item (if +---provided and not `null`) will always be used instead of the value from +---`completionItem.itemDefaults`. +--- +---If a field's value is ApplyKind.Merge, the values will be merged using the rules +---defined against each field below. +--- +---Servers are only allowed to return `applyKind` if the client +---signals support for this via the `completionList.applyKindSupport` +---capability. +--- +---@since 3.18.0 +---@class lsp.CompletionItemApplyKinds +--- +---Specifies whether commitCharacters on a completion will replace or be +---merged with those in `completionList.itemDefaults.commitCharacters`. +--- +---If ApplyKind.Replace, the commit characters from the completion item will +---always be used unless not provided, in which case those from +---`completionList.itemDefaults.commitCharacters` will be used. An +---empty list can be used if a completion item does not have any commit +---characters and also should not use those from +---`completionList.itemDefaults.commitCharacters`. +--- +---If ApplyKind.Merge the commitCharacters for the completion will be the +---union of all values in both `completionList.itemDefaults.commitCharacters` +---and the completion's own `commitCharacters`. +--- +---@since 3.18.0 +---@field commitCharacters? lsp.ApplyKind +--- +---Specifies whether the `data` field on a completion will replace or +---be merged with data from `completionList.itemDefaults.data`. +--- +---If ApplyKind.Replace, the data from the completion item will be used if +---provided (and not `null`), otherwise +---`completionList.itemDefaults.data` will be used. An empty object can +---be used if a completion item does not have any data but also should +---not use the value from `completionList.itemDefaults.data`. +--- +---If ApplyKind.Merge, a shallow merge will be performed between +---`completionList.itemDefaults.data` and the completion's own data +---using the following rules: +--- +---- If a completion's `data` field is not provided (or `null`), the +--- entire `data` field from `completionList.itemDefaults.data` will be +--- used as-is. +---- If a completion's `data` field is provided, each field will +--- overwrite the field of the same name in +--- `completionList.itemDefaults.data` but no merging of nested fields +--- within that value will occur. +--- +---@since 3.18.0 +---@field data? lsp.ApplyKind + ---Completion options. ---@class lsp.CompletionOptions: lsp.WorkDoneProgressOptions --- @@ -3358,6 +3485,12 @@ error('Cannot require a meta file') --- ---@since 3.16.0 ---@field fileOperations? lsp.FileOperationOptions +--- +---The server supports the `workspace/textDocumentContent` request. +--- +---@since 3.18.0 +---@proposed +---@field textDocumentContent? lsp.TextDocumentContentOptions|lsp.TextDocumentContentRegistrationOptions ---@since 3.18.0 ---@class lsp.TextDocumentContentChangePartial @@ -3603,6 +3736,12 @@ error('Cannot require a meta file') ---@since 3.18.0 ---@proposed ---@field foldingRange? lsp.FoldingRangeWorkspaceClientCapabilities +--- +---Capabilities specific to the `workspace/textDocumentContent` request. +--- +---@since 3.18.0 +---@proposed +---@field textDocumentContent? lsp.TextDocumentContentClientCapabilities ---Text document specific client capabilities. ---@class lsp.TextDocumentClientCapabilities @@ -3610,6 +3749,11 @@ error('Cannot require a meta file') ---Defines which synchronization capabilities the client supports. ---@field synchronization? lsp.TextDocumentSyncClientCapabilities --- +---Defines which filters the client supports. +--- +---@since 3.18.0 +---@field filters? lsp.TextDocumentFilterClientCapabilities +--- ---Capabilities specific to the `textDocument/completion` request. ---@field completion? lsp.CompletionClientCapabilities --- @@ -3872,7 +4016,9 @@ error('Cannot require a meta file') --- ---A glob pattern, like **/*.{ts,js}. See TextDocumentFilter for examples. --- ----@since 3.18.0 - support for relative patterns. +---@since 3.18.0 - support for relative patterns. Whether clients support +---relative patterns depends on the client capability +---`textDocuments.filters.relativePatternSupport`. ---@field pattern? lsp.GlobPattern ---A document filter where `scheme` is required field. @@ -3888,7 +4034,9 @@ error('Cannot require a meta file') --- ---A glob pattern, like **/*.{ts,js}. See TextDocumentFilter for examples. --- ----@since 3.18.0 - support for relative patterns. +---@since 3.18.0 - support for relative patterns. Whether clients support +---relative patterns depends on the client capability +---`textDocuments.filters.relativePatternSupport`. ---@field pattern? lsp.GlobPattern ---A document filter where `pattern` is required field. @@ -3904,7 +4052,9 @@ error('Cannot require a meta file') --- ---A glob pattern, like **/*.{ts,js}. See TextDocumentFilter for examples. --- ----@since 3.18.0 - support for relative patterns. +---@since 3.18.0 - support for relative patterns. Whether clients support +---relative patterns depends on the client capability +---`textDocuments.filters.relativePatternSupport`. ---@field pattern lsp.GlobPattern ---A notebook document filter where `notebookType` is required field. @@ -4167,6 +4317,15 @@ error('Cannot require a meta file') ---@proposed ---@field refreshSupport? boolean +---Client capabilities for a text document content provider. +--- +---@since 3.18.0 +---@proposed +---@class lsp.TextDocumentContentClientCapabilities +--- +---Text document content provider supports dynamic registration. +---@field dynamicRegistration? boolean + ---@class lsp.TextDocumentSyncClientCapabilities --- ---Whether text document synchronization supports dynamic registration. @@ -4183,6 +4342,13 @@ error('Cannot require a meta file') ---The client supports did save notifications. ---@field didSave? boolean +---@class lsp.TextDocumentFilterClientCapabilities +--- +---The client supports Relative Patterns. +--- +---@since 3.18.0 +---@field relativePatternSupport? boolean + ---Completion client capabilities ---@class lsp.CompletionClientCapabilities --- @@ -4376,6 +4542,12 @@ error('Cannot require a meta file') ---@since 3.18.0 ---@proposed ---@field documentationSupport? boolean +--- +---Client supports the tag property on a code action. Clients +---supporting tags have to handle unknown tags gracefully. +--- +---@since 3.18.0 - proposed +---@field tagSupport? lsp.CodeActionTagOptions ---The client capabilities of a {@link CodeLensRequest}. ---@class lsp.CodeLensClientCapabilities @@ -4822,6 +4994,19 @@ error('Cannot require a meta file') --- ---@since 3.17.0 ---@field itemDefaults? string[] +--- +---Specifies whether the client supports `CompletionList.applyKind` to +---indicate how supported values from `completionList.itemDefaults` +---and `completion` will be combined. +--- +---If a client supports `applyKind` it must support it for all fields +---that it supports that are listed in `CompletionList.applyKind`. This +---means when clients add support for new/future fields in completion +---items the MUST also support merge for them if those fields are +---defined in `CompletionList.applyKind`. +--- +---@since 3.18.0 +---@field applyKindSupport? boolean ---@since 3.18.0 ---@class lsp.ClientSignatureInformationOptions @@ -4860,6 +5045,12 @@ error('Cannot require a meta file') ---The properties that a client can resolve lazily. ---@field properties string[] +---@since 3.18.0 - proposed +---@class lsp.CodeActionTagOptions +--- +---The tags supported by the client. +---@field valueSet lsp.CodeActionTag[] + ---@since 3.18.0 ---@class lsp.ClientCodeLensResolveOptions --- @@ -5208,6 +5399,12 @@ error('Cannot require a meta file') ---| "source.fixAll" # SourceFixAll ---| "notebook" # Notebook +---Code action tags are extra annotations that tweak the behavior of a code action. +--- +---@since 3.18.0 - proposed +---@alias lsp.CodeActionTag +---| 1 # LLMGenerated + ---@alias lsp.TraceValue ---| "off" # Off ---| "messages" # Messages @@ -5224,7 +5421,6 @@ error('Cannot require a meta file') ---Predefined Language kinds ---@since 3.18.0 ----@proposed ---@alias lsp.LanguageKind ---| "abap" # ABAP ---| "bat" # WindowsBat @@ -5335,6 +5531,14 @@ error('Cannot require a meta file') ---| 2 # TriggerCharacter ---| 3 # TriggerForIncompleteCompletions +---Defines how values from a set of defaults and an individual item will be +---merged. +--- +---@since 3.18.0 +---@alias lsp.ApplyKind +---| 1 # Replace +---| 2 # Merge + ---How a signature help was triggered. --- ---@since 3.15.0 @@ -5478,7 +5682,7 @@ error('Cannot require a meta file') ---A document filter describes a top level text document or ---a notebook cell document. --- ----@since 3.17.0 - proposed support for NotebookCellTextDocumentFilter. +---@since 3.17.0 - support for NotebookCellTextDocumentFilter. ---@alias lsp.DocumentFilter lsp.TextDocumentFilter|lsp.NotebookCellTextDocumentFilter ---LSP object definition. diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua index 253ccc48f4..79a91c3d5f 100644 --- a/runtime/lua/vim/lsp/client.lua +++ b/runtime/lua/vim/lsp/client.lua @@ -1056,7 +1056,7 @@ function Client:supports_method(method, bufnr) --- @diagnostic disable-next-line:no-unknown bufnr = bufnr.bufnr end - local required_capability = lsp._request_name_to_capability[method] + local required_capability = lsp.protocol._request_name_to_capability[method] -- if we don't know about the method, assume that the client supports it. if not required_capability then return true diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 33d029420b..7975006f9d 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -693,6 +693,7 @@ end --- | 'workspace/didRenameFiles', --- | 'workspace/executeCommand', --- | 'workspace/symbol', +--- | 'workspace/textDocumentContent', --- | 'workspace/willCreateFiles', --- | 'workspace/willDeleteFiles', --- | 'workspace/willRenameFiles', @@ -716,6 +717,7 @@ end --- | 'workspace/inlayHint/refresh', --- | 'workspace/inlineValue/refresh', --- | 'workspace/semanticTokens/refresh', +--- | 'workspace/textDocumentContent/refresh', --- | 'workspace/workspaceFolders', --- @alias vim.lsp.protocol.Method @@ -723,7 +725,6 @@ end --- | vim.lsp.protocol.Method.ServerToClient -- Generated by gen_lsp.lua, keep at end of file. ---- --- @enum vim.lsp.protocol.Methods --- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel --- LSP method names. @@ -1049,6 +1050,16 @@ protocol.Methods = { --- need to advertise support for WorkspaceSymbols via the client capability --- `workspace.symbol.resolveSupport`. workspace_symbol = 'workspace/symbol', + --- The `workspace/textDocumentContent` request is sent from the client to the + --- server to request the content of a text document. + --- @since 3.18.0 + --- @proposed + workspace_textDocumentContent = 'workspace/textDocumentContent', + --- The `workspace/textDocumentContent` request is sent from the server to the client to refresh + --- the content of a specific text document. + --- @since 3.18.0 + --- @proposed + workspace_textDocumentContent_refresh = 'workspace/textDocumentContent/refresh', --- The will create files request is sent from the client to the server before files are actually --- created as long as the creation is triggered from within the client. --- The request can return a `WorkspaceEdit` which will be applied to workspace before the @@ -1068,4 +1079,68 @@ protocol.Methods = { workspace_workspaceFolders = 'workspace/workspaceFolders', } +-- stylua: ignore start +-- Generated by gen_lsp.lua, keep at end of file. +--- Maps method names to the required server capability +protocol._request_name_to_capability = { + ['codeAction/resolve'] = { 'codeActionProvider', 'resolveProvider' }, + ['codeLens/resolve'] = { 'codeLensProvider', 'resolveProvider' }, + ['completionItem/resolve'] = { 'completionProvider', 'resolveProvider' }, + ['documentLink/resolve'] = { 'documentLinkProvider', 'resolveProvider' }, + ['inlayHint/resolve'] = { 'inlayHintProvider', 'resolveProvider' }, + ['textDocument/codeAction'] = { 'codeActionProvider' }, + ['textDocument/codeLens'] = { 'codeLensProvider' }, + ['textDocument/completion'] = { 'completionProvider' }, + ['textDocument/declaration'] = { 'declarationProvider' }, + ['textDocument/definition'] = { 'definitionProvider' }, + ['textDocument/diagnostic'] = { 'diagnosticProvider' }, + ['textDocument/didChange'] = { 'textDocumentSync' }, + ['textDocument/didClose'] = { 'textDocumentSync', 'openClose' }, + ['textDocument/didOpen'] = { 'textDocumentSync', 'openClose' }, + ['textDocument/didSave'] = { 'textDocumentSync', 'save' }, + ['textDocument/documentColor'] = { 'colorProvider' }, + ['textDocument/documentHighlight'] = { 'documentHighlightProvider' }, + ['textDocument/documentLink'] = { 'documentLinkProvider' }, + ['textDocument/documentSymbol'] = { 'documentSymbolProvider' }, + ['textDocument/foldingRange'] = { 'foldingRangeProvider' }, + ['textDocument/formatting'] = { 'documentFormattingProvider' }, + ['textDocument/hover'] = { 'hoverProvider' }, + ['textDocument/implementation'] = { 'implementationProvider' }, + ['textDocument/inlayHint'] = { 'inlayHintProvider' }, + ['textDocument/inlineCompletion'] = { 'inlineCompletionProvider' }, + ['textDocument/inlineValue'] = { 'inlineValueProvider' }, + ['textDocument/linkedEditingRange'] = { 'linkedEditingRangeProvider' }, + ['textDocument/moniker'] = { 'monikerProvider' }, + ['textDocument/onTypeFormatting'] = { 'documentOnTypeFormattingProvider' }, + ['textDocument/prepareCallHierarchy'] = { 'callHierarchyProvider' }, + ['textDocument/prepareRename'] = { 'renameProvider', 'prepareProvider' }, + ['textDocument/prepareTypeHierarchy'] = { 'typeHierarchyProvider' }, + ['textDocument/rangeFormatting'] = { 'documentRangeFormattingProvider' }, + ['textDocument/rangesFormatting'] = { 'documentRangeFormattingProvider', 'rangesSupport' }, + ['textDocument/references'] = { 'referencesProvider' }, + ['textDocument/rename'] = { 'renameProvider' }, + ['textDocument/selectionRange'] = { 'selectionRangeProvider' }, + ['textDocument/semanticTokens/full'] = { 'semanticTokensProvider' }, + ['textDocument/semanticTokens/full/delta'] = { 'semanticTokensProvider', 'full', 'delta' }, + ['textDocument/semanticTokens/range'] = { 'semanticTokensProvider', 'range' }, + ['textDocument/signatureHelp'] = { 'signatureHelpProvider' }, + ['textDocument/typeDefinition'] = { 'typeDefinitionProvider' }, + ['textDocument/willSave'] = { 'textDocumentSync', 'willSave' }, + ['textDocument/willSaveWaitUntil'] = { 'textDocumentSync', 'willSaveWaitUntil' }, + ['workspaceSymbol/resolve'] = { 'workspaceSymbolProvider', 'resolveProvider' }, + ['workspace/diagnostic'] = { 'diagnosticProvider', 'workspaceDiagnostics' }, + ['workspace/didChangeWorkspaceFolders'] = { 'workspace', 'workspaceFolders', 'changeNotifications' }, + ['workspace/didCreateFiles'] = { 'workspace', 'fileOperations', 'didCreate' }, + ['workspace/didDeleteFiles'] = { 'workspace', 'fileOperations', 'didDelete' }, + ['workspace/didRenameFiles'] = { 'workspace', 'fileOperations', 'didRename' }, + ['workspace/executeCommand'] = { 'executeCommandProvider' }, + ['workspace/symbol'] = { 'workspaceSymbolProvider' }, + ['workspace/textDocumentContent'] = { 'workspace', 'textDocumentContent' }, + ['workspace/willCreateFiles'] = { 'workspace', 'fileOperations', 'willCreate' }, + ['workspace/willDeleteFiles'] = { 'workspace', 'fileOperations', 'willDelete' }, + ['workspace/willRenameFiles'] = { 'workspace', 'fileOperations', 'willRename' }, + ['workspace/workspaceFolders'] = { 'workspace', 'workspaceFolders' }, +} +-- stylua: ignore end + return protocol diff --git a/scripts/gen_lsp.lua b/scripts/gen_lsp.lua index 8afbae239a..3e419c7d59 100644 --- a/scripts/gen_lsp.lua +++ b/scripts/gen_lsp.lua @@ -6,7 +6,7 @@ Generates lua-ls annotations for lsp. USAGE: nvim -l scripts/gen_lsp.lua gen # by default, this will overwrite runtime/lua/vim/lsp/_meta/protocol.lua nvim -l scripts/gen_lsp.lua gen --version 3.18 --out runtime/lua/vim/lsp/_meta/protocol.lua -nvim -l scripts/gen_lsp.lua gen --version 3.18 --methods +nvim -l scripts/gen_lsp.lua gen --version 3.18 --methods --capabilities ]] local DEFAULT_LSP_VERSION = '3.18' @@ -57,13 +57,21 @@ local function to_luaname(s) end ---@param protocol vim._gen_lsp.Protocol -local function gen_methods(protocol) +---@param gen_methods boolean +---@param gen_capabilities boolean +local function write_to_protocol(protocol, gen_methods, gen_capabilities) + if not gen_methods and not gen_capabilities then + return + end + local indent = (' '):rep(2) --- @class vim._gen_lsp.Request --- @field deprecated? string --- @field documentation? string --- @field messageDirection string + --- @field clientCapability? string + --- @field serverCapability? string --- @field method string --- @field params? any --- @field proposed? boolean @@ -76,6 +84,8 @@ local function gen_methods(protocol) --- @field documentation? string --- @field errorData? any --- @field messageDirection string + --- @field clientCapability? string + --- @field serverCapability? string --- @field method string --- @field params? any[] --- @field partialResult? any @@ -91,52 +101,85 @@ local function gen_methods(protocol) return to_luaname(a.method) < to_luaname(b.method) end) - local output = { - '-- Generated by gen_lsp.lua, keep at end of file.', - '--- @alias vim.lsp.protocol.Method.ClientToServer', - } - for _, item in ipairs(all) do - if item.method and item.messageDirection == 'clientToServer' then - output[#output + 1] = ("--- | '%s',"):format(item.method) + local output = { '-- Generated by gen_lsp.lua, keep at end of file.' } + + if gen_methods then + output[#output + 1] = '--- @alias vim.lsp.protocol.Method.ClientToServer' + + for _, item in ipairs(all) do + if item.method and item.messageDirection == 'clientToServer' then + output[#output + 1] = ("--- | '%s',"):format(item.method) + end end - end - vim.list_extend(output, { - '', - '--- @alias vim.lsp.protocol.Method.ServerToClient', - }) - for _, item in ipairs(all) do - if item.method and item.messageDirection == 'serverToClient' then - output[#output + 1] = ("--- | '%s',"):format(item.method) + vim.list_extend(output, { + '', + '--- @alias vim.lsp.protocol.Method.ServerToClient', + }) + for _, item in ipairs(all) do + if item.method and item.messageDirection == 'serverToClient' then + output[#output + 1] = ("--- | '%s',"):format(item.method) + end end - end - vim.list_extend(output, { - '', - '--- @alias vim.lsp.protocol.Method', - '--- | vim.lsp.protocol.Method.ClientToServer', - '--- | vim.lsp.protocol.Method.ServerToClient', - '', - '-- Generated by gen_lsp.lua, keep at end of file.', - '---', - '--- @enum vim.lsp.protocol.Methods', - '--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel', - '--- LSP method names.', - 'protocol.Methods = {', - }) - - for _, item in ipairs(all) do - if item.method then - if item.documentation then - local document = vim.split(item.documentation, '\n?\n', { trimempty = true }) - for _, docstring in ipairs(document) do - output[#output + 1] = indent .. '--- ' .. docstring + vim.list_extend(output, { + '', + '--- @alias vim.lsp.protocol.Method', + '--- | vim.lsp.protocol.Method.ClientToServer', + '--- | vim.lsp.protocol.Method.ServerToClient', + '', + '-- Generated by gen_lsp.lua, keep at end of file.', + '--- @enum vim.lsp.protocol.Methods', + '--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel', + '--- LSP method names.', + 'protocol.Methods = {', + }) + + for _, item in ipairs(all) do + if item.method then + if item.documentation then + local document = vim.split(item.documentation, '\n?\n', { trimempty = true }) + for _, docstring in ipairs(document) do + output[#output + 1] = indent .. '--- ' .. docstring + end end + output[#output + 1] = ("%s%s = '%s',"):format(indent, to_luaname(item.method), item.method) + end + end + output[#output + 1] = '}' + end + + if gen_capabilities then + vim.list_extend(output, { + '', + '-- stylua: ignore start', + '-- Generated by gen_lsp.lua, keep at end of file.', + '--- Maps method names to the required server capability', + 'protocol._request_name_to_capability = {', + }) + + for _, item in ipairs(all) do + if item.serverCapability then + output[#output + 1] = ("%s['%s'] = { %s },"):format( + indent, + item.method, + table.concat( + vim + .iter(vim.split(item.serverCapability, '.', { plain = true })) + :map(function(segment) + return "'" .. segment .. "'" + end) + :totable(), + ', ' + ) + ) end - output[#output + 1] = ("%s%s = '%s',"):format(indent, to_luaname(item.method), item.method) end + + output[#output + 1] = '}' + output[#output + 1] = '-- stylua: ignore end' end - output[#output + 1] = '}' + output[#output + 1] = '' output[#output + 1] = 'return protocol' @@ -157,15 +200,14 @@ end ---@field output_file string ---@field version string ---@field methods boolean +---@field capabilities boolean ---@param opt vim._gen_lsp.opt function M.gen(opt) --- @type vim._gen_lsp.Protocol local protocol = read_json(opt) - if opt.methods then - gen_methods(protocol) - end + write_to_protocol(protocol, opt.methods, opt.capabilities) local output = { '--' .. '[[', @@ -433,6 +475,7 @@ local opt = { output_file = 'runtime/lua/vim/lsp/_meta/protocol.lua', version = DEFAULT_LSP_VERSION, methods = false, + capabilities = false, } local command = nil @@ -446,6 +489,8 @@ while i <= #_G.arg do i = i + 1 elseif _G.arg[i] == '--methods' then opt.methods = true + elseif _G.arg[i] == '--capabilities' then + opt.capabilities = true elseif vim.startswith(_G.arg[i], '-') then error('Unrecognized args: ' .. _G.arg[i]) else |