fix(util.lsp): LazyVim.lsp.execute only request single client (#6904)

## Description
`LazyVim.lsp.execute` uses `vim.lsp.buf_request` which sends the request
to all attached clients.

`LazyVim.lsp.execute` seems to me to be the equivalent of
[vim.lsp.buf.execute_command](922816877f/runtime/lua/vim/lsp/buf.lua (L1366-L1376)),
but adds the option to also open in Trouble. Otherwise the request is
being made the same way. This command will be deprecated in 0.12 and
it's advised to use `client:exec_cmd` instead.

Since LazyVim supports Neovim >=0.11.2, it makes sense to refactor the
corresponding codeblock and use `client:cmd_exec` instead (it's already
available in Neovim 0.11).

I only changed the necessary parts where `vim.lsp.buf_request` was being
used and not Trouble (when `opts.open = true`), since I'm not familiar
with its codebase. That's also why I went for extending `params` in the
`else` branch instead of adding `title` into original `params`, since I
didn't know how Trouble will react to this change. Not sure if maybe
there also needs to be some change there.
<!-- Describe the big picture of your changes to communicate to the
maintainers
  why we should accept this pull request. -->

## Related Issue(s)
Fixes #6900
<!--
  If this PR fixes any issues, please link to the issue here.
  - Fixes #<issue_number>
-->

## Screenshots

<!-- Add screenshots of the changes if applicable. -->

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
This commit is contained in:
Iordanis Petkakis
2026-03-01 10:31:44 +02:00
committed by GitHub
parent 244af66f8b
commit a4e19e9c9c
4 changed files with 22 additions and 2 deletions

View File

@@ -16,6 +16,8 @@ return {
function()
local params = vim.lsp.util.make_position_params()
LazyVim.lsp.execute({
title = "toPipe",
filter = "elixirls",
command = "manipulatePipes:serverid",
arguments = { "toPipe", params.textDocument.uri, params.position.line, params.position.character },
})
@@ -27,6 +29,8 @@ return {
function()
local params = vim.lsp.util.make_position_params()
LazyVim.lsp.execute({
title = "fromPipe",
filter = "elixirls",
command = "manipulatePipes:serverid",
arguments = { "fromPipe", params.textDocument.uri, params.position.line, params.position.character },
})

View File

@@ -113,7 +113,11 @@ return {
{
"<leader>cV",
function()
LazyVim.lsp.execute({ command = "typescript.selectTypeScriptVersion" })
LazyVim.lsp.execute({
title = "Select TypeScript Version",
filter = "vtsls",
command = "typescript.selectTypeScriptVersion",
})
end,
desc = "Select TS workspace version",
},

View File

@@ -24,6 +24,8 @@ return {
local buf_name = vim.api.nvim_buf_get_name(0)
local file_name = vim.fn.fnamemodify(buf_name, ":t")
LazyVim.lsp.execute({
title = "Pin Main",
filter = "tinymist",
command = "tinymist.pinMain",
arguments = { buf_name },
})

View File

@@ -70,9 +70,18 @@ M.action = setmetatable({}, {
---@class LspCommand: lsp.ExecuteCommandParams
---@field open? boolean
---@field handler? lsp.Handler
---@field filter? string|vim.lsp.get_clients.Filter
---@field title? string
---@param opts LspCommand
function M.execute(opts)
local filter = opts.filter or {}
filter = type(filter) == "string" and { name = filter } or filter
local buf = vim.api.nvim_get_current_buf()
---@cast filter vim.lsp.get_clients.Filter
local client = vim.lsp.get_clients(LazyVim.merge({}, filter, { bufnr = buf }))[1]
local params = {
command = opts.command,
arguments = opts.arguments,
@@ -83,7 +92,8 @@ function M.execute(opts)
params = params,
})
else
return vim.lsp.buf_request(0, "workspace/executeCommand", params, opts.handler)
vim.list_extend(params, { title = opts.title })
return client:exec_cmd(params, { bufnr = buf }, opts.handler)
end
end