Skip to content

Commit 968d071

Browse files
committed
fix(keymap.helpers): improve _toggle* helper functions
1 parent 1bb9d15 commit 968d071

File tree

3 files changed

+36
-39
lines changed

3 files changed

+36
-39
lines changed

lua/keymap/completion.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ function M.lsp(buf)
7272
:with_silent()
7373
:with_buffer(buf)
7474
:with_desc("lsp: Show outgoing calls"),
75+
["n|<leader>lv"] = map_callback(function()
76+
_toggle_diagnostic()
77+
end)
78+
:with_noremap()
79+
:with_silent()
80+
:with_desc("lsp: Toggle virtual text display of current buffer"),
81+
["n|<leader>lh"] = map_callback(function()
82+
_toggle_inlayhint()
83+
end)
84+
:with_noremap()
85+
:with_silent()
86+
:with_desc("lsp: Toggle inlay hints dispaly of current buffer"),
7587
}
7688
bind.nvim_load_mapping(map)
7789

lua/keymap/editor.lua

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,6 @@ local mappings = {
6363
:with_desc("file: chmod +x current file"),
6464
["n|<C-p>"] = map_cmd("<Nop>"):with_noremap():with_silent():with_desc("Disable native cmp"),
6565
["n|<C-n>"] = map_cmd("<Nop>"):with_noremap():with_silent():with_desc("Disable native cmp"),
66-
67-
-- Builtins: Lsp
68-
["n|<leader>td"] = map_callback(function()
69-
_toggle_diagnostic()
70-
end)
71-
:with_noremap()
72-
:with_silent()
73-
:with_desc("edit: Toggle virtual text display of current buffer"),
74-
["n|<leader>th"] = map_callback(function()
75-
_toggle_inlayhint()
76-
end)
77-
:with_noremap()
78-
:with_silent()
79-
:with_desc("edit: Toggle inlay hints dispaly of current buffer"),
8066
},
8167
plugins = {
8268
-- Plugin: persisted.nvim

lua/keymap/helpers.lua

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ _G._telescope_collections = function(picker_type)
3838
:find()
3939
end
4040

41+
_G._toggle_inlayhint = function()
42+
local is_enabled = vim.lsp.inlay_hint.is_enabled()
43+
44+
vim.lsp.inlay_hint.enable(not is_enabled)
45+
vim.notify(
46+
(is_enabled and "Inlay hint disabled successfully" or "Inlay hint enabled successfully"),
47+
vim.log.levels.INFO,
48+
{ title = "LSP Inlay Hint" }
49+
)
50+
end
51+
52+
local _vt_enabled = require("core.settings").diagnostics_virtual_text
53+
_G._toggle_diagnostic = function()
54+
if vim.diagnostic.is_enabled() then
55+
_vt_enabled = not _vt_enabled
56+
vim.diagnostic[_vt_enabled and "show" or "hide"]()
57+
vim.notify(
58+
(_vt_enabled and "Virtual text is now displayed" or "Virtual text is now hidden"),
59+
vim.log.levels.INFO,
60+
{ title = "LSP Diagnostic" }
61+
)
62+
end
63+
end
64+
4165
_G._flash_esc_or_noh = function()
4266
local flash_active, state = pcall(function()
4367
return require("flash.plugins.char").state
@@ -49,31 +73,6 @@ _G._flash_esc_or_noh = function()
4973
end
5074
end
5175

52-
_G._toggle_inlayhint = function()
53-
if vim.lsp.inlay_hint.is_enabled() then
54-
vim.lsp.inlay_hint.enable(false)
55-
vim.notify("Disable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
56-
else
57-
vim.lsp.inlay_hint.enable(true)
58-
vim.notify("Enable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
59-
end
60-
end
61-
62-
local _diagnostic = 1
63-
_G._toggle_diagnostic = function()
64-
if vim.diagnostic.is_enabled() then
65-
if _diagnostic == 1 then
66-
_diagnostic = 0
67-
vim.diagnostic.hide()
68-
vim.notify("Hide virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
69-
else
70-
_diagnostic = 1
71-
vim.diagnostic.show()
72-
vim.notify("Show virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
73-
end
74-
end
75-
end
76-
7776
---@param program string
7877
local function not_found_notify(program)
7978
vim.notify(string.format("[%s] not found!", program), vim.log.levels.ERROR, { title = "toggleterm.nvim" })

0 commit comments

Comments
 (0)