fix(lsp): detect if using nvim-0.10 and use new inlay_hint.enable method (#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 <gamurray@fanatics.com>
This commit is contained in:
Gary Murray 2023-11-30 11:53:40 -07:00 committed by GitHub
parent 68ff818a5b
commit 6853b785d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View file

@ -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" }) map("n", "<leader>ud", function() Util.toggle.diagnostics() end, { desc = "Toggle Diagnostics" })
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 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" }) map("n", "<leader>uc", function() Util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" })
if vim.lsp.inlay_hint then if vim.lsp.buf.inlay_hint or 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.toggle.inlay_hints() end, { desc = "Toggle Inlay Hints" })
end 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" }) 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

@ -115,7 +115,7 @@ return {
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" }) vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
end 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 if opts.inlay_hints.enabled and inlay_hint then
Util.lsp.on_attach(function(client, buffer) Util.lsp.on_attach(function(client, buffer)

View file

@ -53,6 +53,17 @@ function M.diagnostics()
end end
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, { setmetatable(M, {
__call = function(m, ...) __call = function(m, ...)
return m.option(...) return m.option(...)