Skip to content

Commit

Permalink
fix: use vim.F.unpack_len and vim.F.pack_len. Fixes a number of issue…
Browse files Browse the repository at this point in the history
…s...
  • Loading branch information
folke committed Oct 27, 2022
1 parent 8cd47e0 commit 51c2179
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lua/noice/source/lsp/progress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function M.setup()
})
local orig = vim.lsp.handlers["$/progress"]
vim.lsp.handlers["$/progress"] = function(...)
local args = { ... }
local args = vim.F.pack_len(...)
Util.try(function()
M.progress(unpack(args))
M.progress(vim.F.unpack_len(args))
end)
orig(...)
end
Expand Down
9 changes: 3 additions & 6 deletions lua/noice/source/lsp/signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,14 @@ function M.check(buf, chars, encoding)

if vim.tbl_contains(chars, M.get_char(buf)) then
local params = vim.lsp.util.make_position_params(0, encoding)
vim.lsp.buf_request(
buf,
"textDocument/signatureHelp",
params,
vim.lsp.with(require("noice.source.lsp").signature, {
vim.lsp.buf_request(buf, "textDocument/signatureHelp", params, function(err, result, ctx)
require("noice.source.lsp").signature(err, result, ctx, {
trigger = true,
stay = function()
return vim.tbl_contains(chars, M.get_char(buf))
end,
})
)
end)
end
end)
end
Expand Down
6 changes: 3 additions & 3 deletions lua/noice/util/call.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ function M:notify(err)
end

function M:__call(...)
local args = { ... }
local args = vim.F.pack_len(...)

-- wrap the function and call with args
local wrapped = function()
return self._fn(unpack(args))
return self._fn(vim.F.unpack_len(args))
end

-- error handler
Expand All @@ -154,7 +154,7 @@ function M:__call(...)

if not ok and self._defer_retry then
vim.defer_fn(function()
self(unpack(args))
self(vim.F.unpack_len(args))
end, 100)
end

Expand Down
7 changes: 3 additions & 4 deletions lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ M.before_input = false
function M.fix_input()
local function wrap(fn, skip)
return function(...)
local args = { ... }
if skip and skip(unpack(args)) then
return fn(unpack(args))
if skip and skip(...) then
return fn(...)
end

local Manager = require("noice.message.manager")
Expand All @@ -155,7 +154,7 @@ function M.fix_input()

M.hide_cursor()
---@type boolean, any
local ok, ret = pcall(fn, unpack(args))
local ok, ret = pcall(fn, ...)
M.show_cursor()

-- clear any message right after input
Expand Down
8 changes: 4 additions & 4 deletions lua/noice/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ end
function M.debounce(ms, fn)
local timer = vim.loop.new_timer()
return function(...)
local argv = { ... }
local argv = vim.F.pack_len(...)
timer:start(ms, 0, function()
timer:stop()
vim.schedule_wrap(fn)(unpack(argv))
vim.schedule_wrap(fn)(vim.F.unpack_len(argv))
end)
end
end
Expand All @@ -84,11 +84,11 @@ function M.interval(ms, fn, opts)
local timer = vim.loop.new_timer()
local running = false
return function(...)
local args = { ... }
local args = vim.F.pack_len(...)
if not running then
running = true
timer:start(ms, ms, function()
fn(unpack(args))
fn(vim.F.unpack_len(args))
if not (opts.enabled and opts.enabled()) then
timer:stop()
running = false
Expand Down

0 comments on commit 51c2179

Please sign in to comment.