aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/protocol.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/lsp/protocol.lua')
-rw-r--r--runtime/lua/vim/lsp/protocol.lua150
1 files changed, 59 insertions, 91 deletions
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index a7c3914834..599f02425e 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -1,24 +1,17 @@
--- Protocol for the Microsoft Language Server Protocol (mslsp)
-
-local protocol = {}
+--- @diagnostic disable: duplicate-doc-alias
---[=[
----@private
---- Useful for interfacing with:
---- https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.md
-function transform_schema_comments()
- nvim.command [[silent! '<,'>g/\/\*\*\|\*\/\|^$/d]]
- nvim.command [[silent! '<,'>s/^\(\s*\) \* \=\(.*\)/\1--\2/]]
-end
----@private
-function transform_schema_to_table()
- transform_schema_comments()
- nvim.command [[silent! '<,'>s/: \S\+//]]
- nvim.command [[silent! '<,'>s/export const //]]
- nvim.command [[silent! '<,'>s/export namespace \(\S*\)\s*{/protocol.\1 = {/]]
- nvim.command [[silent! '<,'>s/namespace \(\S*\)\s*{/protocol.\1 = {/]]
+---@param tbl table<string, string|number>
+local function get_value_set(tbl)
+ local value_set = {}
+ for _, v in pairs(tbl) do
+ table.insert(value_set, v)
+ end
+ table.sort(value_set)
+ return value_set
end
---]=]
+
+-- Protocol for the Microsoft Language Server Protocol (mslsp)
+local protocol = {}
local constants = {
--- @enum lsp.DiagnosticSeverity
@@ -313,10 +306,13 @@ local constants = {
},
}
-for k, v in pairs(constants) do
- local tbl = vim.deepcopy(v)
- vim.tbl_add_reverse_lookup(tbl)
- protocol[k] = tbl
+for k1, v1 in pairs(constants) do
+ local tbl = vim.deepcopy(v1, true)
+ for _, k2 in ipairs(vim.tbl_keys(tbl)) do
+ local v2 = tbl[k2]
+ tbl[v2] = k2
+ end
+ protocol[k1] = tbl
end
--[=[
@@ -722,11 +718,7 @@ function protocol.make_client_capabilities()
codeActionLiteralSupport = {
codeActionKind = {
- valueSet = (function()
- local res = vim.tbl_values(constants.CodeActionKind)
- table.sort(res)
- return res
- end)(),
+ valueSet = get_value_set(constants.CodeActionKind),
},
},
isPreferredSupport = true,
@@ -751,18 +743,18 @@ function protocol.make_client_capabilities()
commitCharactersSupport = false,
preselectSupport = false,
deprecatedSupport = false,
- documentationFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText },
+ documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
},
completionItemKind = {
- valueSet = (function()
- local res = {}
- for k in ipairs(protocol.CompletionItemKind) do
- if type(k) == 'number' then
- table.insert(res, k)
- end
- end
- return res
- end)(),
+ valueSet = get_value_set(constants.CompletionItemKind),
+ },
+ completionList = {
+ itemDefaults = {
+ 'editRange',
+ 'insertTextFormat',
+ 'insertTextMode',
+ 'data',
+ },
},
-- TODO(tjdevries): Implement this
@@ -783,13 +775,13 @@ function protocol.make_client_capabilities()
},
hover = {
dynamicRegistration = true,
- contentFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText },
+ contentFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
},
signatureHelp = {
dynamicRegistration = false,
signatureInformation = {
activeParameterSupport = true,
- documentationFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText },
+ documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
parameterInformation = {
labelOffsetSupport = true,
},
@@ -804,15 +796,7 @@ function protocol.make_client_capabilities()
documentSymbol = {
dynamicRegistration = false,
symbolKind = {
- valueSet = (function()
- local res = {}
- for k in ipairs(protocol.SymbolKind) do
- if type(k) == 'number' then
- table.insert(res, k)
- end
- end
- return res
- end)(),
+ valueSet = get_value_set(constants.SymbolKind),
},
hierarchicalDocumentSymbolSupport = true,
},
@@ -823,15 +807,7 @@ function protocol.make_client_capabilities()
publishDiagnostics = {
relatedInformation = true,
tagSupport = {
- valueSet = (function()
- local res = {}
- for k in ipairs(protocol.DiagnosticTag) do
- if type(k) == 'number' then
- table.insert(res, k)
- end
- end
- return res
- end)(),
+ valueSet = get_value_set(constants.DiagnosticTag),
},
dataSupport = true,
},
@@ -843,15 +819,7 @@ function protocol.make_client_capabilities()
symbol = {
dynamicRegistration = false,
symbolKind = {
- valueSet = (function()
- local res = {}
- for k in ipairs(protocol.SymbolKind) do
- if type(k) == 'number' then
- table.insert(res, k)
- end
- end
- return res
- end)(),
+ valueSet = get_value_set(constants.SymbolKind),
},
},
configuration = true,
@@ -891,9 +859,9 @@ end
--- Creates a normalized object describing LSP server capabilities.
---@param server_capabilities table Table of capabilities supported by the server
----@return table|nil Normalized table of capabilities
+---@return lsp.ServerCapabilities|nil : Normalized table of capabilities
function protocol.resolve_capabilities(server_capabilities)
- local TextDocumentSyncKind = protocol.TextDocumentSyncKind
+ local TextDocumentSyncKind = protocol.TextDocumentSyncKind ---@type table<string|number, string|number>
local textDocumentSync = server_capabilities.textDocumentSync
if textDocumentSync == nil then
-- Defaults if omitted.
@@ -934,7 +902,7 @@ end
-- 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
+---@see https://microsoft.github.io/language-server-protocol/specification/#metaModel
protocol.Methods = {
--- A request to resolve the incoming calls for a given `CallHierarchyItem`.
--- @since 3.16.0
@@ -1021,16 +989,14 @@ protocol.Methods = {
--- `filterText`, `insertText`, and `textEdit`, must not be changed during resolve.
textDocument_completion = 'textDocument/completion',
--- 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.
+ --- document position. The request's parameter is of type {@link 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.
+ --- document position. The request's parameter is of type {@link 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',
--- The document diagnostic request definition.
--- @since 3.17.0
@@ -1064,9 +1030,9 @@ protocol.Methods = {
--- 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.
+ --- text document position. The request's parameter is of type {@link TextDocumentPosition}
+ --- the request response is an array of type {@link DocumentHighlight}
+ --- or a Thenable that resolves to such.
textDocument_documentHighlight = 'textDocument/documentHighlight',
--- A request to provide document links
textDocument_documentLink = 'textDocument/documentLink',
@@ -1080,16 +1046,15 @@ protocol.Methods = {
--- response is of type {@link FoldingRangeList} or a Thenable
--- that resolves to such.
textDocument_foldingRange = 'textDocument/foldingRange',
- --- A request to to format a whole document.
+ --- 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.
+ --- document position. The request's parameter is of type {@link 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
@@ -1100,6 +1065,7 @@ protocol.Methods = {
--- type {@link InlineCompletionParams}, the response is of type
--- {@link InlineCompletion InlineCompletion[]} or a Thenable that resolves to such.
--- @since 3.18.0
+ --- @proposed
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
@@ -1155,9 +1121,8 @@ protocol.Methods = {
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.
+ --- document position. The request's parameter is of type {@link TextDocumentPositionParams}
+ --- the response is of type {@link Definition} or a Thenable that resolves to such.
textDocument_typeDefinition = 'textDocument/typeDefinition',
--- A document will save notification is sent from the client to the server before
--- the document is actually saved.
@@ -1200,14 +1165,14 @@ protocol.Methods = {
--- symbol's location.
--- @since 3.17.0
workspaceSymbol_resolve = 'workspaceSymbol/resolve',
- --- A request sent from the server to the client to modified certain resources.
+ --- A request sent from the server to the client to modify 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
+ --- This pull model replaces the old push model where the client signaled configuration change via an
--- event. If the server still needs to react to configuration changes (since the server caches the
--- 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.
@@ -1240,9 +1205,12 @@ protocol.Methods = {
--- files were renamed from within the client.
--- @since 3.16.0
workspace_didRenameFiles = 'workspace/didRenameFiles',
- --- A request send from the client to the server to execute a command. The request might return
+ --- A request sent 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.18.0
+ --- @proposed
+ workspace_foldingRange_refresh = 'workspace/foldingRange/refresh',
--- @since 3.17.0
workspace_inlayHint_refresh = 'workspace/inlayHint/refresh',
--- @since 3.17.0