Skip to content

Commit

Permalink
fix(lsp): detect if using nvim-0.10 and use new inlay_hint.enable met…
Browse files Browse the repository at this point in the history
…hod (#2007)

* Detect if using nvim 0.10 and use new inlay_hint.enable method

* Add lsp util for inlay-hints and update keymap

* Remove the need to check vim version

* Support older nightly builds

* Move inlay_hint toggle in Util.toggle

---------

Co-authored-by: Gary Murray <[email protected]>
  • Loading branch information
garymjr and gamurray authored Nov 30, 2023
1 parent 68ff818 commit 6853b78
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lua/lazyvim/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ map("n", "<leader>ul", function() Util.toggle.number() end, { desc = "Toggle Lin
map("n", "<leader>ud", function() Util.toggle.diagnostics() end, { desc = "Toggle Diagnostics" })
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" })
if vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint then
map( "n", "<leader>uh", function() Util.toggle.inlay_hints() 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" })

Expand Down
2 changes: 1 addition & 1 deletion lua/lazyvim/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ return {
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
end

local inlay_hint = vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint
local inlay_hint = vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint.enable

if opts.inlay_hints.enabled and inlay_hint then
Util.lsp.on_attach(function(client, buffer)
Expand Down
11 changes: 11 additions & 0 deletions lua/lazyvim/util/toggle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ function M.diagnostics()
end
end

---@param bufnr? number
function M.inlay_hints(bufnr)
bufnr = bufnr or 0
local inlay_hint = vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint
if inlay_hint.enable then
vim.lsp.inlay_hint.enable(bufnr, not inlay_hint.is_enabled())
else
vim.lsp.inlay_hint(bufnr, nil)
end
end

setmetatable(M, {
__call = function(m, ...)
return m.option(...)
Expand Down

0 comments on commit 6853b78

Please sign in to comment.