diff --git a/README.md b/README.md index f69f641..4cf2116 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,15 @@ To trigger the lsp-overloads signature popup manually when in normal mode, you c ``` vim.api.nvim_set_keymap("n", "", ":LspOverloadsSignature", { noremap = true, silent = true }) ``` -To instead toggle the display on and off, you can use + +It is also useful to create the corresponding trigger mapping for insert mode too (helps when toggling the popup while in insert mode) ``` -:LspOverloadsSignatureDisplayToggle + vim.api.nvim_set_keymap("i", "", "LspOverloadsSignature", { noremap = true, silent = true }) ``` +Closing the popup while typing can be done using the pre-configured `close_signature` keybind created when the signature window is created (see [Keybinds](#keybinds)) +- It is recommended to override this to match the keybind you use to trigger the overload popup manually, so toggling is more intuitive + #### Toggling automatic display lsp-verloads automatically shows itself by default when you are inside of a function signature and begin typing. You can toggle this feature using @@ -121,6 +125,8 @@ The default mappings are used to navigate between various signature overloads an - `previous_parameter = ""` - `close_signature = ""` +**NOTE: If you already have a keybinding that matches one of the above, it will only get overwritten when the signature popup is open. When the popup is closed, your original keybinding will be restored in the buffer. If you still need to keep your original mappings while the signature popup is open, you will need to modify these bindings so they no longer conflict** + ### Additional Tips - Any calls to `vim.lsp.buf.signature_help()` made while the plugin's signature popup is displayed, will behave diff --git a/lua/lsp-overloads/models/signature.lua b/lua/lsp-overloads/models/signature.lua index cdfa7d5..a4b8d44 100644 --- a/lua/lsp-overloads/models/signature.lua +++ b/lua/lsp-overloads/models/signature.lua @@ -10,6 +10,7 @@ local Signature = { ctx = {}, config = {}, mappings = {}, + original_buf_mappings = {}, bufnr = nil, fwin = nil, signature_content = SignatureContent:new(), @@ -75,11 +76,32 @@ function Signature:add_mapping(mapName, default_lhs, rhs, opts) self.mappings[self.bufnr] = {} end + if self.original_buf_mappings[self.bufnr] == nil then + self.original_buf_mappings[self.bufnr] = {} + end + local config_lhs = self.mappings[self.bufnr][mapName] or default_lhs if config_lhs == nil then return end + -- Check if we have already stored the users original keymapping value before + -- If we haven't, get it from the list of buf keymaps and store it, so that when the signature window is destroyed later, + -- we can restore the users original keymapping. + if self.original_buf_mappings[self.bufnr][config_lhs] == nil then + local original_buf_keymaps = vim.api.nvim_buf_get_keymap(self.bufnr, self.mode) + + -- If the user has mapped to something, then the keymap will be stored as + local alt_modified_lhs = string.gsub(config_lhs, "> The mapping list, indexed first by buffer number, then by mapping name, giving the lhs value of the mapping +---@field original_buf_mappings table> The mapping list, indexed first by buffer number, then by lhs, giving the maparg() dictionary value of the mapping ---@field signature_content SignatureContent The signature content