Skip to content

Commit cbe3cfd

Browse files
committed
fix: use new vim.lsp.codelens api in neovim v0.12
1 parent 47587c1 commit cbe3cfd

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lua/astrolsp/init.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ end
7676
---@param client vim.lsp.Client The LSP client details when attaching
7777
---@param bufnr integer The buffer that the LSP client is attaching to
7878
function M.on_attach(client, bufnr)
79-
if client:supports_method("textDocument/codeLens", bufnr) and M.config.features.codelens then
79+
-- TODO: remove check when dropping support for Neovim v0.11
80+
if
81+
client:supports_method("textDocument/codeLens", bufnr)
82+
and not vim.lsp.codelens.enable
83+
and M.config.features.codelens
84+
then
8085
vim.lsp.codelens.refresh { bufnr = bufnr }
8186
end
8287

@@ -289,6 +294,8 @@ function M.setup(opts)
289294
if vim.lsp.linked_editing_range then
290295
vim.lsp.linked_editing_range.enable(M.config.features.linked_editing_range ~= false)
291296
end
297+
-- TODO: remove check when dropping support for Neovim v0.11
298+
if vim.lsp.codelens.enable then vim.lsp.codelens.enable(M.config.features.codelens ~= false) end
292299

293300
-- Set up tracking of signature help trigger characters
294301
local augroup = vim.api.nvim_create_augroup("track_signature_help_triggers", { clear = true })

lua/astrolsp/toggles.lua

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,31 @@ function M.semantic_tokens(silent)
9595
ui_notify(silent, ("Global lsp semantic highlighting %s"):format(bool2str(vim.lsp.semantic_tokens.is_enabled())))
9696
end
9797

98-
--- Toggle codelens
98+
--- Toggle buffer codelens
99+
---@param bufnr? integer the buffer to toggle the clients on
100+
---@param silent? boolean if true then don't sent a notification
101+
function M.buffer_codelens(bufnr, silent)
102+
bufnr = bufnr or 0
103+
if not vim.lsp.codelens.enable then
104+
ui_notify(silent, "Only available in Neovim v0.12+", vim.log.levels.WARN)
105+
return
106+
end
107+
vim.lsp.codelens.enable(not vim.lsp.codelens.is_enabled { bufnr = bufnr })
108+
ui_notify(silent, ("CodeLens %s"):format(bool2str(vim.lsp.codelens.is_enabled { bufnr = bufnr })))
109+
end
110+
111+
--- Toggle global codelens
99112
---@param silent? boolean if true then don't sent a notification
100113
function M.codelens(silent)
101-
features.codelens = not features.codelens
102-
if not features.codelens then vim.lsp.codelens.clear() end
103-
ui_notify(silent, ("CodeLens %s"):format(bool2str(features.codelens)))
114+
-- TODO: remove check when dropping support for Neovim v0.11
115+
if vim.lsp.codelens.enable then
116+
vim.lsp.codelens.enable(not vim.lsp.codelens.is_enabled())
117+
ui_notify(silent, ("CodeLens %s"):format(bool2str(vim.lsp.codelens.is_enabled())))
118+
else
119+
features.codelens = not features.codelens
120+
if not features.codelens then vim.lsp.codelens.clear() end
121+
ui_notify(silent, ("CodeLens %s"):format(bool2str(features.codelens)))
122+
end
104123
end
105124

106125
--- Toggle automatic signature help

0 commit comments

Comments
 (0)