Skip to content

Commit

Permalink
signature hint close and toggle functions
Browse files Browse the repository at this point in the history
  • Loading branch information
daveriedstra committed May 7, 2024
1 parent 94e49fa commit e0e1fda
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lua/scnvim/signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local sclang = require 'scnvim.sclang'
local config = require 'scnvim.config'
local api = vim.api
local lsp_util = vim.lsp.util
local hint_winid = nil

local M = {}

Expand Down Expand Up @@ -101,7 +102,7 @@ local function show_signature(object)
local signature = res:match '%((.+)%)'
if signature then
if float then
lsp_util.open_floating_preview({ signature }, 'supercollider', float_conf)
_, hint_winid = lsp_util.open_floating_preview({ signature }, 'supercollider', float_conf)
else
print(signature)
end
Expand All @@ -110,6 +111,11 @@ local function show_signature(object)
end
end

local function close_signature()
vim.api.nvim_win_close(hint_winid, false)
hint_winid = nil
end

--- Show signature from normal mode
function M.show()
local ok, object = pcall(extract_object)
Expand All @@ -128,4 +134,20 @@ function M.ins_show()
end
end

-- Close signature hint window
function M.close()
if hint_winid ~= nil and vim.api.nvim_win_is_valid(hint_winid) then
pcall(close_signature)
end
end

-- Toggle signature hint window
function M.toggle()
if hint_winid ~= nil and vim.api.nvim_win_is_valid(hint_winid) then
pcall(close_signature)
else
M.show()
end
end

return M

0 comments on commit e0e1fda

Please sign in to comment.