Add lsp util for inlay-hints and update keymap

This commit is contained in:
Gary Murray 2023-11-16 08:50:02 -07:00
parent bd4668737d
commit 8a24b61aed
2 changed files with 15 additions and 1 deletions

View file

@ -120,7 +120,7 @@ map("n", "<leader>ud", function() Util.toggle.diagnostics() end, { desc = "Toggl
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3
map("n", "<leader>uc", function() Util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" })
if vim.lsp.inlay_hint then
map("n", "<leader>uh", function() vim.lsp.inlay_hint(0, nil) end, { desc = "Toggle Inlay Hints" })
map( "n", "<leader>uh", function() Util.lsp.toggle_inline_hint() end, { desc = "Toggle Inlay Hints" })
end
map("n", "<leader>uT", function() if vim.b.ts_highlight then vim.treesitter.stop() else vim.treesitter.start() end end, { desc = "Toggle Treesitter Highlight" })

View file

@ -122,4 +122,18 @@ function M.format(opts)
end
end
---@param bufnr? number
function M.toggle_inline_hint(bufnr)
bufnr = bufnr or 0
if vim.fn.has("nvim-0.10") then
if vim.lsp.inlay_hint.is_enabled() then
vim.lsp.inlay_hint.enable(bufnr, false)
else
vim.lsp.inlay_hint.enable(bufnr, true)
end
else
vim.lsp.inlay_hint(bufnr, nil)
end
end
return M