Cleanup, bugfixes

main
Bryan 2024-12-23 16:35:58 -06:00
parent 3a2a09ea38
commit c39b1a5e4e
2 changed files with 23 additions and 28 deletions

View File

@ -181,7 +181,8 @@ local _make_floating_popup_size = function(contents, opts)
return width, height
end
---@param content table window content
---@param sig_content table|nil signature window content
---@param doc_content table|nil documentation window content
---@param opts table window options
---@returns (table) Options
local function _make_floating_popup_options(sig_content, doc_content, opts)
@ -325,7 +326,9 @@ local function create_float_windows(result, syntax, opts)
local sig_content = make_signature_lines(result, opts.max_width)
local doc_content = make_doc_lines(result, syntax)
---@diagnostic disable-next-line: param-type-mismatch
api.nvim_buf_set_lines(sig_bufnr, 0, -1, true, sig_content)
---@diagnostic disable-next-line: param-type-mismatch
api.nvim_buf_set_lines(doc_bufnr, 0, -1, true, doc_content)
local sig_float_options, doc_float_options = _make_floating_popup_options(sig_content, doc_content, opts)
@ -333,6 +336,7 @@ local function create_float_windows(result, syntax, opts)
local sig_winnr = api.nvim_open_win(sig_bufnr, false, sig_float_options)
vim.wo[sig_winnr].conceallevel = 2
vim.wo[sig_winnr].foldenable = false
vim.wo[sig_winnr].winblend = opts.winblend
vim.bo[sig_bufnr].modifiable = false
vim.bo[sig_bufnr].bufhidden = "hide"
-- save focus_id
@ -342,6 +346,7 @@ local function create_float_windows(result, syntax, opts)
local doc_winnr = api.nvim_open_win(doc_bufnr, false, doc_float_options)
vim.wo[doc_winnr].conceallevel = 2
vim.wo[doc_winnr].foldenable = false
vim.wo[doc_winnr].winblend = opts.winblend
vim.bo[doc_bufnr].modifiable = false
vim.bo[doc_bufnr].bufhidden = "hide"

View File

@ -20,7 +20,6 @@ function SignatureHelp.new()
timer = nil,
current_signatures = nil,
enabled = false,
normal_mode_active = false,
current_signature_idx = nil,
doc_winnr = nil,
@ -28,11 +27,12 @@ function SignatureHelp.new()
doc_win_showing = false,
doc_win_focused = false,
config = nil,
active_winnr = vim.api.nvim_get_current_win(),
}, SignatureHelp)
instance._default_config = {
silent = false,
number = true,
icons = {
parameter = "",
method = "󰡱 ",
@ -53,11 +53,9 @@ function SignatureHelp.new()
border = "rounded",
winblend = 10,
zindex = 200,
focusable = false,
max_height = 20,
max_width = 80,
anchor_bias = "below", -- below|above|auto
relative = "cursor",
offset_y = 0,
offset_x = 0,
},
@ -184,11 +182,10 @@ function SignatureHelp:display_doc_win()
self.doc_bufnr, self.doc_winnr = self._display_doc_win()
self.doc_win_showing = true
self.doc_win_focused = true
local active_winnr = vim.api.nvim_get_current_win()
vim.api.nvim_set_current_win(self.doc_winnr)
exit_docs = function()
vim.api.nvim_set_current_win(active_winnr)
vim.api.nvim_set_current_win(self.active_winnr)
vim.fn.feedkeys("i", "t") --put us back into insert mode
self.doc_win_focused = false
end
@ -267,14 +264,21 @@ function SignatureHelp:setup_autocmds()
api.nvim_create_autocmd({ "InsertEnter", "CursorMovedI" }, {
group = group,
callback = function()
-- local cmp_visible = require("cmp").visible()
-- if cmp_visible then
-- self:hide()
-- elseif vim.fn.pumvisible() == 0 then
debounced_trigger()
-- else
-- self:hide()
-- end
end,
})
-- make sure signature help windows get closed if we switch out of the doc window
-- instead of exiting it using the exit keymaps
api.nvim_create_autocmd({ "WinEnter" }, {
group = group,
callback = function()
vim.defer_fn(function()
if self.active_winnr == vim.api.nvim_get_current_win() and vim.api.nvim_get_mode().mode == "n" then
self:hide_sig_win()
self:hide_doc_win()
end
end, 30)
end,
})
@ -340,7 +344,6 @@ function SignatureHelp:prev_signature()
end
function SignatureHelp:toggle_docs()
-- vim.notify("doc_win_showing: " .. vim.inspect(self.doc_win_showing))
if self.doc_win_showing then
self:hide_doc_win()
elseif self.sig_win_showing then
@ -348,15 +351,6 @@ function SignatureHelp:toggle_docs()
end
end
function SignatureHelp:toggle_normal_mode()
self.normal_mode_active = not self.normal_mode_active
if self.normal_mode_active then
self:trigger()
else
self:hide_sig_win()
end
end
function M.setup(opts)
-- Ensure setup is called only once
if M._initialized then
@ -408,10 +402,6 @@ function M.setup(opts)
signature_help:toggle_docs()
end
M.toggle_normal_mode = function()
signature_help:toggle_normal_mode()
end
return signature_help
end