feat(utils): add type annotations and inline documentation to various utility modules

This commit is contained in:
2024-08-31 03:02:33 -04:00
parent 5ef3bc7445
commit a23fc9c643
9 changed files with 173 additions and 42 deletions
+18 -4
View File
@@ -1,5 +1,10 @@
---@module "utils.indentor"
--- This module provides functions to insert indentation at the start of a line.
local M = {}
--- Get the indentation level from the previous line
---@return integer level The indentation level
local function get_previous_line_indentation()
-- Get the current cursor position
local current_line, _ = unpack(vim.api.nvim_win_get_cursor(0))
@@ -20,6 +25,8 @@ local function get_previous_line_indentation()
return #indentation
end
--- Insert the previous line's indentation at the start of the current line
---@return boolean inserted true if the indentation was inserted, false otherwise
function M.insert_previous_line_indentation()
-- Get the cursor column position
local _, col = unpack(vim.api.nvim_win_get_cursor(0))
@@ -31,6 +38,7 @@ function M.insert_previous_line_indentation()
-- Insert the same number of spaces at the start of the current line
vim.api.nvim_put({ string.rep(" ", indentation_level) }, "c", true, true)
return true
else
-- Insert a tab (or spaces if 'expandtab' is set)
vim.api.nvim_feedkeys(
@@ -38,13 +46,19 @@ function M.insert_previous_line_indentation()
"n",
true
)
return false
end
end
-- Create a keymap to trigger the function
local data = require("data")
for _, map in ipairs(data.keys.indentor) do
data.func.add_keymap(map[1], map[2], map[3], map[4])
--- Create keymaps for the module
---@return nil
function M.setup()
-- Load the data module
local data = require("data")
-- Create keymaps
for _, map in ipairs(data.keys.indentor) do
data.func.add_keymap(map[1], map[2], map[3], map[4])
end
end
return M