Skip to content

Commit 652e95b

Browse files
committed
feat: use command to control LSP inlayHints
1 parent 1d00bfa commit 652e95b

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

lua/lsp_conf.lua

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ vim.api.nvim_create_autocmd("LspAttach", {
8282
if client.name == "ruff" then
8383
client.server_capabilities.hoverProvider = false
8484
end
85-
86-
-- TODO: turn this into a command to toggle dynamically
87-
-- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint,
88-
-- but disable this feature by default, so you may need to enable inlay hint in the LSP server config.
89-
-- vim.lsp.inlay_hint.enable(true, {buffer=bufnr})
9085
end,
9186
nested = true,
9287
desc = "Configure buffer keymap and behavior based on LSP",
@@ -167,3 +162,33 @@ vim.api.nvim_create_autocmd("LspProgress", {
167162
})
168163
end,
169164
})
165+
166+
-- this controls the LSP inlayHints behavior
167+
vim.g.lsp_inlay_hint_enabled = false
168+
169+
local update_inlayhint = function(enable)
170+
-- Some LSP server supports inlay hint, but disable this feature by default, so you may need to
171+
-- enable inlay hint in the LSP server config.
172+
vim.lsp.inlay_hint.enable(enable)
173+
end
174+
175+
vim.api.nvim_create_user_command("LspInlayHints", function(context)
176+
-- vim.print("context", context)
177+
if context["args"] == "enable" then
178+
vim.g.lsp_inlay_hint_enabled = true
179+
end
180+
181+
if context["args"] == "disable" then
182+
vim.g.lsp_inlay_hint_enabled = false
183+
end
184+
185+
update_inlayhint(vim.g.lsp_inlay_hint_enabled)
186+
end, {
187+
bang = false,
188+
nargs = 1,
189+
force = true,
190+
desc = "Toggle LSP inlayHints",
191+
complete = function()
192+
return { "enable", "disable" }
193+
end,
194+
})

0 commit comments

Comments
 (0)