diff options
author | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2023-07-12 14:48:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-12 14:48:21 +0200 |
commit | 317c80f460a7826421f40f57ee8bdbd736b0f225 (patch) | |
tree | 06bb41ef6332fbd0cd4585969e7b3c12c76b444b /runtime/lua/vim/lsp/buf.lua | |
parent | ef94fb69c65bc2e4c67826de6373c202b55b7d5a (diff) | |
download | rneovim-317c80f460a7826421f40f57ee8bdbd736b0f225.tar.gz rneovim-317c80f460a7826421f40f57ee8bdbd736b0f225.tar.bz2 rneovim-317c80f460a7826421f40f57ee8bdbd736b0f225.zip |
feat(lsp): add method filter to get_active_clients (#24319)
Diffstat (limited to 'runtime/lua/vim/lsp/buf.lua')
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 8ae0e0cde3..b238b5c221 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -197,15 +197,6 @@ end function M.format(options) options = options or {} local bufnr = options.bufnr or api.nvim_get_current_buf() - local clients = vim.lsp.get_active_clients({ - id = options.id, - bufnr = bufnr, - name = options.name, - }) - - if options.filter then - clients = vim.tbl_filter(options.filter, clients) - end local mode = api.nvim_get_mode().mode local range = options.range @@ -214,9 +205,15 @@ function M.format(options) end local method = range and 'textDocument/rangeFormatting' or 'textDocument/formatting' - clients = vim.tbl_filter(function(client) - return client.supports_method(method) - end, clients) + local clients = vim.lsp.get_active_clients({ + id = options.id, + bufnr = bufnr, + name = options.name, + method = method, + }) + if options.filter then + clients = vim.tbl_filter(options.filter, clients) + end if #clients == 0 then vim.notify('[LSP] Format request failed, no matching language servers.') @@ -277,16 +274,13 @@ function M.rename(new_name, options) local clients = vim.lsp.get_active_clients({ bufnr = bufnr, name = options.name, + -- Clients must at least support rename, prepareRename is optional + method = 'textDocument/rename', }) if options.filter then clients = vim.tbl_filter(options.filter, clients) end - -- Clients must at least support rename, prepareRename is optional - clients = vim.tbl_filter(function(client) - return client.supports_method('textDocument/rename') - end, clients) - if #clients == 0 then vim.notify('[LSP] Rename, no matching language servers with rename capability.') end |