feat(lsp): add native inlay hints (neovim v0.10 only)

This commit is contained in:
Micah Halter
2023-06-21 11:05:05 -04:00
parent 4b6bea777e
commit 14ba29cec6
3 changed files with 24 additions and 0 deletions
+1
View File
@@ -59,6 +59,7 @@ local options = astronvim.user_opts("options", {
diagnostics_mode = 3, -- set the visibility of diagnostics in the UI (0=off, 1=only show in status line, 2=virtual text off, 3=all on)
highlighturl_enabled = true, -- highlight URLs by default
icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available)
inlay_hints_enabled = false, -- enable or disable LSP inlay hints on startup (Neovim v0.10 only)
lsp_handlers_enabled = true, -- enable or disable default vim.lsp.handlers (hover and signatureHelp)
semantic_tokens_enabled = true, -- enable or disable LSP semantic tokens on startup
ui_notifications_enabled = true, -- disable notifications (TODO: rename to notifications_enabled in AstroNvim v4)
+12
View File
@@ -289,6 +289,18 @@ M.on_attach = function(client, bufnr)
}
end
if client.supports_method "textDocument/inlayHint" then
if vim.b.inlay_hints_enabled == nil then vim.b.inlay_hints_enabled = vim.g.inlay_hints_enabled end
-- TODO: remove check after dropping support for Neovim v0.9
if vim.lsp.buf.inlay_hint then
if vim.b.inlay_hints_enabled then vim.lsp.buf.inlay_hint(bufnr, true) end
lsp_mappings.n["<leader>uH"] = {
function() require("astronvim.utils.ui").toggle_buffer_inlay_hints(bufnr) end,
desc = "Toggle LSP inlay hints (buffer)",
}
end
end
if client.supports_method "textDocument/references" then
lsp_mappings.n["gr"] = {
function() vim.lsp.buf.references() end,
+11
View File
@@ -91,6 +91,17 @@ function M.toggle_buffer_semantic_tokens(bufnr)
end
end
--- Toggle buffer LSP inlay hints
---@param bufnr? number the buffer to toggle the clients on
function M.toggle_buffer_inlay_hints(bufnr)
vim.b.inlay_hints_enabled = not vim.b.inlay_hints_enabled
-- TODO: remove check after dropping support for Neovim v0.9
if vim.lsp.buf.inlay_hint then
vim.lsp.buf.inlay_hint(bufnr or 0, vim.b.inlay_hints_enabled)
notify(string.format("Inlay hints %s", bool2str(vim.b.inlay_hints_enabled)))
end
end
--- Toggle codelens
function M.toggle_codelens()
vim.g.codelens_enabled = not vim.g.codelens_enabled