Skip to content

Commit

Permalink
feat(lsp): added native codelens support. Enable in lsp settings. (di…
Browse files Browse the repository at this point in the history
…sabled by default). Fixes LazyVim#2656
  • Loading branch information
folke authored and konosubakonoakua committed Apr 24, 2024
1 parent 7079b99 commit 7daf7f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lua/lazyvim/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,6 +70,9 @@ return {
workspace = {
checkThirdParty = false,
},
codeLens = {
enable = true,
},
completion = {
callSnippet = "Replace",
},
Expand Down Expand Up @@ -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
Expand All @@ -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 <buffer> 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)
Expand Down
2 changes: 2 additions & 0 deletions lua/lazyvim/plugins/lsp/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function M.get()
{ "gK", vim.lsp.buf.signature_help, desc = "Signature Help", has = "signatureHelp" },
{ "<c-k>", vim.lsp.buf.signature_help, mode = "i", desc = "Signature Help", has = "signatureHelp" },
{ "<leader>ca", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" },
{ "<leader>cc", vim.lsp.codelens.run, desc = "Run Codelens", mode = { "n", "v" }, has = "codeLens" },
{ "<leader>cC", vim.lsp.codelens.refresh, desc = "Refresh & Display Codelens", mode = { "n" }, has = "codeLens" },
{
"<leader>cA",
function()
Expand Down

0 comments on commit 7daf7f7

Please sign in to comment.