refactor(lua): type annotations

This commit is contained in:
Lewis Russell
2024-03-16 17:11:42 +00:00
committed by Lewis Russell
parent 924a7ef8bb
commit 14e4b6bbd8
11 changed files with 157 additions and 122 deletions

View File

@@ -254,9 +254,10 @@ local function display_choices(tabstop)
assert(tabstop.choices, 'Tabstop has no choices')
local start_col = tabstop:get_range()[2] + 1
local matches = vim.iter.map(function(choice)
return { word = choice }
end, tabstop.choices)
local matches = {} --- @type table[]
for _, choice in ipairs(tabstop.choices) do
matches[#matches + 1] = { word = choice }
end
vim.defer_fn(function()
vim.fn.complete(start_col, matches)
@@ -449,7 +450,9 @@ function M.expand(input)
local shiftwidth = vim.fn.shiftwidth()
local curbuf = vim.api.nvim_get_current_buf()
local expandtab = vim.bo[curbuf].expandtab
local lines = vim.iter.map(function(i, line)
local lines = {} --- @type string[]
for i, line in ipairs(text_to_lines(text)) do
-- Replace tabs by spaces.
if expandtab then
line = line:gsub('\t', (' '):rep(shiftwidth)) --- @type string
@@ -459,8 +462,8 @@ function M.expand(input)
line = #line ~= 0 and base_indent .. line
or (expandtab and (' '):rep(shiftwidth) or '\t'):rep(vim.fn.indent('.') / shiftwidth + 1)
end
return line
end, ipairs(text_to_lines(text)))
lines[#lines + 1] = line
end
table.insert(snippet_text, table.concat(lines, '\n'))
end