fix: lua annotations

This commit is contained in:
Lewis Russell 2024-04-26 14:07:47 +01:00 committed by Lewis Russell
parent c5b9fb2f25
commit b8273c9a33
10 changed files with 113 additions and 110 deletions

View File

@ -678,44 +678,47 @@ vim.diff({a}, {b}, {opts}) *vim.diff()*
Parameters: ~ Parameters: ~
• {a} (`string`) First string to compare • {a} (`string`) First string to compare
• {b} (`string`) Second string to compare • {b} (`string`) Second string to compare
• {opts} (`table<string,any>`) Optional parameters: • {opts} (`table`) Optional parameters:
• `on_hunk` (callback): Invoked for each hunk in the diff. • {on_hunk}
Return a negative number to cancel the callback for any (`fun(start_a: integer, count_a: integer, start_b: integer, count_b: integer): integer`)
remaining hunks. Args: Invoked for each hunk in the diff. Return a negative number
• `start_a` (integer): Start line of hunk in {a}. to cancel the callback for any remaining hunks. Arguments:
• `count_a` (integer): Hunk size in {a}. • `start_a` (`integer`): Start line of hunk in {a}.
• `start_b` (integer): Start line of hunk in {b}. • `count_a` (`integer`): Hunk size in {a}.
• `count_b` (integer): Hunk size in {b}. • `start_b` (`integer`): Start line of hunk in {b}.
• `result_type` (string): Form of the returned diff: • `count_b` (`integer`): Hunk size in {b}.
• "unified": (default) String in unified format. • {result_type} (`'unified'|'indices'`, default: `'unified'`)
• "indices": Array of hunk locations. Note: This option is Form of the returned diff:
• `unified`: String in unified format.
• `indices`: Array of hunk locations. Note: This option is
ignored if `on_hunk` is used. ignored if `on_hunk` is used.
• `linematch` (boolean|integer): Run linematch on the {linematch} (`boolean|integer`) Run linematch on the
resulting hunks from xdiff. When integer, only hunks upto resulting hunks from xdiff. When integer, only hunks upto
this size in lines are run through linematch. Requires this size in lines are run through linematch. Requires
`result_type = indices`, ignored otherwise. `result_type = indices`, ignored otherwise.
• `algorithm` (string): Diff algorithm to use. Values: • {algorithm} (`'myers'|'minimal'|'patience'|'histogram'`,
• "myers" the default algorithm default: `'myers'`) Diff algorithm to use. Values:
• "minimal" spend extra time to generate the smallest • `myers`: the default algorithm
• `minimal`: spend extra time to generate the smallest
possible diff possible diff
"patience" patience diff algorithm `patience`: patience diff algorithm
"histogram" histogram diff algorithm `histogram`: histogram diff algorithm
`ctxlen` (integer): Context length {ctxlen} (`integer`) Context length
`interhunkctxlen` (integer): Inter hunk context length {interhunkctxlen} (`integer`) Inter hunk context length
`ignore_whitespace` (boolean): Ignore whitespace {ignore_whitespace} (`boolean`) Ignore whitespace
`ignore_whitespace_change` (boolean): Ignore whitespace {ignore_whitespace_change} (`boolean`) Ignore whitespace
change change
`ignore_whitespace_change_at_eol` (boolean) Ignore {ignore_whitespace_change_at_eol} (`boolean`) Ignore
whitespace change at end-of-line. whitespace change at end-of-line.
`ignore_cr_at_eol` (boolean) Ignore carriage return at {ignore_cr_at_eol} (`boolean`) Ignore carriage return at
end-of-line end-of-line
`ignore_blank_lines` (boolean) Ignore blank lines {ignore_blank_lines} (`boolean`) Ignore blank lines
`indent_heuristic` (boolean): Use the indent heuristic for {indent_heuristic} (`boolean`) Use the indent heuristic for
the internal diff library. the internal diff library.
Return: ~ Return: ~
(`string|table?`) See {opts.result_type}. `nil` if {opts.on_hunk} is (`string|integer[]`) See {opts.result_type}. `nil` if {opts.on_hunk}
given. is given.
============================================================================== ==============================================================================
@ -829,8 +832,8 @@ vim.spell.check({str}) *vim.spell.check()*
• {str} (`string`) • {str} (`string`)
Return: ~ Return: ~
(`{[1]: string, [2]: string, [3]: string}[]`) List of tuples with (`{[1]: string, [2]: 'bad'|'rare'|'local'|'caps', [3]: integer}[]`)
three items: List of tuples with three items:
• The badly spelled word. • The badly spelled word.
• The type of the spelling error: "bad" spelling mistake "rare" rare • The type of the spelling error: "bad" spelling mistake "rare" rare
word "local" word only valid in another region "caps" word should word "local" word only valid in another region "caps" word should
@ -911,7 +914,7 @@ vim.empty_dict() *vim.empty_dict()*
Return: ~ Return: ~
(`table`) (`table`)
vim.iconv({str}, {from}, {to}, {opts}) *vim.iconv()* vim.iconv({str}, {from}, {to}) *vim.iconv()*
The result is a String, which is the text {str} converted from encoding The result is a String, which is the text {str} converted from encoding
{from} to encoding {to}. When the conversion fails `nil` is returned. When {from} to encoding {to}. When the conversion fails `nil` is returned. When
some characters could not be converted they are replaced with "?". The some characters could not be converted they are replaced with "?". The
@ -920,9 +923,8 @@ vim.iconv({str}, {from}, {to}, {opts}) *vim.iconv()*
Parameters: ~ Parameters: ~
• {str} (`string`) Text to convert • {str} (`string`) Text to convert
• {from} (`number`) Encoding of {str} • {from} (`string`) Encoding of {str}
• {to} (`number`) Target encoding • {to} (`string`) Target encoding
• {opts} (`table<string,any>?`)
Return: ~ Return: ~
(`string?`) Converted string if conversion succeeds, `nil` otherwise. (`string?`) Converted string if conversion succeeds, `nil` otherwise.
@ -962,7 +964,7 @@ vim.schedule({fn}) *vim.schedule()*
|textlock| or other temporary restrictions. |textlock| or other temporary restrictions.
Parameters: ~ Parameters: ~
• {fn} (`function`) • {fn} (`fun()`)
vim.str_byteindex({str}, {index}, {use_utf16}) *vim.str_byteindex()* vim.str_byteindex({str}, {index}, {use_utf16}) *vim.str_byteindex()*
Convert UTF-32 or UTF-16 {index} to byte index. If {use_utf16} is not Convert UTF-32 or UTF-16 {index} to byte index. If {use_utf16} is not
@ -974,8 +976,8 @@ vim.str_byteindex({str}, {index}, {use_utf16}) *vim.str_byteindex()*
Parameters: ~ Parameters: ~
• {str} (`string`) • {str} (`string`)
• {index} (`number`) • {index} (`integer`)
• {use_utf16} (`any?`) • {use_utf16} (`boolean?`)
vim.str_utf_end({str}, {index}) *vim.str_utf_end()* vim.str_utf_end({str}, {index}) *vim.str_utf_end()*
Gets the distance (in bytes) from the last byte of the codepoint Gets the distance (in bytes) from the last byte of the codepoint
@ -993,10 +995,10 @@ vim.str_utf_end({str}, {index}) *vim.str_utf_end()*
Parameters: ~ Parameters: ~
• {str} (`string`) • {str} (`string`)
• {index} (`number`) • {index} (`integer`)
Return: ~ Return: ~
(`number`) (`integer`)
vim.str_utf_pos({str}) *vim.str_utf_pos()* vim.str_utf_pos({str}) *vim.str_utf_pos()*
Gets a list of the starting byte positions of each UTF-8 codepoint in the Gets a list of the starting byte positions of each UTF-8 codepoint in the
@ -1008,7 +1010,7 @@ vim.str_utf_pos({str}) *vim.str_utf_pos()*
• {str} (`string`) • {str} (`string`)
Return: ~ Return: ~
(`table`) (`integer[]`)
vim.str_utf_start({str}, {index}) *vim.str_utf_start()* vim.str_utf_start({str}, {index}) *vim.str_utf_start()*
Gets the distance (in bytes) from the starting byte of the codepoint Gets the distance (in bytes) from the starting byte of the codepoint
@ -1029,10 +1031,10 @@ vim.str_utf_start({str}, {index}) *vim.str_utf_start()*
Parameters: ~ Parameters: ~
• {str} (`string`) • {str} (`string`)
• {index} (`number`) • {index} (`integer`)
Return: ~ Return: ~
(`number`) (`integer`)
vim.str_utfindex({str}, {index}) *vim.str_utfindex()* vim.str_utfindex({str}, {index}) *vim.str_utfindex()*
Convert byte index to UTF-32 and UTF-16 indices. If {index} is not Convert byte index to UTF-32 and UTF-16 indices. If {index} is not
@ -1045,7 +1047,7 @@ vim.str_utfindex({str}, {index}) *vim.str_utfindex()*
Parameters: ~ Parameters: ~
• {str} (`string`) • {str} (`string`)
• {index} (`number?`) • {index} (`integer?`)
Return (multiple): ~ Return (multiple): ~
(`integer`) UTF-32 index (`integer`) UTF-32 index

View File

@ -731,8 +731,7 @@ get_captures_at_pos({bufnr}, {row}, {col})
• {col} (`integer`) Position column • {col} (`integer`) Position column
Return: ~ Return: ~
(`table[]`) List of captures (`{capture: string, lang: string, metadata: table}[]`)
`{ capture = "name", metadata = { ... } }`
get_node({opts}) *vim.treesitter.get_node()* get_node({opts}) *vim.treesitter.get_node()*
Returns the smallest named node at the given position Returns the smallest named node at the given position

View File

@ -196,6 +196,7 @@ do
group = nvim_terminal_augroup, group = nvim_terminal_augroup,
desc = 'Respond to OSC foreground/background color requests', desc = 'Respond to OSC foreground/background color requests',
callback = function(args) callback = function(args)
--- @type integer
local channel = vim.bo[args.buf].channel local channel = vim.bo[args.buf].channel
if channel == 0 then if channel == 0 then
return return
@ -270,6 +271,7 @@ if tty then
-- Wait until Nvim is finished starting to set the option to ensure the -- Wait until Nvim is finished starting to set the option to ensure the
-- OptionSet event fires. -- OptionSet event fires.
if vim.v.vim_did_enter == 1 then if vim.v.vim_did_enter == 1 then
--- @diagnostic disable-next-line:no-unknown
vim.o[option] = value vim.o[option] = value
else else
vim.api.nvim_create_autocmd('VimEnter', { vim.api.nvim_create_autocmd('VimEnter', {

View File

@ -55,8 +55,8 @@ function vim.inspect_pos(bufnr, row, col, filter)
bufnr = bufnr == 0 and vim.api.nvim_get_current_buf() or bufnr bufnr = bufnr == 0 and vim.api.nvim_get_current_buf() or bufnr
local results = { local results = {
treesitter = {}, treesitter = {}, --- @type table[]
syntax = {}, syntax = {}, --- @type table[]
extmarks = {}, extmarks = {},
semantic_tokens = {}, semantic_tokens = {},
buffer = bufnr, buffer = bufnr,
@ -93,7 +93,7 @@ function vim.inspect_pos(bufnr, row, col, filter)
end end
-- namespace id -> name map -- namespace id -> name map
local nsmap = {} local nsmap = {} --- @type table<integer,string>
for name, id in pairs(vim.api.nvim_get_namespaces()) do for name, id in pairs(vim.api.nvim_get_namespaces()) do
nsmap[id] = name nsmap[id] = name
end end

View File

@ -3,11 +3,11 @@
--- Encode {str} using Base64. --- Encode {str} using Base64.
--- ---
--- @param str string String to encode --- @param str string String to encode
--- @return string Encoded string --- @return string : Encoded string
function vim.base64.encode(str) end function vim.base64.encode(str) end
--- Decode a Base64 encoded string. --- Decode a Base64 encoded string.
--- ---
--- @param str string Base64 encoded string --- @param str string Base64 encoded string
--- @return string Decoded string --- @return string : Decoded string
function vim.base64.decode(str) end function vim.base64.decode(str) end

View File

@ -119,15 +119,15 @@ function vim.stricmp(a, b) end
--- An {index} in the middle of a UTF-16 sequence is rounded upwards to --- An {index} in the middle of a UTF-16 sequence is rounded upwards to
--- the end of that sequence. --- the end of that sequence.
--- @param str string --- @param str string
--- @param index number --- @param index integer
--- @param use_utf16? any --- @param use_utf16? boolean
function vim.str_byteindex(str, index, use_utf16) end function vim.str_byteindex(str, index, use_utf16) end
--- Gets a list of the starting byte positions of each UTF-8 codepoint in the given string. --- Gets a list of the starting byte positions of each UTF-8 codepoint in the given string.
--- ---
--- Embedded NUL bytes are treated as terminating the string. --- Embedded NUL bytes are treated as terminating the string.
--- @param str string --- @param str string
--- @return table --- @return integer[]
function vim.str_utf_pos(str) end function vim.str_utf_pos(str) end
--- Gets the distance (in bytes) from the starting byte of the codepoint (character) that {index} --- Gets the distance (in bytes) from the starting byte of the codepoint (character) that {index}
@ -148,8 +148,8 @@ function vim.str_utf_pos(str) end
--- ``` --- ```
--- ---
--- @param str string --- @param str string
--- @param index number --- @param index integer
--- @return number --- @return integer
function vim.str_utf_start(str, index) end function vim.str_utf_start(str, index) end
--- Gets the distance (in bytes) from the last byte of the codepoint (character) that {index} points --- Gets the distance (in bytes) from the last byte of the codepoint (character) that {index} points
@ -168,8 +168,8 @@ function vim.str_utf_start(str, index) end
--- ``` --- ```
--- ---
--- @param str string --- @param str string
--- @param index number --- @param index integer
--- @return number --- @return integer
function vim.str_utf_end(str, index) end function vim.str_utf_end(str, index) end
--- Convert byte index to UTF-32 and UTF-16 indices. If {index} is not --- Convert byte index to UTF-32 and UTF-16 indices. If {index} is not
@ -180,7 +180,7 @@ function vim.str_utf_end(str, index) end
--- {index} in the middle of a UTF-8 sequence is rounded upwards to the end of --- {index} in the middle of a UTF-8 sequence is rounded upwards to the end of
--- that sequence. --- that sequence.
--- @param str string --- @param str string
--- @param index? number --- @param index? integer
--- @return integer UTF-32 index --- @return integer UTF-32 index
--- @return integer UTF-16 index --- @return integer UTF-16 index
function vim.str_utfindex(str, index) end function vim.str_utfindex(str, index) end
@ -193,15 +193,14 @@ function vim.str_utfindex(str, index) end
--- can accept, see ":Man 3 iconv". --- can accept, see ":Man 3 iconv".
--- ---
--- @param str string Text to convert --- @param str string Text to convert
--- @param from number Encoding of {str} --- @param from string Encoding of {str}
--- @param to number Target encoding --- @param to string Target encoding
--- @param opts? table<string,any> --- @return string? : Converted string if conversion succeeds, `nil` otherwise.
--- @return string|nil Converted string if conversion succeeds, `nil` otherwise.
function vim.iconv(str, from, to, opts) end function vim.iconv(str, from, to, opts) end
--- Schedules {fn} to be invoked soon by the main event-loop. Useful --- Schedules {fn} to be invoked soon by the main event-loop. Useful
--- to avoid |textlock| or other temporary restrictions. --- to avoid |textlock| or other temporary restrictions.
--- @param fn function --- @param fn fun()
function vim.schedule(fn) end function vim.schedule(fn) end
--- Wait for {time} in milliseconds until {callback} returns `true`. --- Wait for {time} in milliseconds until {callback} returns `true`.

View File

@ -1,5 +1,46 @@
---@meta ---@meta
--- Optional parameters:
--- @class vim.diff.Opts
--- @inlinedoc
---
--- Invoked for each hunk in the diff. Return a negative number
--- to cancel the callback for any remaining hunks.
--- Arguments:
--- - `start_a` (`integer`): Start line of hunk in {a}.
--- - `count_a` (`integer`): Hunk size in {a}.
--- - `start_b` (`integer`): Start line of hunk in {b}.
--- - `count_b` (`integer`): Hunk size in {b}.
--- @field on_hunk fun(start_a: integer, count_a: integer, start_b: integer, count_b: integer): integer
---
--- Form of the returned diff:
--- - `unified`: String in unified format.
--- - `indices`: Array of hunk locations.
--- Note: This option is ignored if `on_hunk` is used.
--- (default: `'unified'`)
--- @field result_type 'unified'|'indices'
---
--- Run linematch on the resulting hunks from xdiff. When integer, only hunks
--- upto this size in lines are run through linematch.
--- Requires `result_type = indices`, ignored otherwise.
--- @field linematch boolean|integer
---
--- Diff algorithm to use. Values:
--- - `myers`: the default algorithm
--- - `minimal`: spend extra time to generate the smallest possible diff
--- - `patience`: patience diff algorithm
--- - `histogram`: histogram diff algorithm
--- (default: `'myers'`)
--- @field algorithm 'myers'|'minimal'|'patience'|'histogram'
--- @field ctxlen integer Context length
--- @field interhunkctxlen integer Inter hunk context length
--- @field ignore_whitespace boolean Ignore whitespace
--- @field ignore_whitespace_change boolean Ignore whitespace change
--- @field ignore_whitespace_change_at_eol boolean Ignore whitespace change at end-of-line.
--- @field ignore_cr_at_eol boolean Ignore carriage return at end-of-line
--- @field ignore_blank_lines boolean Ignore blank lines
--- @field indent_heuristic boolean Use the indent heuristic for the internal diff library.
-- luacheck: no unused args -- luacheck: no unused args
--- Run diff on strings {a} and {b}. Any indices returned by this function, --- Run diff on strings {a} and {b}. Any indices returned by this function,
@ -24,47 +65,7 @@
--- ---
---@param a string First string to compare ---@param a string First string to compare
---@param b string Second string to compare ---@param b string Second string to compare
---@param opts table<string,any> Optional parameters: ---@param opts vim.diff.Opts
--- - `on_hunk` (callback): ---@return string|integer[][]?
--- Invoked for each hunk in the diff. Return a negative number
--- to cancel the callback for any remaining hunks.
--- Args:
--- - `start_a` (integer): Start line of hunk in {a}.
--- - `count_a` (integer): Hunk size in {a}.
--- - `start_b` (integer): Start line of hunk in {b}.
--- - `count_b` (integer): Hunk size in {b}.
--- - `result_type` (string): Form of the returned diff:
--- - "unified": (default) String in unified format.
--- - "indices": Array of hunk locations.
--- Note: This option is ignored if `on_hunk` is used.
--- - `linematch` (boolean|integer): Run linematch on the resulting hunks
--- from xdiff. When integer, only hunks upto this size in
--- lines are run through linematch. Requires `result_type = indices`,
--- ignored otherwise.
--- - `algorithm` (string):
--- Diff algorithm to use. Values:
--- - "myers" the default algorithm
--- - "minimal" spend extra time to generate the
--- smallest possible diff
--- - "patience" patience diff algorithm
--- - "histogram" histogram diff algorithm
--- - `ctxlen` (integer): Context length
--- - `interhunkctxlen` (integer):
--- Inter hunk context length
--- - `ignore_whitespace` (boolean):
--- Ignore whitespace
--- - `ignore_whitespace_change` (boolean):
--- Ignore whitespace change
--- - `ignore_whitespace_change_at_eol` (boolean)
--- Ignore whitespace change at end-of-line.
--- - `ignore_cr_at_eol` (boolean)
--- Ignore carriage return at end-of-line
--- - `ignore_blank_lines` (boolean)
--- Ignore blank lines
--- - `indent_heuristic` (boolean):
--- Use the indent heuristic for the internal
--- diff library.
---
---@return string|table|nil
--- See {opts.result_type}. `nil` if {opts.on_hunk} is given. --- See {opts.result_type}. `nil` if {opts.on_hunk} is given.
function vim.diff(a, b, opts) end function vim.diff(a, b, opts) end

View File

@ -30,8 +30,8 @@ function vim.re.compile(string, defs) end
--- @param subject string --- @param subject string
--- @param pattern vim.lpeg.Pattern|string --- @param pattern vim.lpeg.Pattern|string
--- @param init? integer --- @param init? integer
--- @return integer|nil the index where the occurrence starts, nil if no match --- @return integer|nil : the index where the occurrence starts, nil if no match
--- @return integer|nil the index where the occurrence ends, nil if no match --- @return integer|nil : the index where the occurrence ends, nil if no match
function vim.re.find(subject, pattern, init) end function vim.re.find(subject, pattern, init) end
--- Does a global substitution, replacing all occurrences of {pattern} in the given {subject} by --- Does a global substitution, replacing all occurrences of {pattern} in the given {subject} by

View File

@ -3,11 +3,11 @@
-- luacheck: no unused args -- luacheck: no unused args
--- Check {str} for spelling errors. Similar to the Vimscript function --- Check {str} for spelling errors. Similar to the Vimscript function
--- |spellbadword()|. --- [spellbadword()].
--- ---
--- Note: The behaviour of this function is dependent on: 'spelllang', --- Note: The behaviour of this function is dependent on: 'spelllang',
--- 'spellfile', 'spellcapcheck' and 'spelloptions' which can all be local to --- 'spellfile', 'spellcapcheck' and 'spelloptions' which can all be local to
--- the buffer. Consider calling this with |nvim_buf_call()|. --- the buffer. Consider calling this with [nvim_buf_call()].
--- ---
--- Example: --- Example:
--- ---
@ -20,7 +20,7 @@
--- ``` --- ```
--- ---
--- @param str string --- @param str string
--- @return {[1]: string, [2]: string, [3]: string}[] --- @return {[1]: string, [2]: 'bad'|'rare'|'local'|'caps', [3]: integer}[]
--- List of tuples with three items: --- List of tuples with three items:
--- - The badly spelled word. --- - The badly spelled word.
--- - The type of the spelling error: --- - The type of the spelling error:

View File

@ -257,7 +257,7 @@ end
---@param row integer Position row ---@param row integer Position row
---@param col integer Position column ---@param col integer Position column
--- ---
---@return table[] List of captures `{ capture = "name", metadata = { ... } }` ---@return {capture: string, lang: string, metadata: table}[]
function M.get_captures_at_pos(bufnr, row, col) function M.get_captures_at_pos(bufnr, row, col)
if bufnr == 0 then if bufnr == 0 then
bufnr = api.nvim_get_current_buf() bufnr = api.nvim_get_current_buf()