diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 4db9188f9047e2..db2117e69f793d 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -182,6 +182,8 @@ LSP • |vim.lsp.buf.format()| now supports passing a list of ranges via the `range` parameter (this requires support for the `textDocument/rangesFormatting` request). +• |vim.lsp.buf.code_action()| actions show client name when there are multiple + clients. LUA diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 301c1f0cb62aab..984222efbe6e36 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -827,11 +827,19 @@ local function on_code_action_results(results, opts) return end - ---@param item {action: lsp.Command|lsp.CodeAction} + ---@param item {action: lsp.Command|lsp.CodeAction, ctx: lsp.HandlerContext} local function format_item(item) - local title = item.action.title:gsub('\r\n', '\\r\\n') - return title:gsub('\n', '\\n') + local clients = vim.lsp.get_clients({ bufnr = item.ctx.bufnr }) + local title = item.action.title:gsub('\r\n', '\\r\\n'):gsub('\n', '\\n') + + if #clients == 1 then + return title + end + + local source = vim.lsp.get_client_by_id(item.ctx.client_id).name + return ('%s [%s]'):format(title, source) end + local select_opts = { prompt = 'Code actions:', kind = 'codeaction',