Fix not being buffer scoped. Previously if any LSP attached to any buffer
had SignatureHelp capability then SigHelp would trigger in even buffers with an LSP attached that didn't support SignatureHelp, which would cause an error.main
parent
3c9bd9ba14
commit
889d7273fb
|
|
@ -109,12 +109,11 @@ local function make_signature_lines(signature_help, maxlen)
|
|||
vim.list_extend(lines, vim.split(signature.label, "\n", { plain = true, trimempty = true }))
|
||||
|
||||
local wrapped_lines = {}
|
||||
for _, ll in ipairs(lines) do
|
||||
vim.list_extend(wrapped_lines, _wrap_lines(ll, maxlen))
|
||||
for _, l in ipairs(lines) do
|
||||
vim.list_extend(wrapped_lines, _wrap_lines(l, maxlen))
|
||||
end
|
||||
return wrapped_lines
|
||||
end
|
||||
|
||||
local function make_doc_lines(result, ft)
|
||||
local active_signature = result.activeSignature or 0
|
||||
local signature = result.signatures[active_signature + 1]
|
||||
|
|
@ -319,17 +318,24 @@ local function create_float_windows(result, syntax, opts)
|
|||
syntax = syntax or "text"
|
||||
vim.bo[sig_bufnr].syntax = syntax
|
||||
vim.bo[sig_bufnr].ft = syntax
|
||||
vim.bo[sig_bufnr].bufhidden = "hide"
|
||||
vim.treesitter.start(sig_bufnr)
|
||||
|
||||
vim.bo[doc_bufnr].syntax = "markdown"
|
||||
vim.bo[doc_bufnr].ft = "markdown"
|
||||
vim.bo[doc_bufnr].bufhidden = "hide"
|
||||
vim.treesitter.start(doc_bufnr)
|
||||
|
||||
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)
|
||||
vim.bo[sig_bufnr].modifiable = false
|
||||
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
api.nvim_buf_set_lines(doc_bufnr, 0, -1, true, doc_content)
|
||||
vim.bo[doc_bufnr].modifiable = false
|
||||
|
||||
local sig_float_options, doc_float_options = _make_floating_popup_options(sig_content, doc_content, opts)
|
||||
return function()
|
||||
|
|
@ -337,8 +343,6 @@ local function create_float_windows(result, syntax, opts)
|
|||
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
|
||||
api.nvim_buf_set_var(bufnr, "lsp_sig_win", sig_winnr)
|
||||
return sig_bufnr, sig_winnr, sig_content
|
||||
|
|
@ -347,8 +351,6 @@ local function create_float_windows(result, syntax, opts)
|
|||
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"
|
||||
|
||||
-- save focus_id
|
||||
api.nvim_buf_set_var(doc_bufnr, "lsp_doc_win", doc_winnr)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ function SignatureHelp.new()
|
|||
markid = nil,
|
||||
timer = nil,
|
||||
current_signatures = nil,
|
||||
enabled = false,
|
||||
current_signature_idx = nil,
|
||||
|
||||
doc_winnr = nil,
|
||||
|
|
@ -179,12 +178,18 @@ function SignatureHelp:display_doc_win()
|
|||
if self.doc_win_showing then
|
||||
return
|
||||
else
|
||||
self.active_winnr = vim.api.nvim_get_current_win()
|
||||
self.doc_bufnr, self.doc_winnr = self._display_doc_win()
|
||||
self.doc_win_showing = true
|
||||
self.doc_win_focused = true
|
||||
vim.api.nvim_set_current_win(self.doc_winnr)
|
||||
|
||||
exit_docs = function()
|
||||
-- set window variable that can be checked externally for i.e. setting keymaps
|
||||
local w = vim.w
|
||||
w.sighelp_doc_win = true
|
||||
vim.w = w
|
||||
|
||||
local exit_docs = function()
|
||||
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
|
||||
|
|
@ -208,7 +213,7 @@ function SignatureHelp:display_doc_win()
|
|||
end
|
||||
|
||||
function SignatureHelp:trigger()
|
||||
if not self.enabled then
|
||||
if not vim.b.signatureHelp then
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -239,18 +244,27 @@ function SignatureHelp:trigger()
|
|||
end
|
||||
|
||||
function SignatureHelp:check_capability()
|
||||
local clients = vim.lsp.get_clients()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local clients = vim.lsp.get_clients({ bufnr = bufnr })
|
||||
for _, client in ipairs(clients) do
|
||||
if client.server_capabilities.signatureHelpProvider then
|
||||
self.enabled = true
|
||||
vim.b.signatureHelp = true
|
||||
return
|
||||
end
|
||||
end
|
||||
self.enabled = false
|
||||
end
|
||||
|
||||
function SignatureHelp:setup_autocmds()
|
||||
api.nvim_create_autocmd({ "LspAttach", "BufEnter" }, {
|
||||
-- group = group,
|
||||
callback = function()
|
||||
vim.defer_fn(function()
|
||||
local group = api.nvim_create_augroup("LspSignatureHelp", { clear = true })
|
||||
self:check_capability()
|
||||
|
||||
if not vim.b.signatureHelp then
|
||||
return
|
||||
end
|
||||
|
||||
local function debounced_trigger()
|
||||
if self.timer then
|
||||
|
|
@ -274,7 +288,10 @@ function SignatureHelp:setup_autocmds()
|
|||
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
|
||||
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
|
||||
|
|
@ -301,12 +318,6 @@ function SignatureHelp:setup_autocmds()
|
|||
end
|
||||
end,
|
||||
})
|
||||
|
||||
api.nvim_create_autocmd("LspAttach", {
|
||||
group = group,
|
||||
callback = function()
|
||||
vim.defer_fn(function()
|
||||
self:check_capability()
|
||||
end, 100)
|
||||
end,
|
||||
})
|
||||
|
|
@ -389,7 +400,6 @@ function M.setup(opts)
|
|||
group = vim.api.nvim_create_augroup("LspSignatureColors", { clear = true }),
|
||||
callback = setup_highlights,
|
||||
})
|
||||
|
||||
-- Setup autocmds
|
||||
signature_help:setup_autocmds()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue