feat(lsp): turn rename filter into a predicate (#18745)

Same as https://github.com/neovim/neovim/pull/18458 but for rename
This commit is contained in:
Mathias Fußenegger
2022-05-26 12:28:50 +02:00
committed by GitHub
parent 7b952793d5
commit e8ada41b63
2 changed files with 11 additions and 14 deletions

View File

@@ -1271,10 +1271,10 @@ rename({new_name}, {options}) *vim.lsp.buf.rename()*
prompted for a new name using prompted for a new name using
|vim.ui.input()|. |vim.ui.input()|.
{options} (table|nil) additional options {options} (table|nil) additional options
• filter (function|nil): Predicate to filter • filter (function|nil): Predicate used to
clients used for rename. Receives the filter clients. Receives a client as
attached clients as argument and must return argument and must return a boolean. Clients
a list of clients. matching the predicate are included.
• name (string|nil): Restrict clients used for • name (string|nil): Restrict clients used for
rename to ones where client.name matches rename to ones where client.name matches
this field. this field.

View File

@@ -377,23 +377,20 @@ end
--- name using |vim.ui.input()|. --- name using |vim.ui.input()|.
---@param options table|nil additional options ---@param options table|nil additional options
--- - filter (function|nil): --- - filter (function|nil):
--- Predicate to filter clients used for rename. --- Predicate used to filter clients. Receives a client as argument and
--- Receives the attached clients as argument and must return a list of --- must return a boolean. Clients matching the predicate are included.
--- clients.
--- - name (string|nil): --- - name (string|nil):
--- Restrict clients used for rename to ones where client.name matches --- Restrict clients used for rename to ones where client.name matches
--- this field. --- this field.
function M.rename(new_name, options) function M.rename(new_name, options)
options = options or {} options = options or {}
local bufnr = options.bufnr or vim.api.nvim_get_current_buf() local bufnr = options.bufnr or vim.api.nvim_get_current_buf()
local clients = vim.lsp.buf_get_clients(bufnr) local clients = vim.lsp.get_active_clients({
bufnr = bufnr,
name = options.name,
})
if options.filter then if options.filter then
clients = options.filter(clients) clients = vim.tbl_filter(options.filter, clients)
elseif options.name then
clients = vim.tbl_filter(function(client)
return client.name == options.name
end, clients)
end end
-- Clients must at least support rename, prepareRename is optional -- Clients must at least support rename, prepareRename is optional