diff options
author | Jordan <46637683+JordanllHarper@users.noreply.github.com> | 2024-10-17 09:35:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-17 01:35:19 -0700 |
commit | ce678043e3461d45f1251979cf047dd529b117ea (patch) | |
tree | 86b02f95002d53da89097d6f8263903d9ffce497 | |
parent | e265363a884834ecbc43ede676b3d6127d644b34 (diff) | |
download | rneovim-ce678043e3461d45f1251979cf047dd529b117ea.tar.gz rneovim-ce678043e3461d45f1251979cf047dd529b117ea.tar.bz2 rneovim-ce678043e3461d45f1251979cf047dd529b117ea.zip |
feat(lsp): show server name in code actions #30830
Problem:
If there are multiple LSP clients, it's not clear which actions are provided by which servers. #30710
Solution:
Show the server name next to each action (only if there are multiple clients).
-rw-r--r-- | runtime/doc/news.txt | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 14 |
2 files changed, 13 insertions, 3 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 4db9188f90..db2117e69f 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 301c1f0cb6..984222efbe 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', |