Skip to content

Commit

Permalink
update type hint for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhao committed Aug 5, 2024
1 parent acc3ed7 commit b728b39
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ function M.executable(name)
end

--- check whether a feature exists in Nvim
--- @feat: string
--- the feature name, like `nvim-0.7` or `unix`.
--- return: bool
--- @param feat string the feature name, like `nvim-0.7` or `unix`.
--- @return boolean
M.has = function(feat)
if fn.has(feat) == 1 then
return true
Expand All @@ -33,8 +32,9 @@ end

--- Generate random integers in the range [Low, High], inclusive,
--- adapted from https://stackoverflow.com/a/12739441/6064933
--- @low: the lower value for this range
--- @high: the upper value for this range
--- @param low integer the lower value for this range
--- @param high integer the upper value for this range
--- @return integer
function M.rand_int(low, high)
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
math.randomseed(os.time())
Expand All @@ -43,17 +43,11 @@ function M.rand_int(low, high)
end

--- Select a random element from a sequence/list.
--- @seq: the sequence to choose an element
--- @param seq any[] the sequence to choose an element
function M.rand_element(seq)
local idx = M.rand_int(1, #seq)

return seq[idx]
end

function M.add_pack(name)
local status, error = pcall(vim.cmd, "packadd " .. name)

return status
end

return M

0 comments on commit b728b39

Please sign in to comment.