Skip to content

Commit

Permalink
fix(lsp): don't show codelens for buffers that don't support it (neov…
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 authored Jul 16, 2024
1 parent 5fe4ce6 commit 1f2f460
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 10 additions & 3 deletions runtime/lua/vim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,20 @@ api.nvim_create_autocmd('VimLeavePre', {
---@param params table|nil Parameters to send to the server
---@param handler? lsp.Handler See |lsp-handler|
--- If nil, follows resolution strategy defined in |lsp-handler-configuration|
---
---@param on_unsupported? fun()
--- The function to call when the buffer has no clients that support the given method.
--- Defaults to an `ERROR` level notification.
---@return table<integer, integer> client_request_ids Map of client-id:request-id pairs
---for all successful requests.
---@return function _cancel_all_requests Function which can be used to
---cancel all the requests. You could instead
---iterate all clients and call their `cancel_request()` methods.
function lsp.buf_request(bufnr, method, params, handler)
function lsp.buf_request(bufnr, method, params, handler, on_unsupported)
validate({
bufnr = { bufnr, 'n', true },
method = { method, 's' },
handler = { handler, 'f', true },
on_unsupported = { on_unsupported, 'f', true },
})

bufnr = resolve_bufnr(bufnr)
Expand All @@ -887,7 +890,11 @@ function lsp.buf_request(bufnr, method, params, handler)

-- if has client but no clients support the given method, notify the user
if next(clients) and not method_supported then
vim.notify(lsp._unsupported_method(method), vim.log.levels.ERROR)
if on_unsupported == nil then
vim.notify(lsp._unsupported_method(method), vim.log.levels.ERROR)
else
on_unsupported()
end
vim.cmd.redraw()
return {}, function() end
end
Expand Down
8 changes: 7 additions & 1 deletion runtime/lua/vim/lsp/codelens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@ function M.refresh(opts)
}
active_refreshes[buf] = true

local request_ids = vim.lsp.buf_request(buf, ms.textDocument_codeLens, params, M.on_codelens)
local request_ids = vim.lsp.buf_request(
buf,
ms.textDocument_codeLens,
params,
M.on_codelens,
function() end
)
if vim.tbl_isempty(request_ids) then
active_refreshes[buf] = nil
end
Expand Down

0 comments on commit 1f2f460

Please sign in to comment.