refactor: integer functions, optimize asserts #34112

refactor(lua): add integer coercion helpers

Add vim._tointeger() and vim._ensure_integer(), including optional base
support, and switch integer-only tonumber()/assert call sites in the Lua
runtime to use them.

This also cleans up related integer parsing in LSP, health, loader, URI,
tohtml, and Treesitter code.

supported by AI
This commit is contained in:
Lewis Russell
2026-03-12 15:04:05 +00:00
committed by GitHub
parent 2fe07cc965
commit ce1154048b
30 changed files with 144 additions and 95 deletions

View File

@@ -130,7 +130,7 @@ function properties.indent_size(bufnr, val, opts)
vim.bo[bufnr].shiftwidth = 0
vim.bo[bufnr].softtabstop = 0
else
local n = assert(tonumber(val), 'indent_size must be a number')
local n = assert(vim._tointeger(val), 'indent_size must be an integer')
vim.bo[bufnr].shiftwidth = n
vim.bo[bufnr].softtabstop = -1
if not opts.tab_width then
@@ -141,17 +141,17 @@ end
--- The display size of a single tab character. Sets the 'tabstop' option.
function properties.tab_width(bufnr, val)
vim.bo[bufnr].tabstop = assert(tonumber(val), 'tab_width must be a number')
vim.bo[bufnr].tabstop = assert(vim._tointeger(val), 'tab_width must be an integer')
end
--- A number indicating the maximum length of a single
--- line. Sets the 'textwidth' option.
function properties.max_line_length(bufnr, val)
local n = tonumber(val)
local n = vim._tointeger(val)
if n then
vim.bo[bufnr].textwidth = n
else
assert(val == 'off', 'max_line_length must be a number or "off"')
assert(val == 'off', 'max_line_length must be an integer or "off"')
vim.bo[bufnr].textwidth = 0
end
end