aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/shared.lua
diff options
context:
space:
mode:
authorNAKAI Tsuyoshi <82267684+uga-rosa@users.noreply.github.com>2022-10-24 21:53:53 +0900
committerGitHub <noreply@github.com>2022-10-24 05:53:53 -0700
commit4573cfa3adac3a7dbf1b6b032471a1c14adc7427 (patch)
treed898200b26b654a1fe19b3f09541b9d4a1217283 /runtime/lua/vim/shared.lua
parent1248c12666dc4d8fb801c2a8dbc355027f8f9bbe (diff)
downloadrneovim-4573cfa3adac3a7dbf1b6b032471a1c14adc7427.tar.gz
rneovim-4573cfa3adac3a7dbf1b6b032471a1c14adc7427.tar.bz2
rneovim-4573cfa3adac3a7dbf1b6b032471a1c14adc7427.zip
fix(lua): pesc, tbl_islist result types #20751
Problem: - pesc() returns multiple results, it should return a single result. - tbl_islist() returns non-boolean in some branches. - Docstring: @generic must be declared first Solution: Constrain docstring annotations. Fix return types. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r--runtime/lua/vim/shared.lua16
1 files changed, 7 insertions, 9 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index f03d608e56..f980547ae4 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -62,7 +62,7 @@ end)()
---
---@param s string String to split
---@param sep string Separator or pattern
----@param plain boolean If `true` use `sep` literally (passed to string.find)
+---@param plain (boolean|nil) If `true` use `sep` literally (passed to string.find)
---@return fun():string (function) Iterator over the split components
function vim.gsplit(s, sep, plain)
vim.validate({ s = { s, 's' }, sep = { sep, 's' }, plain = { plain, 'b', true } })
@@ -108,11 +108,9 @@ end
---
---@see |vim.gsplit()|
---
----@alias split_kwargs {plain: boolean, trimempty: boolean} | boolean | nil
----
---@param s string String to split
---@param sep string Separator or pattern
----@param kwargs? {plain: boolean, trimempty: boolean} (table|nil) Keyword arguments:
+---@param kwargs ({plain: boolean, trimempty: boolean}|nil) Keyword arguments:
--- - plain: (boolean) If `true` use `sep` literally (passed to string.find)
--- - trimempty: (boolean) If `true` remove empty items from the front
--- and back of the list
@@ -159,8 +157,8 @@ end
---
---@see From https://github.com/premake/premake-core/blob/master/src/base/table.lua
---
----@param t table<T, any> (table) Table
---@generic T: table
+---@param t table<T, any> (table) Table
---@return T[] (list) List of keys
function vim.tbl_keys(t)
assert(type(t) == 'table', string.format('Expected table, got %s', type(t)))
@@ -417,8 +415,8 @@ end
---@generic T: table
---@param dst T List which will be modified and appended to
---@param src table List from which values will be inserted
----@param start? number Start index on src. Defaults to 1
----@param finish? number Final index on src. Defaults to `#src`
+---@param start (number|nil) Start index on src. Defaults to 1
+---@param finish (number|nil) Final index on src. Defaults to `#src`
---@return T dst
function vim.list_extend(dst, src, start, finish)
vim.validate({
@@ -486,7 +484,7 @@ function vim.tbl_islist(t)
-- TODO(bfredl): in the future, we will always be inside nvim
-- then this check can be deleted.
if vim._empty_dict_mt == nil then
- return nil
+ return false
end
return getmetatable(t) ~= vim._empty_dict_mt
end
@@ -544,7 +542,7 @@ end
---@return string %-escaped pattern string
function vim.pesc(s)
vim.validate({ s = { s, 's' } })
- return s:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', '%%%1')
+ return (s:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', '%%%1'))
end
--- Tests if `s` starts with `prefix`.