📝 Docs(util-funcs): add missing annotations to utility functions
This commit is contained in:
+37
-17
@@ -118,8 +118,10 @@ function M.is_linux()
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@alias FormatType "verbose"|"short"|"code"|"platform"
|
||||||
|
|
||||||
---@function Get the name of the OS.
|
---@function Get the name of the OS.
|
||||||
---@param format string The format of the OS name.
|
---@param format FormatType The format of the OS name.
|
||||||
--- Possible values:
|
--- Possible values:
|
||||||
--- - "verbose": Returns the full name of the OS.
|
--- - "verbose": Returns the full name of the OS.
|
||||||
--- - "short": Returns a short name or abbreviation.
|
--- - "short": Returns a short name or abbreviation.
|
||||||
@@ -228,6 +230,14 @@ function M.get_os(format)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@func Wraps a value in a table.
|
||||||
|
---@generic T
|
||||||
|
---@param value T The value to wrap.
|
||||||
|
---@return T[] A table containing the value.
|
||||||
|
function M.wrap(value)
|
||||||
|
return { value }
|
||||||
|
end
|
||||||
|
|
||||||
---@function Function to check if CWD is a git repo
|
---@function Function to check if CWD is a git repo
|
||||||
---@param dir? string The directory to check, defaults to CWD
|
---@param dir? string The directory to check, defaults to CWD
|
||||||
---@return boolean is_git_repo true if working directory is a git repository, false otherwise
|
---@return boolean is_git_repo true if working directory is a git repository, false otherwise
|
||||||
@@ -1742,7 +1752,7 @@ function M.pick(cmd, provider, options)
|
|||||||
elseif vim.g.lazyvim_picker == 'snacks' then
|
elseif vim.g.lazyvim_picker == 'snacks' then
|
||||||
provider = 'snacks'
|
provider = 'snacks'
|
||||||
elseif vim.g.lazyvim_picker == 'auto' then
|
elseif vim.g.lazyvim_picker == 'auto' then
|
||||||
provider = LazyVim.pick.want()
|
provider = LazyVim.pick.picker.name
|
||||||
else
|
else
|
||||||
local has_fzf, _ = pcall(require, 'fzf-lua')
|
local has_fzf, _ = pcall(require, 'fzf-lua')
|
||||||
if has_fzf then
|
if has_fzf then
|
||||||
@@ -1854,12 +1864,19 @@ function M.convert_path(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@func Gets the character in a given position
|
||||||
|
---@param pos table The position to retrieve the character from
|
||||||
|
---@return string char The character found at the position
|
||||||
function M.char_on_pos(pos)
|
function M.char_on_pos(pos)
|
||||||
pos = pos or vim.fn.getpos('.')
|
pos = pos or vim.fn.getpos('.')
|
||||||
return tostring(vim.fn.getline(pos[1])):sub(pos[2], pos[2])
|
return tostring(vim.fn.getline(pos[1])):sub(pos[2], pos[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- From: https://neovim.discourse.group/t/how-do-you-work-with-strings-with-multibyte-characters-in-lua/2437/4
|
---@func Gets the character byte count of a given character
|
||||||
|
--- From: https://neovim.discourse.group/t/how-do-you-work-with-strings-with-multibyte-characters-in-lua/2437/4
|
||||||
|
---@param s string The character
|
||||||
|
---@param i integer? The number of characters when using a multibyte character
|
||||||
|
---@return integer? count The number of bytes in the character
|
||||||
function M.char_byte_count(s, i)
|
function M.char_byte_count(s, i)
|
||||||
if not s or s == '' then
|
if not s or s == '' then
|
||||||
return 1
|
return 1
|
||||||
@@ -1879,6 +1896,8 @@ function M.char_byte_count(s, i)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@func Gets the range of a visual selection
|
||||||
|
---@return table range The range of the selection
|
||||||
function M.get_visual_range()
|
function M.get_visual_range()
|
||||||
local sr, sc = unpack(vim.fn.getpos('v'), 2, 3)
|
local sr, sc = unpack(vim.fn.getpos('v'), 2, 3)
|
||||||
local er, ec = unpack(vim.fn.getpos('.'), 2, 3)
|
local er, ec = unpack(vim.fn.getpos('.'), 2, 3)
|
||||||
@@ -1901,11 +1920,8 @@ function M.get_visual_range()
|
|||||||
return range
|
return range
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.to_api_range(range)
|
---@func Generates a basic numberline
|
||||||
local sr, sc, er, ec = unpack(range)
|
---@return string numln Numberline string
|
||||||
return sr - 1, sc, er - 1, ec
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.number()
|
function M.number()
|
||||||
local nu = vim.opt.number:get()
|
local nu = vim.opt.number:get()
|
||||||
local rnu = vim.opt.relativenumber:get()
|
local rnu = vim.opt.relativenumber:get()
|
||||||
@@ -1951,7 +1967,7 @@ function M.number()
|
|||||||
return '%s' .. v_hl .. line_display
|
return '%s' .. v_hl .. line_display
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Function to search for the provided filetypes with pickers
|
---@func Function to search for the provided filetypes with pickers
|
||||||
---@param filetypes table A list of filetypes to search for
|
---@param filetypes table A list of filetypes to search for
|
||||||
function M.pick_filetypes(filetypes)
|
function M.pick_filetypes(filetypes)
|
||||||
if not pcall(require, 'telescope') then
|
if not pcall(require, 'telescope') then
|
||||||
@@ -2178,6 +2194,7 @@ local function base64_encode(input)
|
|||||||
return table.concat(output):sub(1, -1 - #padding) .. padding
|
return table.concat(output):sub(1, -1 - #padding) .. padding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Function to encode visual selection with base64 encoding
|
||||||
function M.base64_encode_visual()
|
function M.base64_encode_visual()
|
||||||
local Range = require('u.range')
|
local Range = require('u.range')
|
||||||
local range = Range.from_vtext()
|
local range = Range.from_vtext()
|
||||||
@@ -2188,7 +2205,7 @@ function M.base64_encode_visual()
|
|||||||
range:replace(encoded_text)
|
range:replace(encoded_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to encode the current line
|
-- Function to encode the current line with base64 encoding
|
||||||
function M.base64_encode_text()
|
function M.base64_encode_text()
|
||||||
-- Get the current line where the cursor is
|
-- Get the current line where the cursor is
|
||||||
local current_line = vim.api.nvim_get_current_line()
|
local current_line = vim.api.nvim_get_current_line()
|
||||||
@@ -2200,7 +2217,9 @@ function M.base64_encode_text()
|
|||||||
vim.api.nvim_set_current_line(encoded_line)
|
vim.api.nvim_set_current_line(encoded_line)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to base64 decode a string
|
---@func Function to base64 decode a string
|
||||||
|
---@param input string The string to be decoded
|
||||||
|
---@return string output The decoded string
|
||||||
local function base64_decode(input)
|
local function base64_decode(input)
|
||||||
local b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
local b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||||
local output = {}
|
local output = {}
|
||||||
@@ -2304,9 +2323,9 @@ function M.rot47_visual()
|
|||||||
range:replace(transformed_text)
|
range:replace(transformed_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Converts a given string into its hexadecimal representation while preserving newlines.
|
---@func Converts a given string into its hexadecimal representation while preserving newlines.
|
||||||
-- @param input_string The string to be transformed into hexadecimal.
|
---@param input_string string The string to be transformed into hexadecimal.
|
||||||
-- @return The hexadecimal encoded string, preserving the original structure.
|
---@return string output_string The hexadecimal encoded string, preserving the original structure.
|
||||||
local function hex_encode(input_string)
|
local function hex_encode(input_string)
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
@@ -2328,8 +2347,8 @@ local function hex_encode(input_string)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Decodes a given hexadecimal encoded string back to its original form while preserving newlines.
|
--- Decodes a given hexadecimal encoded string back to its original form while preserving newlines.
|
||||||
-- @param hex_string The hexadecimal encoded string to be decoded.
|
---@param hex_string string The hexadecimal encoded string to be decoded.
|
||||||
-- @return The decoded string, preserving the original structure.
|
---@return string decoded_text The decoded string, preserving the original structure.
|
||||||
local function hex_decode(hex_string)
|
local function hex_decode(hex_string)
|
||||||
local result = {}
|
local result = {}
|
||||||
local i = 1
|
local i = 1
|
||||||
@@ -2468,7 +2487,8 @@ function M.help_lookup_quoted_visual()
|
|||||||
M.help_lookup_string(M.wrap_in_quotes(selected_text))
|
M.help_lookup_string(M.wrap_in_quotes(selected_text))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to get the system architecture
|
---@func Function to get the system architecture
|
||||||
|
---@return string arch The architecture
|
||||||
function M.get_system_arch()
|
function M.get_system_arch()
|
||||||
-- Use jit.arch if available
|
-- Use jit.arch if available
|
||||||
if jit and jit.arch then
|
if jit and jit.arch then
|
||||||
|
|||||||
Reference in New Issue
Block a user