Skip to content

Commit

Permalink
feat: add types
Browse files Browse the repository at this point in the history
  • Loading branch information
NStefan002 committed Jan 18, 2025
1 parent 41cdf96 commit 30b48da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lua/visual-surround/config.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
local M = {}

---@type visual-surround.config.full
M.defaults = {
-- if set to true, the user must manually add keymaps
use_default_keymaps = true,
-- will be ignored if use_default_keymaps is set to false
surround_chars = { "{", "}", "[", "]", "(", ")", "'", '"', "`" },
-- whether to exit visual mode after adding surround
exit_visual_mode = true,
}

---@type visual-surround.config.full
M.opts = M.defaults

---@param opts? table
---@param opts? visual-surround.config
function M.setup(opts)
opts = opts or {}
M.opts = vim.tbl_deep_extend("force", M.defaults, opts)
Expand Down
2 changes: 1 addition & 1 deletion lua/visual-surround/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function M.surround(char)
end
end

---@param opts? table
---@param opts? visual-surround.config
function M.setup(opts)
config.setup(opts)
if config.opts.use_default_keymaps then
Expand Down
12 changes: 12 additions & 0 deletions lua/visual-surround/types.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---@class (strict) visual-surround.config.full
---@field use_default_keymaps boolean if set to false, the user must manually add keymaps
---@field surround_chars string[] will be ignored if use_default_keymaps is set to false
---@field exit_visual_mode boolean whether to exit visual mode after adding surround

---@class (strict) visual-surround.config : visual-surround.config.full, {}

---@class visual-surround.bounds
---@field vline_start integer
---@field vcol_start integer
---@field vline_end integer
---@field vcol_end integer
2 changes: 1 addition & 1 deletion lua/visual-surround/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function M.get_char_pair(char)
end

---@param mode string
---@return { vline_start: integer, vcol_start: integer, vline_end: integer, vcol_end: integer }
---@return visual-surround.bounds
function M.get_bounds(mode)
local vline_start = vim.fn.line("v")
local vcol_start = vim.fn.col("v")
Expand Down

0 comments on commit 30b48da

Please sign in to comment.