diff options
author | Christian Clason <c.clason@uni-graz.at> | 2023-08-09 11:06:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 11:06:13 +0200 |
commit | c43c745a14dced87a23227d7be4f1c33d4455193 (patch) | |
tree | 0cd5cf1cbbfa20be7fffbad696ba5ee97181847e /runtime/lua/vim/lsp | |
parent | 8afdc1f3867a620c8235b3d3964b019b94657190 (diff) | |
download | rneovim-c43c745a14dced87a23227d7be4f1c33d4455193.tar.gz rneovim-c43c745a14dced87a23227d7be4f1c33d4455193.tar.bz2 rneovim-c43c745a14dced87a23227d7be4f1c33d4455193.zip |
fix(lua): improve annotations for stricter luals diagnostics (#24609)
Problem: luals returns stricter diagnostics with bundled luarc.json
Solution: Improve some function and type annotations:
* use recognized uv.* types
* disable diagnostic for global `vim` in shared.lua
* docs: don't start comment lines with taglink (otherwise LuaLS will interpret it as a type)
* add type alias for lpeg pattern
* fix return annotation for `vim.secure.trust`
* rename local Range object in vim.version (shadows `Range` in vim.treesitter)
* fix some "missing fields" warnings
* add missing required fields for test functions in eval.lua
* rename lsp meta files for consistency
Diffstat (limited to 'runtime/lua/vim/lsp')
-rw-r--r-- | runtime/lua/vim/lsp/_meta.lua (renamed from runtime/lua/vim/lsp/types.lua) | 1 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/_meta/protocol.lua (renamed from runtime/lua/vim/lsp/types/protocol.lua) | 5 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/_watchfiles.lua | 8 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/inlay_hint.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 13 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 4 |
6 files changed, 20 insertions, 15 deletions
diff --git a/runtime/lua/vim/lsp/types.lua b/runtime/lua/vim/lsp/_meta.lua index 98e948c945..acf799264e 100644 --- a/runtime/lua/vim/lsp/types.lua +++ b/runtime/lua/vim/lsp/_meta.lua @@ -1,4 +1,5 @@ ---@meta +error('Cannot require a meta file') ---@alias lsp-handler fun(err: lsp.ResponseError|nil, result: any, context: lsp.HandlerContext, config: table|nil): any? diff --git a/runtime/lua/vim/lsp/types/protocol.lua b/runtime/lua/vim/lsp/_meta/protocol.lua index e1ed8dbcc3..72b0f00f65 100644 --- a/runtime/lua/vim/lsp/types/protocol.lua +++ b/runtime/lua/vim/lsp/_meta/protocol.lua @@ -1,9 +1,12 @@ --[[ 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 +nvim -l scripts/gen_lsp.lua gen --version 3.18 --runtime/lua/vim/lsp/_meta/protocol.lua --]] +---@meta +error('Cannot require a meta file') + ---@alias lsp.null nil ---@alias uinteger integer ---@alias lsp.decimal number diff --git a/runtime/lua/vim/lsp/_watchfiles.lua b/runtime/lua/vim/lsp/_watchfiles.lua index 5dbd4a7199..1a4909b3f3 100644 --- a/runtime/lua/vim/lsp/_watchfiles.lua +++ b/runtime/lua/vim/lsp/_watchfiles.lua @@ -6,11 +6,13 @@ local lpeg = vim.lpeg local M = {} +---@alias lpeg userdata + --- Parses the raw pattern into an |lpeg| pattern. LPeg patterns natively support the "this" or "that" --- alternative constructions described in the LSP spec that cannot be expressed in a standard Lua pattern. --- ---@param pattern string The raw glob pattern ----@return userdata An |lpeg| representation of the pattern, or nil if the pattern is invalid. +---@return lpeg An |lpeg| representation of the pattern, or nil if the pattern is invalid. local function parse(pattern) local l = lpeg @@ -109,7 +111,7 @@ local to_lsp_change_type = { --- Default excludes the same as VSCode's `files.watcherExclude` setting. --- https://github.com/microsoft/vscode/blob/eef30e7165e19b33daa1e15e92fa34ff4a5df0d3/src/vs/workbench/contrib/files/browser/files.contribution.ts#L261 ----@type Lpeg pattern +---@type lpeg parsed Lpeg pattern M._poll_exclude_pattern = parse('**/.git/{objects,subtree-cache}/**') + parse('**/node_modules/*/**') + parse('**/.hg/store/**') @@ -132,7 +134,7 @@ function M.register(reg, ctx) if not has_capability or not client.workspace_folders then return end - local watch_regs = {} --- @type table<string,{pattern:userdata,kind:integer}> + local watch_regs = {} --- @type table<string,{pattern:lpeg,kind:integer}> for _, w in ipairs(reg.registerOptions.watchers) do local relative_pattern = false local glob_patterns = {} --- @type {baseUri:string, pattern: string}[] diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua index eb2f59b312..8407105d47 100644 --- a/runtime/lua/vim/lsp/inlay_hint.lua +++ b/runtime/lua/vim/lsp/inlay_hint.lua @@ -5,8 +5,8 @@ local api = vim.api local M = {} ---@class lsp.inlay_hint.bufstate ----@field version integer ----@field client_hint table<integer, table<integer, lsp.InlayHint[]>> client_id -> (lnum -> hints) +---@field version? integer +---@field client_hint? table<integer, table<integer, lsp.InlayHint[]>> client_id -> (lnum -> hints) ---@field applied table<integer, integer> Last version of hints applied to this line ---@field enabled boolean Whether inlay hints are enabled for this buffer ---@type table<integer, lsp.inlay_hint.bufstate> diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index bab1b23ee4..5b20344bd3 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -14,11 +14,11 @@ local uv = vim.uv --- @field marked boolean whether this token has had extmarks applied --- --- @class STCurrentResult ---- @field version integer document version associated with this result ---- @field result_id string resultId from the server; used with delta requests ---- @field highlights STTokenRange[] cache of highlight ranges for this document version ---- @field tokens integer[] raw token array as received by the server. used for calculating delta responses ---- @field namespace_cleared boolean whether the namespace was cleared for this result yet +--- @field version? integer document version associated with this result +--- @field result_id? string resultId from the server; used with delta requests +--- @field highlights? STTokenRange[] cache of highlight ranges for this document version +--- @field tokens? integer[] raw token array as received by the server. used for calculating delta responses +--- @field namespace_cleared? boolean whether the namespace was cleared for this result yet --- --- @class STActiveRequest --- @field request_id integer the LSP request ID of the most recent request sent to the server @@ -717,8 +717,7 @@ end --- mark will be deleted by the semantic token engine when appropriate; for --- example, when the LSP sends updated tokens. This function is intended for --- use inside |LspTokenUpdate| callbacks. ----@param token (table) a semantic token, found as `args.data.token` in ---- |LspTokenUpdate|. +---@param token (table) a semantic token, found as `args.data.token` in |LspTokenUpdate|. ---@param bufnr (integer) the buffer to highlight ---@param client_id (integer) The ID of the |vim.lsp.client| ---@param hl_group (string) Highlight group name diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 738e23ff28..633cddca2d 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -715,8 +715,8 @@ end --- Turns the result of a `textDocument/completion` request into vim-compatible --- |complete-items|. --- ----@param result table The result of a `textDocument/completion` call, e.g. from ----|vim.lsp.buf.completion()|, which may be one of `CompletionItem[]`, +---@param result table The result of a `textDocument/completion` call, e.g. +--- from |vim.lsp.buf.completion()|, which may be one of `CompletionItem[]`, --- `CompletionList` or `null` ---@param prefix (string) the prefix to filter the completion items ---@return table { matches = complete-items table, incomplete = bool } |