nvim/lsp: add an usercommand to toggle inlay hints

This commit is contained in:
Primrose 2025-07-12 18:38:29 +02:00
parent d3a439f324
commit 10c8aa854d
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

View file

@ -28,12 +28,20 @@ M.on_attach = function(client, bufnr)
nnoremap("<leader>r", vim.lsp.buf.rename, "rename symbol") nnoremap("<leader>r", vim.lsp.buf.rename, "rename symbol")
pcall(nnoremap, "<leader>f", function() vim.lsp.buf.format { async = true } end, "format buffer", { unique = true }) pcall(nnoremap, "<leader>f", function() vim.lsp.buf.format { async = true } end, "format buffer", { unique = true })
vim.api.nvim_buf_create_user_command(
bufnr,
"LspToggleInlayHints",
function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) end,
{}
)
local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr }) local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
if if
client:supports_method(methods.textDocument_inlayHint) client:supports_method(methods.textDocument_inlayHint)
-- Never start cabal with inlay hint request -- Never start cabal with inlay hint request
-- Related: https://github.com/mrcjkb/haskell-tools.nvim/discussions/485 -- Related: https://github.com/mrcjkb/haskell-tools.nvim/discussions/485
and filetype ~= "cabal" and filetype ~= "cabal"
-- I find it annoying especially with qmk
and filetype ~= "c"
then then
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
end end