diff --git a/lua/scnvim/signature.lua b/lua/scnvim/signature.lua index cc7684b4..59c9ff10 100644 --- a/lua/scnvim/signature.lua +++ b/lua/scnvim/signature.lua @@ -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 = {} @@ -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 @@ -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) @@ -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