diff options
author | Riley Bruins <ribru17@hotmail.com> | 2024-07-16 10:48:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-16 19:48:54 +0200 |
commit | 1f2f460b4a77a8ff58872e03c071b5d0d882dd44 (patch) | |
tree | d39c4b770acb00ae171eb24c8eefa149bb197c3b | |
parent | 5fe4ce6678c0b531487e4d9836774464b5ec56ed (diff) | |
download | rneovim-1f2f460b4a77a8ff58872e03c071b5d0d882dd44.tar.gz rneovim-1f2f460b4a77a8ff58872e03c071b5d0d882dd44.tar.bz2 rneovim-1f2f460b4a77a8ff58872e03c071b5d0d882dd44.zip |
fix(lsp): don't show codelens for buffers that don't support it (#29690)
-rw-r--r-- | runtime/lua/vim/lsp.lua | 13 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/codelens.lua | 8 |
2 files changed, 17 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 382ec58156..168172f345 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -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) @@ -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 diff --git a/runtime/lua/vim/lsp/codelens.lua b/runtime/lua/vim/lsp/codelens.lua index c85bb6aa32..c1b6bfb28c 100644 --- a/runtime/lua/vim/lsp/codelens.lua +++ b/runtime/lua/vim/lsp/codelens.lua @@ -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 |