mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
refactor(lua): improve type annotations
This commit is contained in:

committed by
Lewis Russell

parent
d8e384b7bf
commit
5e49ef0af3
@@ -12,9 +12,6 @@ end
|
||||
|
||||
local sysname = vim.uv.os_uname().sysname
|
||||
|
||||
-- Protocol for the Microsoft Language Server Protocol (mslsp)
|
||||
local protocol = {}
|
||||
|
||||
local constants = {
|
||||
--- @enum lsp.DiagnosticSeverity
|
||||
DiagnosticSeverity = {
|
||||
@@ -46,6 +43,8 @@ local constants = {
|
||||
Info = 3,
|
||||
-- A log message.
|
||||
Log = 4,
|
||||
-- A debug message.
|
||||
Debug = 5,
|
||||
},
|
||||
|
||||
-- The file event type.
|
||||
@@ -308,326 +307,18 @@ local constants = {
|
||||
},
|
||||
}
|
||||
|
||||
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
|
||||
-- Protocol for the Microsoft Language Server Protocol (mslsp)
|
||||
local protocol = {}
|
||||
|
||||
--- @diagnostic disable:no-unknown
|
||||
for k1, v1 in pairs(vim.deepcopy(constants, true)) do
|
||||
for _, k2 in ipairs(vim.tbl_keys(v1)) do
|
||||
local v2 = v1[k2]
|
||||
v1[v2] = k2
|
||||
end
|
||||
protocol[k1] = tbl
|
||||
protocol[k1] = v1
|
||||
end
|
||||
|
||||
--[=[
|
||||
--Text document specific client capabilities.
|
||||
export interface TextDocumentClientCapabilities {
|
||||
synchronization?: {
|
||||
--Whether text document synchronization supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports sending will save notifications.
|
||||
willSave?: boolean;
|
||||
--The client supports sending a will save request and
|
||||
--waits for a response providing text edits which will
|
||||
--be applied to the document before it is saved.
|
||||
willSaveWaitUntil?: boolean;
|
||||
--The client supports did save notifications.
|
||||
didSave?: boolean;
|
||||
}
|
||||
--Capabilities specific to the `textDocument/completion`
|
||||
completion?: {
|
||||
--Whether completion supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports the following `CompletionItem` specific
|
||||
--capabilities.
|
||||
completionItem?: {
|
||||
--The client supports snippets as insert text.
|
||||
--
|
||||
--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. Placeholders with equal identifiers are linked,
|
||||
--that is typing in one will update others too.
|
||||
snippetSupport?: boolean;
|
||||
--The client supports commit characters on a completion item.
|
||||
commitCharactersSupport?: boolean
|
||||
--The client supports the following content formats for the documentation
|
||||
--property. The order describes the preferred format of the client.
|
||||
documentationFormat?: MarkupKind[];
|
||||
--The client supports the deprecated property on a completion item.
|
||||
deprecatedSupport?: boolean;
|
||||
--The client supports the preselect property on a completion item.
|
||||
preselectSupport?: boolean;
|
||||
}
|
||||
completionItemKind?: {
|
||||
--The completion item kind values the client supports. When this
|
||||
--property exists the client also guarantees that it will
|
||||
--handle values outside its set gracefully and falls back
|
||||
--to a default value when unknown.
|
||||
--
|
||||
--If this property is not present the client only supports
|
||||
--the completion items kinds from `Text` to `Reference` as defined in
|
||||
--the initial version of the protocol.
|
||||
valueSet?: CompletionItemKind[];
|
||||
},
|
||||
--The client supports to send additional context information for a
|
||||
--`textDocument/completion` request.
|
||||
contextSupport?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/hover`
|
||||
hover?: {
|
||||
--Whether hover supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports the follow content formats for the content
|
||||
--property. The order describes the preferred format of the client.
|
||||
contentFormat?: MarkupKind[];
|
||||
};
|
||||
--Capabilities specific to the `textDocument/signatureHelp`
|
||||
signatureHelp?: {
|
||||
--Whether signature help supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports the following `SignatureInformation`
|
||||
--specific properties.
|
||||
signatureInformation?: {
|
||||
--The client supports the follow content formats for the documentation
|
||||
--property. The order describes the preferred format of the client.
|
||||
documentationFormat?: MarkupKind[];
|
||||
--Client capabilities specific to parameter information.
|
||||
parameterInformation?: {
|
||||
--The client supports processing label offsets instead of a
|
||||
--simple label string.
|
||||
--
|
||||
--Since 3.14.0
|
||||
labelOffsetSupport?: boolean;
|
||||
}
|
||||
};
|
||||
};
|
||||
--Capabilities specific to the `textDocument/references`
|
||||
references?: {
|
||||
--Whether references supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/documentHighlight`
|
||||
documentHighlight?: {
|
||||
--Whether document highlight supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/documentSymbol`
|
||||
documentSymbol?: {
|
||||
--Whether document symbol supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--Specific capabilities for the `SymbolKind`.
|
||||
symbolKind?: {
|
||||
--The symbol kind values the client supports. When this
|
||||
--property exists the client also guarantees that it will
|
||||
--handle values outside its set gracefully and falls back
|
||||
--to a default value when unknown.
|
||||
--
|
||||
--If this property is not present the client only supports
|
||||
--the symbol kinds from `File` to `Array` as defined in
|
||||
--the initial version of the protocol.
|
||||
valueSet?: SymbolKind[];
|
||||
}
|
||||
--The client supports hierarchical document symbols.
|
||||
hierarchicalDocumentSymbolSupport?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/formatting`
|
||||
formatting?: {
|
||||
--Whether formatting supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/rangeFormatting`
|
||||
rangeFormatting?: {
|
||||
--Whether range formatting supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/onTypeFormatting`
|
||||
onTypeFormatting?: {
|
||||
--Whether on type formatting supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/declaration`
|
||||
declaration?: {
|
||||
--Whether declaration supports dynamic registration. If this is set to `true`
|
||||
--the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
|
||||
--return value for the corresponding server capability as well.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports additional metadata in the form of declaration links.
|
||||
--
|
||||
--Since 3.14.0
|
||||
linkSupport?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/definition`.
|
||||
--
|
||||
--Since 3.14.0
|
||||
definition?: {
|
||||
--Whether definition supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports additional metadata in the form of definition links.
|
||||
linkSupport?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/typeDefinition`
|
||||
--
|
||||
--Since 3.6.0
|
||||
typeDefinition?: {
|
||||
--Whether typeDefinition supports dynamic registration. If this is set to `true`
|
||||
--the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
|
||||
--return value for the corresponding server capability as well.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports additional metadata in the form of definition links.
|
||||
--
|
||||
--Since 3.14.0
|
||||
linkSupport?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/implementation`.
|
||||
--
|
||||
--Since 3.6.0
|
||||
implementation?: {
|
||||
--Whether implementation supports dynamic registration. If this is set to `true`
|
||||
--the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
|
||||
--return value for the corresponding server capability as well.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports additional metadata in the form of definition links.
|
||||
--
|
||||
--Since 3.14.0
|
||||
linkSupport?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/codeAction`
|
||||
codeAction?: {
|
||||
--Whether code action supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client support code action literals as a valid
|
||||
--response of the `textDocument/codeAction` request.
|
||||
--
|
||||
--Since 3.8.0
|
||||
codeActionLiteralSupport?: {
|
||||
--The code action kind is support with the following value
|
||||
--set.
|
||||
codeActionKind: {
|
||||
--The code action kind values the client supports. When this
|
||||
--property exists the client also guarantees that it will
|
||||
--handle values outside its set gracefully and falls back
|
||||
--to a default value when unknown.
|
||||
valueSet: CodeActionKind[];
|
||||
};
|
||||
};
|
||||
};
|
||||
--Capabilities specific to the `textDocument/codeLens`
|
||||
codeLens?: {
|
||||
--Whether code lens supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/documentLink`
|
||||
documentLink?: {
|
||||
--Whether document link supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `textDocument/documentColor` and the
|
||||
--`textDocument/colorPresentation` request.
|
||||
--
|
||||
--Since 3.6.0
|
||||
colorProvider?: {
|
||||
--Whether colorProvider supports dynamic registration. If this is set to `true`
|
||||
--the client supports the new `(ColorProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)`
|
||||
--return value for the corresponding server capability as well.
|
||||
dynamicRegistration?: boolean;
|
||||
}
|
||||
--Capabilities specific to the `textDocument/rename`
|
||||
rename?: {
|
||||
--Whether rename supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--The client supports testing for validity of rename operations
|
||||
--before execution.
|
||||
prepareSupport?: boolean;
|
||||
};
|
||||
--Capabilities specific to `textDocument/publishDiagnostics`.
|
||||
publishDiagnostics?: {
|
||||
--Whether the clients accepts diagnostics with related information.
|
||||
relatedInformation?: boolean;
|
||||
--Client supports the tag property to provide meta data about a diagnostic.
|
||||
--Clients supporting tags have to handle unknown tags gracefully.
|
||||
--Since 3.15.0
|
||||
tagSupport?: {
|
||||
--The tags supported by this client
|
||||
valueSet: DiagnosticTag[];
|
||||
};
|
||||
};
|
||||
--Capabilities specific to `textDocument/foldingRange` requests.
|
||||
--
|
||||
--Since 3.10.0
|
||||
foldingRange?: {
|
||||
--Whether implementation supports dynamic registration for folding range providers. If this is set to `true`
|
||||
--the client supports the new `(FoldingRangeProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)`
|
||||
--return value for the corresponding server capability as well.
|
||||
dynamicRegistration?: boolean;
|
||||
--The maximum number of folding ranges that the client prefers to receive per document. The value serves as a
|
||||
--hint, servers are free to follow the limit.
|
||||
rangeLimit?: number;
|
||||
--If set, the client signals that it only supports folding complete lines. If set, client will
|
||||
--ignore specified `startCharacter` and `endCharacter` properties in a FoldingRange.
|
||||
lineFoldingOnly?: boolean;
|
||||
};
|
||||
}
|
||||
--]=]
|
||||
|
||||
--[=[
|
||||
--Workspace specific client capabilities.
|
||||
export interface WorkspaceClientCapabilities {
|
||||
--The client supports applying batch edits to the workspace by supporting
|
||||
--the request 'workspace/applyEdit'
|
||||
applyEdit?: boolean;
|
||||
--Capabilities specific to `WorkspaceEdit`s
|
||||
workspaceEdit?: {
|
||||
--The client supports versioned document changes in `WorkspaceEdit`s
|
||||
documentChanges?: boolean;
|
||||
--The resource operations the client supports. Clients should at least
|
||||
--support 'create', 'rename' and 'delete' files and folders.
|
||||
resourceOperations?: ResourceOperationKind[];
|
||||
--The failure handling strategy of a client if applying the workspace edit
|
||||
--fails.
|
||||
failureHandling?: FailureHandlingKind;
|
||||
};
|
||||
--Capabilities specific to the `workspace/didChangeConfiguration` notification.
|
||||
didChangeConfiguration?: {
|
||||
--Did change configuration notification supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `workspace/didChangeWatchedFiles` notification.
|
||||
didChangeWatchedFiles?: {
|
||||
--Did change watched files notification supports dynamic registration. Please note
|
||||
--that the current protocol doesn't support static configuration for file changes
|
||||
--from the server side.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--Capabilities specific to the `workspace/symbol` request.
|
||||
symbol?: {
|
||||
--Symbol request supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
--Specific capabilities for the `SymbolKind` in the `workspace/symbol` request.
|
||||
symbolKind?: {
|
||||
--The symbol kind values the client supports. When this
|
||||
--property exists the client also guarantees that it will
|
||||
--handle values outside its set gracefully and falls back
|
||||
--to a default value when unknown.
|
||||
--
|
||||
--If this property is not present the client only supports
|
||||
--the symbol kinds from `File` to `Array` as defined in
|
||||
--the initial version of the protocol.
|
||||
valueSet?: SymbolKind[];
|
||||
}
|
||||
};
|
||||
--Capabilities specific to the `workspace/executeCommand` request.
|
||||
executeCommand?: {
|
||||
--Execute command supports dynamic registration.
|
||||
dynamicRegistration?: boolean;
|
||||
};
|
||||
--The client has support for workspace folders.
|
||||
--
|
||||
--Since 3.6.0
|
||||
workspaceFolders?: boolean;
|
||||
--The client supports `workspace/configuration` requests.
|
||||
--
|
||||
--Since 3.6.0
|
||||
configuration?: boolean;
|
||||
}
|
||||
--]=]
|
||||
--- @diagnostic enable:no-unknown
|
||||
|
||||
--- Gets a new ClientCapabilities object describing the LSP client
|
||||
--- capabilities.
|
||||
@@ -1250,14 +941,5 @@ protocol.Methods = {
|
||||
--- 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({}, {
|
||||
__index = t,
|
||||
__newindex = function()
|
||||
error('cannot modify immutable table')
|
||||
end,
|
||||
})
|
||||
end
|
||||
protocol.Methods = freeze(protocol.Methods)
|
||||
|
||||
return protocol
|
||||
|
Reference in New Issue
Block a user