Skip to content

Commit

Permalink
FT: signature hint close and toggle functions (#242)
Browse files Browse the repository at this point in the history
* signature hint close and toggle functions

* locally scope temporary vars
  • Loading branch information
daveriedstra authored May 7, 2024
1 parent 94e49fa commit 4777c0d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 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,8 @@ local function show_signature(object)
local signature = res:match '%((.+)%)'
if signature then
if float then
lsp_util.open_floating_preview({ signature }, 'supercollider', float_conf)
local _, id = lsp_util.open_floating_preview({ signature }, 'supercollider', float_conf)
hint_winid = id
else
print(signature)
end
Expand All @@ -110,6 +112,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 +135,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 4777c0d

Please sign in to comment.