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
This commit is contained in:
Christian Clason
2023-08-09 11:06:13 +02:00
committed by GitHub
parent 8afdc1f386
commit c43c745a14
25 changed files with 111 additions and 95 deletions

View File

@ -562,8 +562,8 @@ end
---@param opts table|nil When omitted or "nil", retrieve the current configuration. Otherwise, a
--- configuration table with the following keys:
--- - underline: (default true) Use underline for diagnostics. Options:
--- * severity: Only underline diagnostics matching the given severity
--- |diagnostic-severity|
--- * severity: Only underline diagnostics matching the given
--- severity |diagnostic-severity|
--- - virtual_text: (default true) Use virtual text for diagnostics. If multiple diagnostics
--- are set for a namespace, one prefix per diagnostic + the last diagnostic
--- message are shown.
@ -596,8 +596,8 @@ end
--- end
--- </pre>
--- - signs: (default true) Use signs for diagnostics. Options:
--- * severity: Only show signs for diagnostics matching the given severity
--- |diagnostic-severity|
--- * severity: Only show signs for diagnostics matching the given
--- severity |diagnostic-severity|
--- * priority: (number, default 10) Base priority to use for signs. When
--- {severity_sort} is used, the priority of a sign is adjusted based on
--- its severity. Otherwise, all signs use the same priority.
@ -723,17 +723,17 @@ function M.get_namespaces()
end
---@class Diagnostic
---@field bufnr integer
---@field bufnr? integer
---@field lnum integer 0-indexed
---@field end_lnum nil|integer 0-indexed
---@field end_lnum? integer 0-indexed
---@field col integer 0-indexed
---@field end_col nil|integer 0-indexed
---@field severity DiagnosticSeverity
---@field end_col? integer 0-indexed
---@field severity? DiagnosticSeverity
---@field message string
---@field source nil|string
---@field code nil|string
---@field _tags { deprecated: boolean, unnecessary: boolean}
---@field user_data nil|any arbitrary data plugins can add
---@field source? string
---@field code? string
---@field _tags? { deprecated: boolean, unnecessary: boolean}
---@field user_data? any arbitrary data plugins can add
--- Get current diagnostics.
---
@ -819,13 +819,13 @@ end
---
---@param opts table|nil Configuration table with the following keys:
--- - namespace: (number) Only consider diagnostics from the given namespace.
--- - cursor_position: (cursor position) Cursor position as a (row, col) tuple. See
--- |nvim_win_get_cursor()|. Defaults to the current cursor position.
--- - cursor_position: (cursor position) Cursor position as a (row, col) tuple.
--- See |nvim_win_get_cursor()|. Defaults to the current cursor position.
--- - wrap: (boolean, default true) Whether to loop around file or not. Similar to 'wrapscan'.
--- - severity: See |diagnostic-severity|.
--- - float: (boolean or table, default true) If "true", call |vim.diagnostic.open_float()|
--- after moving. If a table, pass the table as the {opts} parameter to
--- |vim.diagnostic.open_float()|. Unless overridden, the float will show
--- after moving. If a table, pass the table as the {opts} parameter
--- to |vim.diagnostic.open_float()|. Unless overridden, the float will show
--- diagnostics at the new cursor position (as if "cursor" were passed to
--- the "scope" option).
--- - win_id: (number, default 0) Window ID
@ -1213,8 +1213,8 @@ end
--- Show diagnostics in a floating window.
---
---@param opts table|nil Configuration table with the same keys as
--- |vim.lsp.util.open_floating_preview()| in addition to the following:
---@param opts table|nil Configuration table with the same keys
--- as |vim.lsp.util.open_floating_preview()| in addition to the following:
--- - bufnr: (number) Buffer number to show diagnostics from.
--- Defaults to the current buffer.
--- - namespace: (number) Limit diagnostics to the given namespace
@ -1227,16 +1227,15 @@ end
--- otherwise, a (row, col) tuple.
--- - severity_sort: (default false) Sort diagnostics by severity. Overrides the setting
--- from |vim.diagnostic.config()|.
--- - severity: See |diagnostic-severity|. Overrides the setting from
--- |vim.diagnostic.config()|.
--- - severity: See |diagnostic-severity|. Overrides the setting
--- from |vim.diagnostic.config()|.
--- - header: (string or table) String to use as the header for the floating window. If a
--- table, it is interpreted as a [text, hl_group] tuple. Overrides the setting
--- from |vim.diagnostic.config()|.
--- - source: (boolean or string) Include the diagnostic source in the message.
--- Use "if_many" to only show sources if there is more than one source of
--- diagnostics in the buffer. Otherwise, any truthy value means to always show
--- the diagnostic source. Overrides the setting from
--- |vim.diagnostic.config()|.
--- the diagnostic source. Overrides the setting from |vim.diagnostic.config()|.
--- - format: (function) A function that takes a diagnostic as input and returns a
--- string. The return value is the text used to display the diagnostic.
--- Overrides the setting from |vim.diagnostic.config()|.
@ -1692,8 +1691,7 @@ end
--- Convert a list of quickfix items to a list of diagnostics.
---
---@param list table A list of quickfix items from |getqflist()| or
--- |getloclist()|.
---@param list table[] List of quickfix items from |getqflist()| or |getloclist()|.
---@return Diagnostic[] array of |diagnostic-structure|
function M.fromqflist(list)
vim.validate({