diff --git a/lua/keymap/completion.lua b/lua/keymap/completion.lua index 0d19f4e86..3f902b896 100644 --- a/lua/keymap/completion.lua +++ b/lua/keymap/completion.lua @@ -67,6 +67,18 @@ function M.lsp(buf) :with_silent() :with_buffer(buf) :with_desc("lsp: Show outgoing calls"), + ["n|lv"] = map_callback(function() + _toggle_diagnostic() + end) + :with_noremap() + :with_silent() + :with_desc("lsp: Toggle virtual text display of current buffer"), + ["n|lh"] = map_callback(function() + _toggle_inlayhint() + end) + :with_noremap() + :with_silent() + :with_desc("lsp: Toggle inlay hints dispaly of current buffer"), } bind.nvim_load_mapping(map) diff --git a/lua/keymap/editor.lua b/lua/keymap/editor.lua index b1bd50146..8c8c8cd30 100644 --- a/lua/keymap/editor.lua +++ b/lua/keymap/editor.lua @@ -50,20 +50,6 @@ local mappings = { :with_silent() :with_desc("edit: Clear search highlight"), ["n|o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("edit: Toggle spell check"), - - -- Builtins: Lsp - ["n|td"] = map_callback(function() - _toggle_diagnostic() - end) - :with_noremap() - :with_silent() - :with_desc("edit: Toggle global display of virtual text"), - ["n|th"] = map_callback(function() - _toggle_inlayhint() - end) - :with_noremap() - :with_silent() - :with_desc("edit: Toggle global display of inlay hints"), }, plugins = { -- Plugin: persisted.nvim diff --git a/lua/keymap/helpers.lua b/lua/keymap/helpers.lua index 334db528e..d37fe4160 100644 --- a/lua/keymap/helpers.lua +++ b/lua/keymap/helpers.lua @@ -38,6 +38,30 @@ _G._telescope_collections = function(picker_type) :find() end +_G._toggle_inlayhint = function() + local is_enabled = vim.lsp.inlay_hint.is_enabled() + + vim.lsp.inlay_hint.enable(not is_enabled) + vim.notify( + (is_enabled and "Inlay hint disabled successfully" or "Inlay hint enabled successfully"), + vim.log.levels.INFO, + { title = "LSP Inlay Hint" } + ) +end + +local _vt_enabled = require("core.settings").diagnostics_virtual_text +_G._toggle_diagnostic = function() + if vim.diagnostic.is_enabled() then + _vt_enabled = not _vt_enabled + vim.diagnostic[_vt_enabled and "show" or "hide"]() + vim.notify( + (_vt_enabled and "Virtual text is now displayed" or "Virtual text is now hidden"), + vim.log.levels.INFO, + { title = "LSP Diagnostic" } + ) + end +end + _G._flash_esc_or_noh = function() local flash_active, state = pcall(function() return require("flash.plugins.char").state @@ -65,32 +89,6 @@ _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 - _G._async_compile_and_debug = function() local file_ext = vim.fn.expand("%:e") local file_path = vim.fn.expand("%:p")