mirror of
https://github.com/neovim/neovim.git
synced 2026-03-29 20:02:03 +00:00
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:
@@ -56,7 +56,10 @@ local function get_content_length(header)
|
||||
elseif state == 'value' then
|
||||
if c == 13 and header:byte(i + 1) == 10 then -- must end with \r\n
|
||||
local value = buf:get()
|
||||
return assert(digit and tonumber(value), 'value of Content-Length is not number: ' .. value)
|
||||
if digit then
|
||||
return vim._ensure_integer(value)
|
||||
end
|
||||
error('value of Content-Length is not number: ' .. value)
|
||||
else
|
||||
buf:put(string.char(c))
|
||||
end
|
||||
@@ -429,7 +432,7 @@ function Client:handle_body(body)
|
||||
)
|
||||
then
|
||||
-- We sent a number, so we expect a number.
|
||||
local result_id = assert(tonumber(decoded.id), 'response id must be a number') --[[@as integer]]
|
||||
local result_id = vim._ensure_integer(decoded.id)
|
||||
|
||||
-- Notify the user that a response was received for the request
|
||||
local notify_reply_callback = self.notify_reply_callbacks[result_id]
|
||||
|
||||
Reference in New Issue
Block a user