commit f41496ce74fb30c18bb9a03027a172800b269643
parent da09f9b551badfb3fd363589009168560ae607f6
Author: Justin M. Keyes <justinkz@gmail.com>
Date: Tue, 1 Aug 2023 15:52:53 +0200
feat(gen_lsp.lua): sort by name, handle failure #24504
Diffstat:
6 files changed, 516 insertions(+), 547 deletions(-)
diff --git a/MAINTAIN.md b/MAINTAIN.md
@@ -120,7 +120,7 @@ These dependencies are "vendored" (inlined), we must update the sources manually
* `src/nvim/tui/terminfo_defs.h`: terminfo definitions
* Run `scripts/update_terminfo.sh` to update these definitions.
* `runtime/lua/vim/lsp/types/protocol.lua`: LSP specification
- * Run `scripts/lsp_types.lua` to update.
+ * Run `scripts/gen_lsp.lua` to update.
* `src/bit.c`: only for PUC lua: port of `require'bit'` from luajit https://bitop.luajit.org/
* [treesitter parsers](https://github.com/neovim/neovim/blob/fcc24e43e0b5f9d801a01ff2b8f78ce8c16dd551/cmake.deps/CMakeLists.txt#L197-L210)
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
@@ -70,21 +70,6 @@ The following new APIs and features were added.
• 'diffopt' "linematch" scoring algorithm now favours larger and less groups
https://github.com/neovim/neovim/pull/23611
-• Added |vim.lsp.status()| to consume the last progress messages as a string.
-
-• Neovim's LSP client now always saves and restores named buffer marks when
- applying text edits.
-
-• Nvim now supports the `positionEncoding` server capability. If a server
- responds with the `positionEncoding` capability in its initialization
- response, Nvim automatically sets the client's `offset_encoding` field.
-
-• Dynamic registration of LSP capabilities. An implication of this change is
- that checking a client's `server_capabilities` is no longer a sufficient
- indicator to see if a server supports a feature. Instead use
- `client.supports_method(<method>)`. It considers both the dynamic
- capabilities and static `server_capabilities`.
-
• |vim.iter()| provides a generic iterator interface for tables and Lua
iterators |luaref-in|.
@@ -118,10 +103,22 @@ The following new APIs and features were added.
terminal emulator that supports |tui-csiu|.
• LSP
+ • LSP method names are available in |vim.lsp.protocol.Methods|.
• Implemented LSP inlay hints: |vim.lsp.inlay_hint()|
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
• Implemented pull diagnostic textDocument/diagnostic: |vim.lsp.diagnostic.on_diagnostic()|
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_diagnostic
+ • Added |vim.lsp.status()| to consume the last progress messages as a string.
+ • LSP client now always saves and restores named buffer marks when applying
+ text edits.
+ • LSP client now supports the `positionEncoding` server capability. If a server
+ responds with the `positionEncoding` capability in its initialization
+ response, Nvim automatically sets the client's `offset_encoding` field.
+ • Dynamic registration of LSP capabilities. An implication of this change is
+ that checking a client's `server_capabilities` is no longer a sufficient
+ indicator to see if a server supports a feature. Instead use
+ `client.supports_method(<method>)`. It considers both the dynamic
+ capabilities and static `server_capabilities`.
• Bundled treesitter parser and queries (highlight, folds) for Markdown,
Python, and Bash.
@@ -176,8 +173,6 @@ The following changes to existing APIs or features add new behavior.
supports it, unless |'keywordprg'| was customized before calling
|vim.lsp.start()|.
-• |vim.lsp.protocol.Methods| all the lsp methods constants.
-
==============================================================================
REMOVED FEATURES *news-removed*
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
@@ -923,110 +923,62 @@ function protocol.resolve_capabilities(server_capabilities)
return server_capabilities
end
--- Generated by lsp_types.lua, keep at end of file.
+-- Generated by gen_lsp.lua, keep at end of file.
--- LSP method names.
---
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#metaModel
protocol.Methods = {
+ --- A request to resolve the incoming calls for a given `CallHierarchyItem`.
+ --- @since 3.16.0
+ callHierarchy_incomingCalls = 'callHierarchy/incomingCalls',
+ --- A request to resolve the outgoing calls for a given `CallHierarchyItem`.
+ --- @since 3.16.0
+ callHierarchy_outgoingCalls = 'callHierarchy/outgoingCalls',
+ --- The `client/registerCapability` request is sent from the server to the client to register a new capability
+ --- handler on the client side.
+ client_registerCapability = 'client/registerCapability',
+ --- The `client/unregisterCapability` request is sent from the server to the client to unregister a previously registered capability
+ --- handler on the client side.
+ client_unregisterCapability = 'client/unregisterCapability',
+ --- Request to resolve additional information for a given code action.The request's
+ --- parameter is of type {@link CodeAction} the response
+ --- is of type {@link CodeAction} or a Thenable that resolves to such.
+ codeAction_resolve = 'codeAction/resolve',
+ --- A request to resolve a command for a given code lens.
+ codeLens_resolve = 'codeLens/resolve',
+ --- Request to resolve additional information for a given completion item.The request's
+ --- parameter is of type {@link CompletionItem} the response
+ --- is of type {@link CompletionItem} or a Thenable that resolves to such.
+ completionItem_resolve = 'completionItem/resolve',
+ --- Request to resolve additional information for a given document link. The request's
+ --- parameter is of type {@link DocumentLink} the response
+ --- is of type {@link DocumentLink} or a Thenable that resolves to such.
+ documentLink_resolve = 'documentLink/resolve',
--- The initialize request is sent from the client to the server.
--- It is sent once as the request after starting up the server.
--- The requests parameter is of type {@link InitializeParams}
--- the response if of type {@link InitializeResult} of a Thenable that
--- resolves to such.
initialize = 'initialize',
+ --- A request to resolve additional properties for an inlay hint.
+ --- The request's parameter is of type {@link InlayHint}, the response is
+ --- of type {@link InlayHint} or a Thenable that resolves to such.
+ --- @since 3.17.0
+ inlayHint_resolve = 'inlayHint/resolve',
--- A shutdown request is sent from the client to the server.
--- It is sent once when the client decides to shutdown the
--- server. The only notification that is sent after a shutdown request
--- is the exit event.
shutdown = 'shutdown',
- --- The `client/registerCapability` request is sent from the server to the client to register a new capability
- --- handler on the client side.
- client_registerCapability = 'client/registerCapability',
- --- The `client/unregisterCapability` request is sent from the server to the client to unregister a previously registered capability
- --- handler on the client side.
- client_unregisterCapability = 'client/unregisterCapability',
- --- A request to resolve the implementation locations of a symbol at a given text
- --- document position. The request's parameter is of type [TextDocumentPositionParams]
- --- (#TextDocumentPositionParams) the response is of type {@link Definition} or a
- --- Thenable that resolves to such.
- textDocument_implementation = 'textDocument/implementation',
- --- A request to resolve the type definition locations of a symbol at a given text
- --- document position. The request's parameter is of type [TextDocumentPositionParams]
- --- (#TextDocumentPositionParams) the response is of type {@link Definition} or a
- --- Thenable that resolves to such.
- textDocument_typeDefinition = 'textDocument/typeDefinition',
- --- A request to list all color symbols found in a given text document. The request's
- --- parameter is of type {@link DocumentColorParams} the
- --- response is of type {@link ColorInformation ColorInformation[]} or a Thenable
- --- that resolves to such.
- textDocument_documentColor = 'textDocument/documentColor',
+ --- A request to provide commands for the given text document and range.
+ textDocument_codeAction = 'textDocument/codeAction',
+ --- A request to provide code lens for the given text document.
+ textDocument_codeLens = 'textDocument/codeLens',
--- A request to list all presentation for a color. The request's
--- parameter is of type {@link ColorPresentationParams} the
--- response is of type {@link ColorInformation ColorInformation[]} or a Thenable
--- that resolves to such.
textDocument_colorPresentation = 'textDocument/colorPresentation',
- --- A request to provide folding ranges in a document. The request's
- --- parameter is of type {@link FoldingRangeParams}, the
- --- response is of type {@link FoldingRangeList} or a Thenable
- --- that resolves to such.
- textDocument_foldingRange = 'textDocument/foldingRange',
- --- A request to resolve the type definition locations of a symbol at a given text
- --- document position. The request's parameter is of type [TextDocumentPositionParams]
- --- (#TextDocumentPositionParams) the response is of type {@link Declaration}
- --- or a typed array of {@link DeclarationLink} or a Thenable that resolves
- --- to such.
- textDocument_declaration = 'textDocument/declaration',
- --- A request to provide selection ranges in a document. The request's
- --- parameter is of type {@link SelectionRangeParams}, the
- --- response is of type {@link SelectionRange SelectionRange[]} or a Thenable
- --- that resolves to such.
- textDocument_selectionRange = 'textDocument/selectionRange',
- --- A request to result a `CallHierarchyItem` in a document at a given position.
- --- Can be used as an input to an incoming or outgoing call hierarchy.
- --- @since 3.16.0
- textDocument_prepareCallHierarchy = 'textDocument/prepareCallHierarchy',
- --- @since 3.16.0
- textDocument_semanticTokens_full = 'textDocument/semanticTokens/full',
- --- @since 3.16.0
- textDocument_semanticTokens_full_delta = 'textDocument/semanticTokens/full/delta',
- --- @since 3.16.0
- textDocument_semanticTokens_range = 'textDocument/semanticTokens/range',
- --- A request to provide ranges that can be edited together.
- --- @since 3.16.0
- textDocument_linkedEditingRange = 'textDocument/linkedEditingRange',
- --- A request to get the moniker of a symbol at a given text document position.
- --- The request parameter is of type {@link TextDocumentPositionParams}.
- --- The response is of type {@link Moniker Moniker[]} or `null`.
- textDocument_moniker = 'textDocument/moniker',
- --- A request to result a `TypeHierarchyItem` in a document at a given position.
- --- Can be used as an input to a subtypes or supertypes type hierarchy.
- --- @since 3.17.0
- textDocument_prepareTypeHierarchy = 'textDocument/prepareTypeHierarchy',
- --- A request to provide inline values in a document. The request's parameter is of
- --- type {@link InlineValueParams}, the response is of type
- --- {@link InlineValue InlineValue[]} or a Thenable that resolves to such.
- --- @since 3.17.0
- textDocument_inlineValue = 'textDocument/inlineValue',
- --- A request to provide inlay hints in a document. The request's parameter is of
- --- type {@link InlayHintsParams}, the response is of type
- --- {@link InlayHint InlayHint[]} or a Thenable that resolves to such.
- --- @since 3.17.0
- textDocument_inlayHint = 'textDocument/inlayHint',
- --- The document diagnostic request definition.
- --- @since 3.17.0
- textDocument_diagnostic = 'textDocument/diagnostic',
- --- A request to provide inline completions in a document. The request's parameter is of
- --- type {@link InlineCompletionParams}, the response is of type
- --- {@link InlineCompletion InlineCompletion[]} or a Thenable that resolves to such.
- --- @since 3.18.0
- textDocument_inlineCompletion = 'textDocument/inlineCompletion',
- --- A document will save request is sent from the client to the server before
- --- the document is actually saved. The request can return an array of TextEdits
- --- which will be applied to the text document before it is saved. Please note that
- --- clients might drop results if computing the text edits took too long or if a
- --- server constantly fails on this request. This is done to keep the save fast and
- --- reliable.
- textDocument_willSaveWaitUntil = 'textDocument/willSaveWaitUntil',
--- Request to request completion at a given text document position. The request's
--- parameter is of type {@link TextDocumentPosition} the response
--- is of type {@link CompletionItem CompletionItem[]} or {@link CompletionList}
@@ -1036,55 +988,153 @@ protocol.Methods = {
--- request. However, properties that are needed for the initial sorting and filtering, like `sortText`,
--- `filterText`, `insertText`, and `textEdit`, must not be changed during resolve.
textDocument_completion = 'textDocument/completion',
- --- Request to request hover information at a given text document position. The request's
- --- parameter is of type {@link TextDocumentPosition} the response is of
- --- type {@link Hover} or a Thenable that resolves to such.
- textDocument_hover = 'textDocument/hover',
- textDocument_signatureHelp = 'textDocument/signatureHelp',
+ --- A request to resolve the type definition locations of a symbol at a given text
+ --- document position. The request's parameter is of type [TextDocumentPositionParams]
+ --- (#TextDocumentPositionParams) the response is of type {@link Declaration}
+ --- or a typed array of {@link DeclarationLink} or a Thenable that resolves
+ --- to such.
+ textDocument_declaration = 'textDocument/declaration',
--- A request to resolve the definition location of a symbol at a given text
--- document position. The request's parameter is of type [TextDocumentPosition]
--- (#TextDocumentPosition) the response is of either type {@link Definition}
--- or a typed array of {@link DefinitionLink} or a Thenable that resolves
--- to such.
textDocument_definition = 'textDocument/definition',
- --- A request to resolve project-wide references for the symbol denoted
- --- by the given text document position. The request's parameter is of
- --- type {@link ReferenceParams} the response is of type
- --- {@link Location Location[]} or a Thenable that resolves to such.
- textDocument_references = 'textDocument/references',
+ --- The document diagnostic request definition.
+ --- @since 3.17.0
+ textDocument_diagnostic = 'textDocument/diagnostic',
+ --- A request to list all color symbols found in a given text document. The request's
+ --- parameter is of type {@link DocumentColorParams} the
+ --- response is of type {@link ColorInformation ColorInformation[]} or a Thenable
+ --- that resolves to such.
+ textDocument_documentColor = 'textDocument/documentColor',
--- Request to resolve a {@link DocumentHighlight} for a given
--- text document position. The request's parameter is of type [TextDocumentPosition]
--- (#TextDocumentPosition) the request response is of type [DocumentHighlight[]]
--- (#DocumentHighlight) or a Thenable that resolves to such.
textDocument_documentHighlight = 'textDocument/documentHighlight',
+ --- A request to provide document links
+ textDocument_documentLink = 'textDocument/documentLink',
--- A request to list all symbols found in a given text document. The request's
--- parameter is of type {@link TextDocumentIdentifier} the
--- response is of type {@link SymbolInformation SymbolInformation[]} or a Thenable
--- that resolves to such.
textDocument_documentSymbol = 'textDocument/documentSymbol',
- --- A request to provide commands for the given text document and range.
- textDocument_codeAction = 'textDocument/codeAction',
- --- A request to provide code lens for the given text document.
- textDocument_codeLens = 'textDocument/codeLens',
- --- A request to provide document links
- textDocument_documentLink = 'textDocument/documentLink',
- --- A request to to format a whole document.
+ --- A request to provide folding ranges in a document. The request's
+ --- parameter is of type {@link FoldingRangeParams}, the
+ --- response is of type {@link FoldingRangeList} or a Thenable
+ --- that resolves to such.
+ textDocument_foldingRange = 'textDocument/foldingRange',
+ --- A request to format a whole document.
textDocument_formatting = 'textDocument/formatting',
+ --- Request to request hover information at a given text document position. The request's
+ --- parameter is of type {@link TextDocumentPosition} the response is of
+ --- type {@link Hover} or a Thenable that resolves to such.
+ textDocument_hover = 'textDocument/hover',
+ --- A request to resolve the implementation locations of a symbol at a given text
+ --- document position. The request's parameter is of type [TextDocumentPositionParams]
+ --- (#TextDocumentPositionParams) the response is of type {@link Definition} or a
+ --- Thenable that resolves to such.
+ textDocument_implementation = 'textDocument/implementation',
+ --- A request to provide inlay hints in a document. The request's parameter is of
+ --- type {@link InlayHintsParams}, the response is of type
+ --- {@link InlayHint InlayHint[]} or a Thenable that resolves to such.
+ --- @since 3.17.0
+ textDocument_inlayHint = 'textDocument/inlayHint',
+ --- A request to provide inline completions in a document. The request's parameter is of
+ --- type {@link InlineCompletionParams}, the response is of type
+ --- {@link InlineCompletion InlineCompletion[]} or a Thenable that resolves to such.
+ --- @since 3.18.0
+ textDocument_inlineCompletion = 'textDocument/inlineCompletion',
+ --- A request to provide inline values in a document. The request's parameter is of
+ --- type {@link InlineValueParams}, the response is of type
+ --- {@link InlineValue InlineValue[]} or a Thenable that resolves to such.
+ --- @since 3.17.0
+ textDocument_inlineValue = 'textDocument/inlineValue',
+ --- A request to provide ranges that can be edited together.
+ --- @since 3.16.0
+ textDocument_linkedEditingRange = 'textDocument/linkedEditingRange',
+ --- A request to get the moniker of a symbol at a given text document position.
+ --- The request parameter is of type {@link TextDocumentPositionParams}.
+ --- The response is of type {@link Moniker Moniker[]} or `null`.
+ textDocument_moniker = 'textDocument/moniker',
+ --- A request to format a document on type.
+ textDocument_onTypeFormatting = 'textDocument/onTypeFormatting',
+ --- A request to result a `CallHierarchyItem` in a document at a given position.
+ --- Can be used as an input to an incoming or outgoing call hierarchy.
+ --- @since 3.16.0
+ textDocument_prepareCallHierarchy = 'textDocument/prepareCallHierarchy',
+ --- A request to test and perform the setup necessary for a rename.
+ --- @since 3.16 - support for default behavior
+ textDocument_prepareRename = 'textDocument/prepareRename',
+ --- A request to result a `TypeHierarchyItem` in a document at a given position.
+ --- Can be used as an input to a subtypes or supertypes type hierarchy.
+ --- @since 3.17.0
+ textDocument_prepareTypeHierarchy = 'textDocument/prepareTypeHierarchy',
--- A request to format a range in a document.
textDocument_rangeFormatting = 'textDocument/rangeFormatting',
--- A request to format ranges in a document.
--- @since 3.18.0
--- @proposed
textDocument_rangesFormatting = 'textDocument/rangesFormatting',
- --- A request to format a document on type.
- textDocument_onTypeFormatting = 'textDocument/onTypeFormatting',
+ --- A request to resolve project-wide references for the symbol denoted
+ --- by the given text document position. The request's parameter is of
+ --- type {@link ReferenceParams} the response is of type
+ --- {@link Location Location[]} or a Thenable that resolves to such.
+ textDocument_references = 'textDocument/references',
--- A request to rename a symbol.
textDocument_rename = 'textDocument/rename',
- --- A request to test and perform the setup necessary for a rename.
- --- @since 3.16 - support for default behavior
- textDocument_prepareRename = 'textDocument/prepareRename',
- --- The `workspace/workspaceFolders` is sent from the server to the client to fetch the open workspace folders.
- workspace_workspaceFolders = 'workspace/workspaceFolders',
+ --- A request to provide selection ranges in a document. The request's
+ --- parameter is of type {@link SelectionRangeParams}, the
+ --- response is of type {@link SelectionRange SelectionRange[]} or a Thenable
+ --- that resolves to such.
+ textDocument_selectionRange = 'textDocument/selectionRange',
+ --- @since 3.16.0
+ textDocument_semanticTokens_full = 'textDocument/semanticTokens/full',
+ --- @since 3.16.0
+ textDocument_semanticTokens_full_delta = 'textDocument/semanticTokens/full/delta',
+ --- @since 3.16.0
+ textDocument_semanticTokens_range = 'textDocument/semanticTokens/range',
+ textDocument_signatureHelp = 'textDocument/signatureHelp',
+ --- A request to resolve the type definition locations of a symbol at a given text
+ --- document position. The request's parameter is of type [TextDocumentPositionParams]
+ --- (#TextDocumentPositionParams) the response is of type {@link Definition} or a
+ --- Thenable that resolves to such.
+ textDocument_typeDefinition = 'textDocument/typeDefinition',
+ --- A document will save request is sent from the client to the server before
+ --- the document is actually saved. The request can return an array of TextEdits
+ --- which will be applied to the text document before it is saved. Please note that
+ --- clients might drop results if computing the text edits took too long or if a
+ --- server constantly fails on this request. This is done to keep the save fast and
+ --- reliable.
+ textDocument_willSaveWaitUntil = 'textDocument/willSaveWaitUntil',
+ --- A request to resolve the subtypes for a given `TypeHierarchyItem`.
+ --- @since 3.17.0
+ typeHierarchy_subtypes = 'typeHierarchy/subtypes',
+ --- A request to resolve the supertypes for a given `TypeHierarchyItem`.
+ --- @since 3.17.0
+ typeHierarchy_supertypes = 'typeHierarchy/supertypes',
+ --- A request to show a document. This request might open an
+ --- external program depending on the value of the URI to open.
+ --- For example a request to open `https://code.visualstudio.com/`
+ --- will very likely open the URI in a WEB browser.
+ --- @since 3.16.0
+ window_showDocument = 'window/showDocument',
+ --- The show message request is sent from the server to the client to show a message
+ --- and a set of options actions to the user.
+ window_showMessageRequest = 'window/showMessageRequest',
+ --- The `window/workDoneProgress/create` request is sent from the server to the client to initiate progress
+ --- reporting from the server.
+ window_workDoneProgress_create = 'window/workDoneProgress/create',
+ --- A request to resolve the range inside the workspace
+ --- symbol's location.
+ --- @since 3.17.0
+ workspaceSymbol_resolve = 'workspaceSymbol/resolve',
+ --- A request sent from the server to the client to modified certain resources.
+ workspace_applyEdit = 'workspace/applyEdit',
+ --- A request to refresh all code actions
+ --- @since 3.16.0
+ workspace_codeLens_refresh = 'workspace/codeLens/refresh',
--- The 'workspace/configuration' request is sent from the server to the client to fetch a certain
--- configuration setting.
--- This pull model replaces the old push model were the client signaled configuration change via an
@@ -1092,33 +1142,21 @@ protocol.Methods = {
--- result of `workspace/configuration` requests) the server should register for an empty configuration
--- change event and empty the cache if such an event is received.
workspace_configuration = 'workspace/configuration',
- --- @since 3.16.0
- workspace_semanticTokens_refresh = 'workspace/semanticTokens/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
- --- files are created. Hence the `WorkspaceEdit` can not manipulate the content of the file
- --- to be created.
- --- @since 3.16.0
- workspace_willCreateFiles = 'workspace/willCreateFiles',
- --- The will rename files request is sent from the client to the server before files are actually
- --- renamed as long as the rename is triggered from within the client.
- --- @since 3.16.0
- workspace_willRenameFiles = 'workspace/willRenameFiles',
- --- The did delete files notification is sent from the client to the server when
- --- files were deleted from within the client.
- --- @since 3.16.0
- workspace_willDeleteFiles = 'workspace/willDeleteFiles',
- --- @since 3.17.0
- workspace_inlineValue_refresh = 'workspace/inlineValue/refresh',
- --- @since 3.17.0
- workspace_inlayHint_refresh = 'workspace/inlayHint/refresh',
--- The workspace diagnostic request definition.
--- @since 3.17.0
workspace_diagnostic = 'workspace/diagnostic',
--- The diagnostic refresh request definition.
--- @since 3.17.0
workspace_diagnostic_refresh = 'workspace/diagnostic/refresh',
+ --- A request send from the client to the server to execute a command. The request might return
+ --- a workspace edit which the client will apply to the workspace.
+ workspace_executeCommand = 'workspace/executeCommand',
+ --- @since 3.17.0
+ workspace_inlayHint_refresh = 'workspace/inlayHint/refresh',
+ --- @since 3.17.0
+ workspace_inlineValue_refresh = 'workspace/inlineValue/refresh',
+ --- @since 3.16.0
+ workspace_semanticTokens_refresh = 'workspace/semanticTokens/refresh',
--- A request to list project-wide symbols matching the query string given
--- by the {@link WorkspaceSymbolParams}. The response is
--- of type {@link SymbolInformation SymbolInformation[]} or a Thenable that
@@ -1127,61 +1165,23 @@ protocol.Methods = {
--- need to advertise support for WorkspaceSymbols via the client capability
--- `workspace.symbol.resolveSupport`.
workspace_symbol = 'workspace/symbol',
- --- A request to refresh all code actions
- --- @since 3.16.0
- workspace_codeLens_refresh = 'workspace/codeLens/refresh',
- --- A request send from the client to the server to execute a command. The request might return
- --- a workspace edit which the client will apply to the workspace.
- workspace_executeCommand = 'workspace/executeCommand',
- --- A request sent from the server to the client to modified certain resources.
- workspace_applyEdit = 'workspace/applyEdit',
- --- The `window/workDoneProgress/create` request is sent from the server to the client to initiate progress
- --- reporting from the server.
- window_workDoneProgress_create = 'window/workDoneProgress/create',
- --- A request to resolve the incoming calls for a given `CallHierarchyItem`.
+ --- 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
+ --- files are created. Hence the `WorkspaceEdit` can not manipulate the content of the file
+ --- to be created.
--- @since 3.16.0
- callHierarchy_incomingCalls = 'callHierarchy/incomingCalls',
- --- A request to resolve the outgoing calls for a given `CallHierarchyItem`.
+ workspace_willCreateFiles = 'workspace/willCreateFiles',
+ --- The did delete files notification is sent from the client to the server when
+ --- files were deleted from within the client.
--- @since 3.16.0
- callHierarchy_outgoingCalls = 'callHierarchy/outgoingCalls',
- --- A request to show a document. This request might open an
- --- external program depending on the value of the URI to open.
- --- For example a request to open `https://code.visualstudio.com/`
- --- will very likely open the URI in a WEB browser.
+ workspace_willDeleteFiles = 'workspace/willDeleteFiles',
+ --- The will rename files request is sent from the client to the server before files are actually
+ --- renamed as long as the rename is triggered from within the client.
--- @since 3.16.0
- window_showDocument = 'window/showDocument',
- --- A request to resolve the supertypes for a given `TypeHierarchyItem`.
- --- @since 3.17.0
- typeHierarchy_supertypes = 'typeHierarchy/supertypes',
- --- A request to resolve the subtypes for a given `TypeHierarchyItem`.
- --- @since 3.17.0
- typeHierarchy_subtypes = 'typeHierarchy/subtypes',
- --- A request to resolve additional properties for an inlay hint.
- --- The request's parameter is of type {@link InlayHint}, the response is
- --- of type {@link InlayHint} or a Thenable that resolves to such.
- --- @since 3.17.0
- inlayHint_resolve = 'inlayHint/resolve',
- --- The show message request is sent from the server to the client to show a message
- --- and a set of options actions to the user.
- window_showMessageRequest = 'window/showMessageRequest',
- --- Request to resolve additional information for a given completion item.The request's
- --- parameter is of type {@link CompletionItem} the response
- --- is of type {@link CompletionItem} or a Thenable that resolves to such.
- completionItem_resolve = 'completionItem/resolve',
- --- Request to resolve additional information for a given code action.The request's
- --- parameter is of type {@link CodeAction} the response
- --- is of type {@link CodeAction} or a Thenable that resolves to such.
- codeAction_resolve = 'codeAction/resolve',
- --- A request to resolve the range inside the workspace
- --- symbol's location.
- --- @since 3.17.0
- workspaceSymbol_resolve = 'workspaceSymbol/resolve',
- --- A request to resolve a command for a given code lens.
- codeLens_resolve = 'codeLens/resolve',
- --- Request to resolve additional information for a given document link. The request's
- --- parameter is of type {@link DocumentLink} the response
- --- is of type {@link DocumentLink} or a Thenable that resolves to such.
- documentLink_resolve = 'documentLink/resolve',
+ workspace_willRenameFiles = 'workspace/willRenameFiles',
+ --- The `workspace/workspaceFolders` is sent from the server to the client to fetch the open workspace folders.
+ workspace_workspaceFolders = 'workspace/workspaceFolders',
}
local function freeze(t)
return setmetatable({}, {
diff --git a/runtime/lua/vim/lsp/types/protocol.lua b/runtime/lua/vim/lsp/types/protocol.lua
@@ -1,7 +1,7 @@
--[[
-This file is autogenerated from scripts/lsp_types.lua
+This file is autogenerated from scripts/gen_lsp.lua
Regenerate:
-nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/protocol.lua
+nvim -l scripts/gen_lsp.lua gen --version 3.18 --runtime/lua/vim/lsp/types/protocol.lua
--]]
---@alias lsp.null nil
@@ -611,16 +611,12 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---A parameter literal used in inline completion requests.
---
---@since 3.18.0
----@proposed
---@class lsp.InlineCompletionParams: lsp.TextDocumentPositionParams, lsp.WorkDoneProgressParams
---Additional information about the context in which inline completions were
---requested.
---@field context lsp.InlineCompletionContext
---Represents a collection of {@link InlineCompletionItem inline completion items} to be presented in the editor.
----
----@since 3.18.0
----@proposed
---@class lsp.InlineCompletionList
---The inline completion items
---@field items lsp.InlineCompletionItem[]
@@ -628,10 +624,11 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---An inline completion item represents a text snippet that is proposed inline to complete text that is being typed.
---
---@since 3.18.0
----@proposed
---@class lsp.InlineCompletionItem
---The text to replace the range with. Must be set.
----@field insertText string|lsp.StringValue
+---@field insertText string
+---The format of the insert text. The format applies to the `insertText`. If omitted defaults to `InsertTextFormat.PlainText`.
+---@field insertTextFormat? lsp.InsertTextFormat
---A text that is used to decide if this inline completion should be shown. When `falsy` the {@link InlineCompletionItem.insertText} is used.
---@field filterText? string
---The range to replace. Must begin and end on the same line.
@@ -642,7 +639,6 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Inline completion options used during static or dynamic registration.
---
---@since 3.18.0
----@proposed
---@class lsp.InlineCompletionRegistrationOptions: lsp.InlineCompletionOptions, lsp.StaticRegistrationOptions
---@class lsp.RegistrationParams
@@ -1249,6 +1245,18 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Registration options for a {@link DocumentRangeFormattingRequest}.
---@class lsp.DocumentRangeFormattingRegistrationOptions: lsp.TextDocumentRegistrationOptions
+---The parameters of a {@link DocumentRangesFormattingRequest}.
+---
+---@since 3.18.0
+---@proposed
+---@class lsp.DocumentRangesFormattingParams
+---The document to format.
+---@field textDocument lsp.TextDocumentIdentifier
+---The ranges to format
+---@field ranges lsp.Range[]
+---The format options
+---@field options lsp.FormattingOptions
+
---The parameters of a {@link DocumentOnTypeFormattingRequest}.
---@class lsp.DocumentOnTypeFormattingParams
---The document to format.
@@ -1904,36 +1912,18 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Provides information about the context in which an inline completion was requested.
---
---@since 3.18.0
----@proposed
---@class lsp.InlineCompletionContext
---Describes how the inline completion was triggered.
---@field triggerKind lsp.InlineCompletionTriggerKind
---Provides information about the currently selected item in the autocomplete widget if it is visible.
---@field selectedCompletionInfo? lsp.SelectedCompletionInfo
----A string value used as a snippet is a template which allows to insert text
----and to control the editor cursor when insertion happens.
----
----A snippet can define tab stops and placeholders with `$1`, `$2`
----and `${3:foo}`. `$0` defines the final tab stop, it defaults to
----the end of the snippet. Variables are defined with `$name` and
----`${name:default value}`.
----
----@since 3.18.0
----@proposed
----@class lsp.StringValue
----The kind of string value.
----@field kind "snippet"
----The snippet string.
----@field value string
-
---Inline completion options used during static registration.
---
---@since 3.18.0
----@proposed
---@class lsp.InlineCompletionOptions
----General parameters to register for a notification or to register a provider.
+---General parameters to to register for an notification or to register a provider.
---@class lsp.Registration
---The id used to register the request. The id can be used to deregister
---the request again.
@@ -2104,7 +2094,6 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Inline completion options used during static registration.
---
---@since 3.18.0
----@proposed
---@field inlineCompletionProvider? boolean|lsp.InlineCompletionOptions
---Workspace specific server capabilities.
---@field workspace? anonym12
@@ -2399,6 +2388,11 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Provider options for a {@link DocumentRangeFormattingRequest}.
---@class lsp.DocumentRangeFormattingOptions
+---Whether the server supports formatting multiple ranges at once.
+---
+---@since 3.18.0
+---@proposed
+---@field rangesSupport? boolean
---Provider options for a {@link DocumentOnTypeFormattingRequest}.
---@class lsp.DocumentOnTypeFormattingOptions
@@ -2548,7 +2542,6 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Describes the currently selected completion item.
---
---@since 3.18.0
----@proposed
---@class lsp.SelectedCompletionInfo
---The range that will be replaced if this completion item is accepted.
---@field range lsp.Range
@@ -2857,7 +2850,6 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Client capabilities specific to inline completions.
---
---@since 3.18.0
----@proposed
---@field inlineCompletion? lsp.InlineCompletionClientCapabilities
---Capabilities specific to the notebook document support.
@@ -3283,6 +3275,11 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---@class lsp.DocumentRangeFormattingClientCapabilities
---Whether range formatting supports dynamic registration.
---@field dynamicRegistration? boolean
+---Whether the client supports formatting multiple ranges at once.
+---
+---@since 3.18.0
+---@proposed
+---@field rangesSupport? boolean
---Client capabilities of a {@link DocumentOnTypeFormattingRequest}.
---@class lsp.DocumentOnTypeFormattingClientCapabilities
@@ -3474,7 +3471,6 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Client capabilities specific to inline completions.
---
---@since 3.18.0
----@proposed
---@class lsp.InlineCompletionClientCapabilities
---Whether implementation supports dynamic registration for inline completion providers.
---@field dynamicRegistration? boolean
@@ -3663,6 +3659,12 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---| 1 # Type
---| 2 # Parameter
+---Defines whether the insert text in a completion item should be interpreted as
+---plain text or a snippet.
+---@alias lsp.InsertTextFormat
+---| 1 # PlainText
+---| 2 # Snippet
+
---The message type
---@alias lsp.MessageType
---| 1 # Error
@@ -3718,12 +3720,6 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---@alias lsp.CompletionItemTag
---| 1 # Deprecated
----Defines whether the insert text in a completion item should be interpreted as
----plain text or a snippet.
----@alias lsp.InsertTextFormat
----| 1 # PlainText
----| 2 # Snippet
-
---How whitespace and indentation is handled during completion
---item insertion.
---
@@ -3767,7 +3763,6 @@ nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/pro
---Describes how an {@link InlineCompletionItemProvider inline completion provider} was triggered.
---
---@since 3.18.0
----@proposed
---@alias lsp.InlineCompletionTriggerKind
---| 0 # Invoked
---| 1 # Automatic
diff --git a/scripts/gen_lsp.lua b/scripts/gen_lsp.lua
@@ -0,0 +1,288 @@
+--[[
+Generates lua-ls annotations for lsp
+USAGE:
+nvim -l scripts/gen_lsp.lua gen # this will overwrite runtime/lua/vim/lsp/types/protocol.lua
+nvim -l scripts/gen_lsp.lua gen --version 3.18 --build/new_lsp_types.lua
+nvim -l scripts/gen_lsp.lua gen --version 3.18 --out runtime/lua/vim/lsp/types/protocol.lua
+nvim -l scripts/gen_lsp.lua gen --version 3.18 --methods
+--]]
+
+local M = {}
+
+local function tofile(fname, text)
+ local f = io.open(fname, 'w')
+ if not f then
+ error(('failed to write: %s'):format(f))
+ else
+ f:write(text)
+ f:close()
+ end
+end
+
+local function read_json(opt)
+ local uri = 'https://raw.githubusercontent.com/microsoft/language-server-protocol/gh-pages/_specifications/lsp/'
+ .. opt.version
+ .. '/metaModel/metaModel.json'
+
+ local res = vim.system({ 'curl', '--no-progress-meter', uri, '-o', '-' }):wait()
+ if res.code ~= 0 or (res.stdout or ''):len() < 999 then
+ print(('URL failed: %s'):format(uri))
+ vim.print(res)
+ error(res.stdout)
+ end
+ return vim.json.decode(res.stdout)
+end
+
+-- Gets the Lua symbol for a given fully-qualified LSP method name.
+local function name(s)
+ return s:gsub('/', '_', 3)
+end
+
+local function gen_methods(protocol)
+ local output = {
+ '-- Generated by gen_lsp.lua, keep at end of file.',
+ '--- LSP method names.',
+ '---',
+ '---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#metaModel',
+ 'protocol.Methods = {',
+ }
+ local indent = (' '):rep(2)
+
+ table.sort(protocol.requests, function(a, b)
+ return name(a.method) < name(b.method)
+ end)
+ for _, item in ipairs(protocol.requests) 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, name(item.method), item.method)
+ end
+ end
+ output[#output + 1] = '}'
+ output = vim.list_extend(
+ output,
+ vim.split(
+ [[
+local function freeze(t)
+ return setmetatable({}, {
+ __index = t,
+ __newindex = function()
+ error('cannot modify immutable table')
+ end,
+ })
+end
+protocol.Methods = freeze(protocol.Methods)
+
+return protocol
+]],
+ '\n',
+ { trimempty = true }
+ )
+ )
+
+ local fname = './runtime/lua/vim/lsp/protocol.lua'
+ local bufnr = vim.fn.bufadd(fname)
+ vim.fn.bufload(bufnr)
+ vim.api.nvim_set_current_buf(bufnr)
+ local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
+ local index = vim.iter(ipairs(lines)):find(function(key, item)
+ return vim.startswith(item, '-- Generated by') and key or nil
+ end)
+ index = index and index - 1 or vim.api.nvim_buf_line_count(bufnr) - 1
+ vim.api.nvim_buf_set_lines(bufnr, index, -1, true, output)
+ vim.cmd.write()
+end
+
+function M.gen(opt)
+ local protocol = read_json(opt)
+
+ if opt.methods then
+ gen_methods(protocol)
+ end
+
+ local output = {
+ '--[[',
+ 'This file is autogenerated from scripts/gen_lsp.lua',
+ 'Regenerate:',
+ [=[nvim -l scripts/gen_lsp.lua gen --version 3.18 --runtime/lua/vim/lsp/types/protocol.lua]=],
+ '--]]',
+ '',
+ '---@alias lsp.null nil',
+ '---@alias uinteger integer',
+ '---@alias lsp.decimal number',
+ '---@alias lsp.DocumentUri string',
+ '---@alias lsp.URI string',
+ '---@alias lsp.LSPObject table<string, lsp.LSPAny>',
+ '---@alias lsp.LSPArray lsp.LSPAny[]',
+ '---@alias lsp.LSPAny lsp.LSPObject|lsp.LSPArray|string|number|boolean|nil',
+ '',
+ }
+
+ local anonymous_num = 0
+
+ local anonym_classes = {}
+
+ local simple_types = {
+ 'string',
+ 'boolean',
+ 'integer',
+ 'uinteger',
+ 'decimal',
+ }
+
+ local function parse_type(type)
+ if type.kind == 'reference' or type.kind == 'base' then
+ if vim.tbl_contains(simple_types, type.name) then
+ return type.name
+ end
+ return 'lsp.' .. type.name
+ elseif type.kind == 'array' then
+ return parse_type(type.element) .. '[]'
+ elseif type.kind == 'or' then
+ local val = ''
+ for _, item in ipairs(type.items) do
+ val = val .. parse_type(item) .. '|'
+ end
+ val = val:sub(0, -2)
+ return val
+ elseif type.kind == 'stringLiteral' then
+ return '"' .. type.value .. '"'
+ elseif type.kind == 'map' then
+ return 'table<' .. parse_type(type.key) .. ', ' .. parse_type(type.value) .. '>'
+ elseif type.kind == 'literal' then
+ -- can I use ---@param disabled? {reason: string}
+ -- use | to continue the inline class to be able to add docs
+ -- https://github.com/LuaLS/lua-language-server/issues/2128
+ anonymous_num = anonymous_num + 1
+ local anonym = { '---@class anonym' .. anonymous_num }
+ for _, field in ipairs(type.value.properties) do
+ if field.documentation then
+ field.documentation = field.documentation:gsub('\n', '\n---')
+ anonym[#anonym + 1] = '---' .. field.documentation
+ end
+ anonym[#anonym + 1] = '---@field '
+ .. field.name
+ .. (field.optional and '?' or '')
+ .. ' '
+ .. parse_type(field.type)
+ end
+ anonym[#anonym + 1] = ''
+ for _, line in ipairs(anonym) do
+ anonym_classes[#anonym_classes + 1] = line
+ end
+ return 'anonym' .. anonymous_num
+ elseif type.kind == 'tuple' then
+ local tuple = '{ '
+ for i, value in ipairs(type.items) do
+ tuple = tuple .. '[' .. i .. ']: ' .. parse_type(value) .. ', '
+ end
+ -- remove , at the end
+ tuple = tuple:sub(0, -3)
+ return tuple .. ' }'
+ end
+ vim.print(type)
+ return ''
+ end
+
+ for _, structure in ipairs(protocol.structures) do
+ if structure.documentation then
+ structure.documentation = structure.documentation:gsub('\n', '\n---')
+ output[#output + 1] = '---' .. structure.documentation
+ end
+ if structure.extends then
+ local class_string = '---@class lsp.'
+ .. structure.name
+ .. ': '
+ .. parse_type(structure.extends[1])
+ for _, mixin in ipairs(structure.mixins or {}) do
+ class_string = class_string .. ', ' .. parse_type(mixin)
+ end
+ output[#output + 1] = class_string
+ else
+ output[#output + 1] = '---@class lsp.' .. structure.name
+ end
+ for _, field in ipairs(structure.properties or {}) do
+ if field.documentation then
+ field.documentation = field.documentation:gsub('\n', '\n---')
+ output[#output + 1] = '---' .. field.documentation
+ end
+ output[#output + 1] = '---@field '
+ .. field.name
+ .. (field.optional and '?' or '')
+ .. ' '
+ .. parse_type(field.type)
+ end
+ output[#output + 1] = ''
+ end
+
+ for _, enum in ipairs(protocol.enumerations) do
+ if enum.documentation then
+ enum.documentation = enum.documentation:gsub('\n', '\n---')
+ output[#output + 1] = '---' .. enum.documentation
+ end
+ local enum_type = '---@alias lsp.' .. enum.name
+ for _, value in ipairs(enum.values) do
+ enum_type = enum_type
+ .. '\n---| '
+ .. (type(value.value) == 'string' and '"' .. value.value .. '"' or value.value)
+ .. ' # '
+ .. value.name
+ end
+ output[#output + 1] = enum_type
+ output[#output + 1] = ''
+ end
+
+ for _, alias in ipairs(protocol.typeAliases) do
+ if alias.documentation then
+ alias.documentation = alias.documentation:gsub('\n', '\n---')
+ output[#output + 1] = '---' .. alias.documentation
+ end
+ if alias.type.kind == 'or' then
+ local alias_type = '---@alias lsp.' .. alias.name .. ' '
+ for _, item in ipairs(alias.type.items) do
+ alias_type = alias_type .. parse_type(item) .. '|'
+ end
+ alias_type = alias_type:sub(0, -2)
+ output[#output + 1] = alias_type
+ else
+ output[#output + 1] = '---@alias lsp.' .. alias.name .. ' ' .. parse_type(alias.type)
+ end
+ output[#output + 1] = ''
+ end
+
+ for _, line in ipairs(anonym_classes) do
+ output[#output + 1] = line
+ end
+
+ tofile(opt.output_file, table.concat(output, '\n'))
+end
+
+local opt = {
+ output_file = 'runtime/lua/vim/lsp/types/protocol.lua',
+ version = nil,
+ methods = nil,
+}
+
+for i = 1, #_G.arg do
+ if _G.arg[i] == '--out' then
+ opt.output_file = _G.arg[i + 1]
+ elseif _G.arg[i] == '--version' then
+ opt.version = _G.arg[i + 1]
+ elseif _G.arg[i] == '--methods' then
+ opt.methods = true
+ elseif vim.startswith(_G.arg[i], '--') then
+ opt.output_file = _G.arg[i]:sub(3)
+ end
+end
+
+for _, a in ipairs(arg) do
+ if M[a] then
+ M[a](opt)
+ end
+end
+
+return M
diff --git a/scripts/lsp_types.lua b/scripts/lsp_types.lua
@@ -1,309 +0,0 @@
---[[
-Generates lua-ls annotations for lsp
-USAGE:
-nvim -l scripts/lsp_types.lua gen # this will overwrite runtime/lua/vim/lsp/types/protocol.lua
-nvim -l scripts/lsp_types.lua gen --version 3.1x --build/new_lsp_types.lua
-nvim -l scripts/lsp_types.lua gen --version 3.1x --out runtime/lua/vim/lsp/types/protocol.lua
-nvim -l scripts/lsp_types.lua gen --version 3.1x --methods
---]]
-
-local M = {}
-
-local function tofile(fname, text)
- local f = io.open(fname, 'w')
- if not f then
- error(('failed to write: %s'):format(f))
- else
- f:write(text)
- f:close()
- end
-end
-
-local function sort_by_method(tbl)
- local single, client, textD, workspace, others = {}, {}, {}, {}, {}
- for _, item in ipairs(tbl) do
- local parts = vim.split(item.method, '/', { trimempty = true })
- if #parts == 1 then
- single[#single + 1] = item
- elseif parts[1] == 'textDocument' then
- textD[#textD + 1] = item
- elseif parts[1] == 'client' then
- client[#client + 1] = item
- elseif parts[1] == 'workspace' then
- workspace[#workspace + 1] = item
- else
- others[#others + 1] = item
- end
- end
-
- local res = {}
- for _, item in ipairs({ single, client, textD, workspace, others }) do
- res = vim.list_extend(res, item)
- end
- return res
-end
-
-local function read_json(opt)
- local uri = 'https://raw.githubusercontent.com/microsoft/language-server-protocol/gh-pages/_specifications/lsp/'
- .. opt.version
- .. '/metaModel/metaModel.json'
-
- local res = vim.system({ 'curl', uri, '-o', '-' }):wait()
-
- if res.code ~= 0 then
- io.write(res.stderr)
- return
- end
- return vim.json.decode(res.stdout)
-end
-
-local function gen_methods(protocol)
- local output = {
- '-- Generated by lsp_types.lua, keep at end of file.',
- '--- LSP method names.',
- '---',
- '---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#metaModel',
- 'protocol.Methods = {',
- }
- local indent = (' '):rep(2)
-
- for _, item in ipairs(sort_by_method(protocol.requests)) do
- if item.method then
- local name = item.method:gsub('/', '_', 3)
- 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] = indent .. name .. " = '" .. item.method .. "',"
- end
- end
- output[#output + 1] = '}'
- output = vim.list_extend(
- output,
- vim.split(
- [[
-local function freeze(t)
- return setmetatable({}, {
- __index = t,
- __newindex = function()
- error('cannot modify immutable table')
- end,
- })
-end
-protocol.Methods = freeze(protocol.Methods)
-
-return protocol
-]],
- '\n',
- { trimempty = true }
- )
- )
-
- local fname = './runtime/lua/vim/lsp/protocol.lua'
- local bufnr = vim.fn.bufadd(fname)
- vim.fn.bufload(bufnr)
- vim.api.nvim_set_current_buf(bufnr)
- local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
- local index = vim.iter(ipairs(lines)):find(function(key, item)
- return vim.startswith(item, '-- Generated by') and key or nil
- end)
- index = index and index - 1 or vim.api.nvim_buf_line_count(bufnr) - 1
- vim.api.nvim_buf_set_lines(bufnr, index, -1, true, output)
- vim.cmd.write()
-end
-
-function M.gen(opt)
- local protocol = read_json(opt)
- if not protocol then
- os.exit(1)
- return
- end
-
- if opt.methods then
- gen_methods(protocol)
- end
-
- local output = {
- '--[[',
- 'This file is autogenerated from scripts/lsp_types.lua',
- 'Regenerate:',
- [=[nvim -l scripts/lsp_types.lua gen --version 3.1x --runtime/lua/vim/lsp/types/protocol.lua]=],
- '--]]',
- '',
- '---@alias lsp.null nil',
- '---@alias uinteger integer',
- '---@alias lsp.decimal number',
- '---@alias lsp.DocumentUri string',
- '---@alias lsp.URI string',
- '---@alias lsp.LSPObject table<string, lsp.LSPAny>',
- '---@alias lsp.LSPArray lsp.LSPAny[]',
- '---@alias lsp.LSPAny lsp.LSPObject|lsp.LSPArray|string|number|boolean|nil',
- '',
- }
-
- local anonymous_num = 0
-
- local anonym_classes = {}
-
- local simple_types = {
- 'string',
- 'boolean',
- 'integer',
- 'uinteger',
- 'decimal',
- }
-
- local function parse_type(type)
- if type.kind == 'reference' or type.kind == 'base' then
- if vim.tbl_contains(simple_types, type.name) then
- return type.name
- end
- return 'lsp.' .. type.name
- elseif type.kind == 'array' then
- return parse_type(type.element) .. '[]'
- elseif type.kind == 'or' then
- local val = ''
- for _, item in ipairs(type.items) do
- val = val .. parse_type(item) .. '|'
- end
- val = val:sub(0, -2)
- return val
- elseif type.kind == 'stringLiteral' then
- return '"' .. type.value .. '"'
- elseif type.kind == 'map' then
- return 'table<' .. parse_type(type.key) .. ', ' .. parse_type(type.value) .. '>'
- elseif type.kind == 'literal' then
- -- can I use ---@param disabled? {reason: string}
- -- use | to continue the inline class to be able to add docs
- -- https://github.com/LuaLS/lua-language-server/issues/2128
- anonymous_num = anonymous_num + 1
- local anonym = { '---@class anonym' .. anonymous_num }
- for _, field in ipairs(type.value.properties) do
- if field.documentation then
- field.documentation = field.documentation:gsub('\n', '\n---')
- anonym[#anonym + 1] = '---' .. field.documentation
- end
- anonym[#anonym + 1] = '---@field '
- .. field.name
- .. (field.optional and '?' or '')
- .. ' '
- .. parse_type(field.type)
- end
- anonym[#anonym + 1] = ''
- for _, line in ipairs(anonym) do
- anonym_classes[#anonym_classes + 1] = line
- end
- return 'anonym' .. anonymous_num
- elseif type.kind == 'tuple' then
- local tuple = '{ '
- for i, value in ipairs(type.items) do
- tuple = tuple .. '[' .. i .. ']: ' .. parse_type(value) .. ', '
- end
- -- remove , at the end
- tuple = tuple:sub(0, -3)
- return tuple .. ' }'
- end
- vim.print(type)
- return ''
- end
-
- for _, structure in ipairs(protocol.structures) do
- if structure.documentation then
- structure.documentation = structure.documentation:gsub('\n', '\n---')
- output[#output + 1] = '---' .. structure.documentation
- end
- if structure.extends then
- local class_string = '---@class lsp.'
- .. structure.name
- .. ': '
- .. parse_type(structure.extends[1])
- for _, mixin in ipairs(structure.mixins or {}) do
- class_string = class_string .. ', ' .. parse_type(mixin)
- end
- output[#output + 1] = class_string
- else
- output[#output + 1] = '---@class lsp.' .. structure.name
- end
- for _, field in ipairs(structure.properties or {}) do
- if field.documentation then
- field.documentation = field.documentation:gsub('\n', '\n---')
- output[#output + 1] = '---' .. field.documentation
- end
- output[#output + 1] = '---@field '
- .. field.name
- .. (field.optional and '?' or '')
- .. ' '
- .. parse_type(field.type)
- end
- output[#output + 1] = ''
- end
-
- for _, enum in ipairs(protocol.enumerations) do
- if enum.documentation then
- enum.documentation = enum.documentation:gsub('\n', '\n---')
- output[#output + 1] = '---' .. enum.documentation
- end
- local enum_type = '---@alias lsp.' .. enum.name
- for _, value in ipairs(enum.values) do
- enum_type = enum_type
- .. '\n---| '
- .. (type(value.value) == 'string' and '"' .. value.value .. '"' or value.value)
- .. ' # '
- .. value.name
- end
- output[#output + 1] = enum_type
- output[#output + 1] = ''
- end
-
- for _, alias in ipairs(protocol.typeAliases) do
- if alias.documentation then
- alias.documentation = alias.documentation:gsub('\n', '\n---')
- output[#output + 1] = '---' .. alias.documentation
- end
- if alias.type.kind == 'or' then
- local alias_type = '---@alias lsp.' .. alias.name .. ' '
- for _, item in ipairs(alias.type.items) do
- alias_type = alias_type .. parse_type(item) .. '|'
- end
- alias_type = alias_type:sub(0, -2)
- output[#output + 1] = alias_type
- else
- output[#output + 1] = '---@alias lsp.' .. alias.name .. ' ' .. parse_type(alias.type)
- end
- output[#output + 1] = ''
- end
-
- for _, line in ipairs(anonym_classes) do
- output[#output + 1] = line
- end
-
- tofile(opt.output_file, table.concat(output, '\n'))
-end
-
-local opt = {
- output_file = 'runtime/lua/vim/lsp/types/protocol.lua',
- version = nil,
- methods = nil,
-}
-
-for i = 1, #_G.arg do
- if _G.arg[i] == '--out' then
- opt.output_file = _G.arg[i + 1]
- elseif _G.arg[i] == '--version' then
- opt.version = _G.arg[i + 1]
- elseif _G.arg[i] == '--methods' then
- opt.methods = true
- elseif vim.startswith(_G.arg[i], '--') then
- opt.output_file = _G.arg[i]:sub(3)
- end
-end
-
-for _, a in ipairs(arg) do
- if M[a] then
- M[a](opt)
- end
-end
-
-return M