docs(utils): update format of docs
This commit is contained in:
+24
-8
@@ -3,14 +3,14 @@ local M = {}
|
|||||||
M.os_name = vim.uv.os_uname().sysname
|
M.os_name = vim.uv.os_uname().sysname
|
||||||
|
|
||||||
--- Check that an executable is available
|
--- Check that an executable is available
|
||||||
--- @param exe string: Array to look for
|
--- @param exe string Array to look for
|
||||||
--- @return boolean
|
--- @return boolean
|
||||||
function M.is_installed(exe)
|
function M.is_installed(exe)
|
||||||
return vim.fn.executable(exe) == 1
|
return vim.fn.executable(exe) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check that at least one executable is available
|
--- Check that at least one executable is available
|
||||||
--- @param exes table: Array of exes
|
--- @param exes table Array of exes
|
||||||
--- @return boolean
|
--- @return boolean
|
||||||
function M.any_installed(exes)
|
function M.any_installed(exes)
|
||||||
for _, e in ipairs(exes) do
|
for _, e in ipairs(exes) do
|
||||||
@@ -24,7 +24,7 @@ end
|
|||||||
|
|
||||||
--- Asserts that an executable is available
|
--- Asserts that an executable is available
|
||||||
--- Raises error if missing.
|
--- Raises error if missing.
|
||||||
--- @param exe string: Array to look for
|
--- @param exe string Array to look for
|
||||||
function M.assert_installed(exe)
|
function M.assert_installed(exe)
|
||||||
if not M.is_installed(exe) then
|
if not M.is_installed(exe) then
|
||||||
M.notify("Missing executable '" .. exe .. "'.")
|
M.notify("Missing executable '" .. exe .. "'.")
|
||||||
@@ -33,7 +33,7 @@ end
|
|||||||
|
|
||||||
--- Asserts that at least one executable is available
|
--- Asserts that at least one executable is available
|
||||||
--- Raises error if missing.
|
--- Raises error if missing.
|
||||||
--- @param exes table: Array of exes
|
--- @param exes table Array of exes
|
||||||
function M.assert_any_installed(exes)
|
function M.assert_any_installed(exes)
|
||||||
if not M.any_installed(exes) then
|
if not M.any_installed(exes) then
|
||||||
error("At least one of the following is required:\n" ..
|
error("At least one of the following is required:\n" ..
|
||||||
@@ -42,7 +42,7 @@ function M.assert_any_installed(exes)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Asserts that a python module is installed
|
--- Asserts that a python module is installed
|
||||||
---@param mod string: The python module to check
|
---@param mod string The python module to check
|
||||||
function M.python3_module_is_installed(mod)
|
function M.python3_module_is_installed(mod)
|
||||||
if not M.is_installed("python3") then
|
if not M.is_installed("python3") then
|
||||||
return false
|
return false
|
||||||
@@ -53,13 +53,17 @@ function M.python3_module_is_installed(mod)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Asserts that a python module is installed
|
--- Asserts that a python module is installed
|
||||||
---@param mod string: The python module to check
|
---@param mod string The python module to check
|
||||||
function M.assert_python3_module_installed(mod)
|
function M.assert_python3_module_installed(mod)
|
||||||
if not M.python3_module_is_installed(mod) then
|
if not M.python3_module_is_installed(mod) then
|
||||||
error("Python3 module " .. mod .. " not installed")
|
error("Python3 module " .. mod .. " not installed")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Send a notification
|
||||||
|
---@param msg string Message to send
|
||||||
|
---@param title string Title of notification
|
||||||
|
---@param level integer Log level
|
||||||
function M.notify(msg, title, level)
|
function M.notify(msg, title, level)
|
||||||
if title and not pcall(require, "notify") then
|
if title and not pcall(require, "notify") then
|
||||||
msg = "[" .. title .. "] " .. msg
|
msg = "[" .. title .. "] " .. msg
|
||||||
@@ -67,18 +71,30 @@ function M.notify(msg, title, level)
|
|||||||
vim.notify(msg, level, { title = title, })
|
vim.notify(msg, level, { title = title, })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Send a debug notification
|
||||||
|
---@param msg string Message to send
|
||||||
|
---@param title string Title of notification
|
||||||
function M.debug(msg, title)
|
function M.debug(msg, title)
|
||||||
M.notify(msg, title, vim.log.levels.DEBUG)
|
M.notify(msg, title, vim.log.levels.DEBUG)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Send an info notification
|
||||||
|
---@param msg string Message to send
|
||||||
|
---@param title string Title of notification
|
||||||
function M.info(msg, title)
|
function M.info(msg, title)
|
||||||
M.notify(msg, title, vim.log.levels.INFO)
|
M.notify(msg, title, vim.log.levels.INFO)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Send a warning notification
|
||||||
|
---@param msg string Message to send
|
||||||
|
---@param title string Title of notification
|
||||||
function M.warn(msg, title)
|
function M.warn(msg, title)
|
||||||
M.notify(msg, title, vim.log.levels.WARN)
|
M.notify(msg, title, vim.log.levels.WARN)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Send an error notification
|
||||||
|
---@param msg string Message to send
|
||||||
|
---@param title string Title of notification
|
||||||
function M.err(msg, title)
|
function M.err(msg, title)
|
||||||
M.notify(msg, title, vim.log.levels.ERROR)
|
M.notify(msg, title, vim.log.levels.ERROR)
|
||||||
end
|
end
|
||||||
@@ -104,8 +120,8 @@ function M.try_require(module, err_title, on_success)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Update table t1 with values in t2.
|
--- Update table t1 with values in t2.
|
||||||
--- @param table table: The table to update
|
---@param table table<any, any> The table to update
|
||||||
--- @param values table: The table with new values
|
---@param values table<any, any> The table with new values
|
||||||
function M.update_table(table, values)
|
function M.update_table(table, values)
|
||||||
for k, v in pairs(values) do
|
for k, v in pairs(values) do
|
||||||
if type(v) == "table" and type(table[k] or false) == "table" then
|
if type(v) == "table" and type(table[k] or false) == "table" then
|
||||||
|
|||||||
Reference in New Issue
Block a user