mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-03 17:24:29 +00:00 
			
		
		
		
	fix(lsp): include context for each client in multi-handler results (#34669)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							f0c0c24ed7
						
					
				
				
					commit
					6005bc68b2
				
			@@ -1331,7 +1331,7 @@ end
 | 
				
			|||||||
--- a `client_id:result` map.
 | 
					--- a `client_id:result` map.
 | 
				
			||||||
---@return function cancel Function that cancels all requests.
 | 
					---@return function cancel Function that cancels all requests.
 | 
				
			||||||
function lsp.buf_request_all(bufnr, method, params, handler)
 | 
					function lsp.buf_request_all(bufnr, method, params, handler)
 | 
				
			||||||
  local results = {} --- @type table<integer,{err: lsp.ResponseError?, result: any}>
 | 
					  local results = {} --- @type table<integer,{err: lsp.ResponseError?, result: any, context: lsp.HandlerContext}>
 | 
				
			||||||
  local remaining --- @type integer?
 | 
					  local remaining --- @type integer?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local _, cancel = lsp.buf_request(bufnr, method, params, function(err, result, ctx, config)
 | 
					  local _, cancel = lsp.buf_request(bufnr, method, params, function(err, result, ctx, config)
 | 
				
			||||||
@@ -1341,7 +1341,7 @@ function lsp.buf_request_all(bufnr, method, params, handler)
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    -- The error key is deprecated and will be removed in 0.13
 | 
					    -- The error key is deprecated and will be removed in 0.13
 | 
				
			||||||
    results[ctx.client_id] = { err = err, error = err, result = result }
 | 
					    results[ctx.client_id] = { err = err, error = err, result = result, context = ctx }
 | 
				
			||||||
    remaining = remaining - 1
 | 
					    remaining = remaining - 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if remaining == 0 then
 | 
					    if remaining == 0 then
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
error('Cannot require a meta file')
 | 
					error('Cannot require a meta file')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
---@alias lsp.Handler fun(err: lsp.ResponseError?, result: any, context: lsp.HandlerContext, config?: table): ...any
 | 
					---@alias lsp.Handler fun(err: lsp.ResponseError?, result: any, context: lsp.HandlerContext, config?: table): ...any
 | 
				
			||||||
---@alias lsp.MultiHandler fun(results: table<integer,{err: lsp.ResponseError?, result: any}>, context: lsp.HandlerContext, config?: table): ...any
 | 
					---@alias lsp.MultiHandler fun(results: table<integer,{err: lsp.ResponseError?, result: any, context: lsp.HandlerContext}>, context: lsp.HandlerContext, config?: table): ...any
 | 
				
			||||||
 | 
					
 | 
				
			||||||
---@class lsp.HandlerContext
 | 
					---@class lsp.HandlerContext
 | 
				
			||||||
---@field method string
 | 
					---@field method string
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1075,7 +1075,7 @@ end
 | 
				
			|||||||
---@class vim.lsp.CodeActionResultEntry
 | 
					---@class vim.lsp.CodeActionResultEntry
 | 
				
			||||||
---@field err? lsp.ResponseError
 | 
					---@field err? lsp.ResponseError
 | 
				
			||||||
---@field result? (lsp.Command|lsp.CodeAction)[]
 | 
					---@field result? (lsp.Command|lsp.CodeAction)[]
 | 
				
			||||||
---@field ctx lsp.HandlerContext
 | 
					---@field context lsp.HandlerContext
 | 
				
			||||||
 | 
					
 | 
				
			||||||
--- @class vim.lsp.buf.code_action.Opts
 | 
					--- @class vim.lsp.buf.code_action.Opts
 | 
				
			||||||
--- @inlinedoc
 | 
					--- @inlinedoc
 | 
				
			||||||
@@ -1152,7 +1152,7 @@ local function on_code_action_results(results, opts)
 | 
				
			|||||||
  for _, result in pairs(results) do
 | 
					  for _, result in pairs(results) do
 | 
				
			||||||
    for _, action in pairs(result.result or {}) do
 | 
					    for _, action in pairs(result.result or {}) do
 | 
				
			||||||
      if action_filter(action) then
 | 
					      if action_filter(action) then
 | 
				
			||||||
        table.insert(actions, { action = action, ctx = result.ctx })
 | 
					        table.insert(actions, { action = action, ctx = result.context })
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
@@ -1325,12 +1325,7 @@ function M.code_action(opts)
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return params
 | 
					    return params
 | 
				
			||||||
  end, function(results, ctx)
 | 
					  end, function(results)
 | 
				
			||||||
    for _, result in pairs(results) do
 | 
					 | 
				
			||||||
      ---@cast result vim.lsp.CodeActionResultEntry
 | 
					 | 
				
			||||||
      result.ctx = ctx
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    on_code_action_results(results, opts)
 | 
					    on_code_action_results(results, opts)
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user