diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index fbb4aeac2b..7d5fad0dd2 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -41,6 +41,12 @@ return { inlay_hints = { enabled = false, }, + -- Enable this to enable the builtin LSP code lenses on Neovim >= 0.10.0 + -- Be aware that you also will need to properly configure your LSP server to + -- provide the code lenses. + codelens = { + enabled = false, + }, -- add any global capabilities here capabilities = {}, -- options for vim.lsp.buf.format @@ -64,6 +70,9 @@ return { workspace = { checkThirdParty = false, }, + codeLens = { + enable = true, + }, completion = { callSnippet = "Replace", }, @@ -123,6 +132,7 @@ return { vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" }) end + -- inlay hints if opts.inlay_hints.enabled then Util.lsp.on_attach(function(client, buffer) if client.supports_method("textDocument/inlayHint") then @@ -131,6 +141,20 @@ return { end) end + -- code lens + if opts.codelens.enabled and vim.lsp.codelens then + Util.lsp.on_attach(function(client, buffer) + if client.supports_method("textDocument/codeLens") then + vim.lsp.codelens.refresh() + --- autocmd BufEnter,CursorHold,InsertLeave lua vim.lsp.codelens.refresh() + vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, { + buffer = buffer, + callback = vim.lsp.codelens.refresh, + }) + end + end) + end + if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and "●" or function(diagnostic) diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 10e5d86f85..3e8976bb6e 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -23,6 +23,8 @@ function M.get() { "gK", vim.lsp.buf.signature_help, desc = "Signature Help", has = "signatureHelp" }, { "", vim.lsp.buf.signature_help, mode = "i", desc = "Signature Help", has = "signatureHelp" }, { "ca", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" }, + { "cc", vim.lsp.codelens.run, desc = "Run Codelens", mode = { "n", "v" }, has = "codeLens" }, + { "cC", vim.lsp.codelens.refresh, desc = "Refresh & Display Codelens", mode = { "n" }, has = "codeLens" }, { "cA", function()