Skip to content

Commit

Permalink
Add keymaps to toggle lsp inlay hints and virtual text (#1364)
Browse files Browse the repository at this point in the history
* chores: rearrange wm & editor keymaps and corresponding plugin

* feat: add keymaps to toggle virtual text and inlay hints
  • Loading branch information
AngelontheRoad authored Nov 17, 2024
1 parent 02aff10 commit f57d574
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lua/keymap/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ function mapping.lsp(buf)
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show outgoing calls"),
["n|<leader>td"] = map_callback(function()
_toggle_diagnostic()
end)
:with_noremap()
:with_silent()
:with_desc("edit: Toggle virtual text display of current buffer"),
["n|<leader>th"] = map_callback(function()
_toggle_inlayhint()
end)
:with_noremap()
:with_silent()
:with_desc("edit: Toggle inlay hints dispaly of current buffer"),
}
bind.nvim_load_mapping(map)

Expand Down
25 changes: 25 additions & 0 deletions lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,28 @@ _G._toggle_lazygit = function()
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
end
end

_G._toggle_inlayhint = function()
if vim.lsp.inlay_hint.is_enabled() then
vim.lsp.inlay_hint.enable(false)
vim.notify("Disable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
else
vim.lsp.inlay_hint.enable(true)
vim.notify("Enable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
end
end

local _diagnostic = 1
_G._toggle_diagnostic = function()
if vim.diagnostic.is_enabled() then
if _diagnostic == 1 then
_diagnostic = 0
vim.diagnostic.hide()
vim.notify("Hide virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
else
_diagnostic = 1
vim.diagnostic.show()
vim.notify("Show virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
end
end
end

0 comments on commit f57d574

Please sign in to comment.