Skip to content

Commit

Permalink
feat(lsp): show server name in code actions neovim#30830
Browse files Browse the repository at this point in the history
Problem:
If there are multiple LSP clients, it's not clear which actions are provided by which servers. neovim#30710

Solution:
Show the server name next to each action (only if there are multiple clients).
  • Loading branch information
JordanllHarper authored Oct 17, 2024
1 parent e265363 commit ce67804
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions runtime/lua/vim/lsp/buf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit ce67804

Please sign in to comment.