From 0112e1f77983141e1453bd37d124302f1c876c46 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Fri, 20 Jun 2025 15:07:25 +0200 Subject: fix: some `on_attach` callbacks may act on the wrong buffer #3916 Problem: If a server is attached to a non-current buffer by `vim.lsp.buf_attach_client`, then the Language Server-related commands may be created in the current (wrong) buffer. Solution: Always use the `bufnr` arg provided to `on_attach`. --- lsp/ccls.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lsp/ccls.lua') diff --git a/lsp/ccls.lua b/lsp/ccls.lua index d449fc2d..0b72d6d6 100644 --- a/lsp/ccls.lua +++ b/lsp/ccls.lua @@ -44,9 +44,9 @@ return { offset_encoding = 'utf-32', -- ccls does not support sending a null root directory workspace_required = true, - on_attach = function(client) - vim.api.nvim_buf_create_user_command(0, 'LspCclsSwitchSourceHeader', function() - switch_source_header(client, 0) + on_attach = function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspCclsSwitchSourceHeader', function() + switch_source_header(client, bufnr) end, { desc = 'Switch between source/header' }) end, } -- cgit v1.2.3-70-g09d2