Merge pull request #20496 from ehllie/runtime_annotations

docs(docstrings): fix runtime type annotations
This commit is contained in:
bfredl 2022-10-05 20:21:30 +02:00 committed by GitHub
commit ede85dda2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 31 deletions

View File

@ -1416,11 +1416,11 @@ defer_fn({fn}, {timeout}) *vim.defer_fn()*
are safe to call. are safe to call.
Parameters: ~ Parameters: ~
• {fn} Callback to call once `timeout` expires • {fn} (function) Callback to call once `timeout` expires
• {timeout} Number of milliseconds to wait before calling `fn` • {timeout} integer Number of milliseconds to wait before calling `fn`
Return: ~ Return: ~
timer luv timer object (table) timer luv timer object
*vim.deprecate()* *vim.deprecate()*
deprecate({name}, {alternative}, {version}, {plugin}, {backtrace}) deprecate({name}, {alternative}, {version}, {plugin}, {backtrace})
@ -1514,18 +1514,19 @@ paste({lines}, {phase}) *vim.paste()*
< <
Parameters: ~ Parameters: ~
• {lines} |readfile()|-style list of lines to paste. |channel-lines| • {lines} string[] # |readfile()|-style list of lines to paste.
• {phase} -1: "non-streaming" paste: the call contains all lines. If |channel-lines|
paste is "streamed", `phase` indicates the stream state: • {phase} paste_phase -1: "non-streaming" paste: the call contains all
lines. If paste is "streamed", `phase` indicates the stream state:
• 1: starts the paste (exactly once) • 1: starts the paste (exactly once)
• 2: continues the paste (zero or more times) • 2: continues the paste (zero or more times)
• 3: ends the paste (exactly once) • 3: ends the paste (exactly once)
Return: ~ Return: ~
false if client should cancel the paste. (boolean) # false if client should cancel the paste.
See also: ~ See also: ~
|paste| |paste| @alias paste_phase -1 | 1 | 2 | 3
pretty_print({...}) *vim.pretty_print()* pretty_print({...}) *vim.pretty_print()*
Prints given arguments in human-readable format. Example: > Prints given arguments in human-readable format. Example: >
@ -1534,7 +1535,7 @@ pretty_print({...}) *vim.pretty_print()*
< <
Return: ~ Return: ~
given arguments. any # given arguments.
See also: ~ See also: ~
|vim.inspect()| |vim.inspect()|
@ -1545,18 +1546,26 @@ region({bufnr}, {pos1}, {pos2}, {regtype}, {inclusive}) *vim.region()*
Parameters: ~ Parameters: ~
• {bufnr} (number) of buffer • {bufnr} (number) of buffer
• {pos1} (line, column) tuple marking beginning of region • {pos1} integer[] (line, column) tuple marking beginning of
• {pos2} (line, column) tuple marking end of region region
• {regtype} type of selection, see |setreg()| • {pos2} integer[] (line, column) tuple marking end of region
• {regtype} (string) type of selection, see |setreg()|
• {inclusive} (boolean) indicating whether the selection is • {inclusive} (boolean) indicating whether the selection is
end-inclusive end-inclusive
Return: ~ Return: ~
region lua table of the form {linenr = {startcol,endcol}} table<integer, {}> region lua table of the form {linenr =
{startcol,endcol}}
schedule_wrap({cb}) *vim.schedule_wrap()* schedule_wrap({cb}) *vim.schedule_wrap()*
Defers callback `cb` until the Nvim API is safe to call. Defers callback `cb` until the Nvim API is safe to call.
Parameters: ~
• {cb} (function)
Return: ~
(function)
See also: ~ See also: ~
|lua-loop-callbacks| |lua-loop-callbacks|
|vim.schedule()| |vim.schedule()|
@ -1700,10 +1709,15 @@ split({s}, {sep}, {kwargs}) *vim.split()*
split("|x|y|z|", "|", {trimempty=true}) --> {'x', 'y', 'z'} split("|x|y|z|", "|", {trimempty=true}) --> {'x', 'y', 'z'}
< <
@alias split_kwargs {plain: boolean, trimempty: boolean} | boolean | nil
See also: ~
|vim.gsplit()|
Parameters: ~ Parameters: ~
• {s} (string) String to split • {s} (string) String to split
• {sep} (string) Separator or pattern • {sep} (string) Separator or pattern
• {kwargs} (table) Keyword arguments: • {kwargs} split_kwargs Keyword arguments:
• plain: (boolean) If `true` use `sep` literally (passed to • plain: (boolean) If `true` use `sep` literally (passed to
string.find) string.find)
• trimempty: (boolean) If `true` remove empty items from the • trimempty: (boolean) If `true` remove empty items from the
@ -1712,9 +1726,6 @@ split({s}, {sep}, {kwargs}) *vim.split()*
Return: ~ Return: ~
(table) List of split components (table) List of split components
See also: ~
|vim.gsplit()|
startswith({s}, {prefix}) *vim.startswith()* startswith({s}, {prefix}) *vim.startswith()*
Tests if `s` starts with `prefix`. Tests if `s` starts with `prefix`.

View File

@ -2,8 +2,12 @@ local F = {}
--- Returns {a} if it is not nil, otherwise returns {b}. --- Returns {a} if it is not nil, otherwise returns {b}.
--- ---
---@param a ---@generic A
---@param b ---@generic B
---
---@param a A
---@param b B
---@return A | B
function F.if_nil(a, b) function F.if_nil(a, b)
if a == nil then if a == nil then
return b return b

View File

@ -152,14 +152,15 @@ do
--- </pre> --- </pre>
--- ---
---@see |paste| ---@see |paste|
---@alias paste_phase -1 | 1 | 2 | 3
--- ---
---@param lines |readfile()|-style list of lines to paste. |channel-lines| ---@param lines string[] # |readfile()|-style list of lines to paste. |channel-lines|
---@param phase -1: "non-streaming" paste: the call contains all lines. ---@param phase paste_phase -1: "non-streaming" paste: the call contains all lines.
--- If paste is "streamed", `phase` indicates the stream state: --- If paste is "streamed", `phase` indicates the stream state:
--- - 1: starts the paste (exactly once) --- - 1: starts the paste (exactly once)
--- - 2: continues the paste (zero or more times) --- - 2: continues the paste (zero or more times)
--- - 3: ends the paste (exactly once) --- - 3: ends the paste (exactly once)
---@returns false if client should cancel the paste. ---@returns boolean # false if client should cancel the paste.
function vim.paste(lines, phase) function vim.paste(lines, phase)
local now = vim.loop.now() local now = vim.loop.now()
local is_first_chunk = phase < 2 local is_first_chunk = phase < 2
@ -255,6 +256,8 @@ end
---@see |lua-loop-callbacks| ---@see |lua-loop-callbacks|
---@see |vim.schedule()| ---@see |vim.schedule()|
---@see |vim.in_fast_event()| ---@see |vim.in_fast_event()|
---@param cb function
---@return function
function vim.schedule_wrap(cb) function vim.schedule_wrap(cb)
return function(...) return function(...)
local args = vim.F.pack_len(...) local args = vim.F.pack_len(...)
@ -399,11 +402,11 @@ end
--- Get a table of lines with start, end columns for a region marked by two points --- Get a table of lines with start, end columns for a region marked by two points
--- ---
---@param bufnr number of buffer ---@param bufnr number of buffer
---@param pos1 (line, column) tuple marking beginning of region ---@param pos1 integer[] (line, column) tuple marking beginning of region
---@param pos2 (line, column) tuple marking end of region ---@param pos2 integer[] (line, column) tuple marking end of region
---@param regtype type of selection, see |setreg()| ---@param regtype string type of selection, see |setreg()|
---@param inclusive boolean indicating whether the selection is end-inclusive ---@param inclusive boolean indicating whether the selection is end-inclusive
---@return region lua table of the form {linenr = {startcol,endcol}} ---@return table<integer, {}> region lua table of the form {linenr = {startcol,endcol}}
function vim.region(bufnr, pos1, pos2, regtype, inclusive) function vim.region(bufnr, pos1, pos2, regtype, inclusive)
if not vim.api.nvim_buf_is_loaded(bufnr) then if not vim.api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr) vim.fn.bufload(bufnr)
@ -450,9 +453,9 @@ end
--- Use to do a one-shot timer that calls `fn` --- Use to do a one-shot timer that calls `fn`
--- Note: The {fn} is |vim.schedule_wrap()|ped automatically, so API functions are --- Note: The {fn} is |vim.schedule_wrap()|ped automatically, so API functions are
--- safe to call. --- safe to call.
---@param fn Callback to call once `timeout` expires ---@param fn function Callback to call once `timeout` expires
---@param timeout Number of milliseconds to wait before calling `fn` ---@param timeout integer Number of milliseconds to wait before calling `fn`
---@return timer luv timer object ---@return table timer luv timer object
function vim.defer_fn(fn, timeout) function vim.defer_fn(fn, timeout)
vim.validate({ fn = { fn, 'c', true } }) vim.validate({ fn = { fn, 'c', true } })
local timer = vim.loop.new_timer() local timer = vim.loop.new_timer()
@ -758,7 +761,7 @@ end
--- local hl_normal = vim.pretty_print(vim.api.nvim_get_hl_by_name("Normal", true)) --- local hl_normal = vim.pretty_print(vim.api.nvim_get_hl_by_name("Normal", true))
---</pre> ---</pre>
---@see |vim.inspect()| ---@see |vim.inspect()|
---@return given arguments. ---@return any # given arguments.
function vim.pretty_print(...) function vim.pretty_print(...)
local objects = {} local objects = {}
for i = 1, select('#', ...) do for i = 1, select('#', ...) do

View File

@ -107,9 +107,11 @@ end
--- ---
---@see |vim.gsplit()| ---@see |vim.gsplit()|
--- ---
---@alias split_kwargs {plain: boolean, trimempty: boolean} | boolean | nil
---
---@param s string String to split ---@param s string String to split
---@param sep string Separator or pattern ---@param sep string Separator or pattern
---@param kwargs table Keyword arguments: ---@param kwargs split_kwargs Keyword arguments:
--- - plain: (boolean) If `true` use `sep` literally (passed to string.find) --- - plain: (boolean) If `true` use `sep` literally (passed to string.find)
--- - trimempty: (boolean) If `true` remove empty items from the front --- - trimempty: (boolean) If `true` remove empty items from the front
--- and back of the list --- and back of the list