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/ds_pinyin_lsp.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lsp/ds_pinyin_lsp.lua') diff --git a/lsp/ds_pinyin_lsp.lua b/lsp/ds_pinyin_lsp.lua index bf12272e..528a5102 100644 --- a/lsp/ds_pinyin_lsp.lua +++ b/lsp/ds_pinyin_lsp.lua @@ -55,12 +55,12 @@ return { match_long_input = true, max_suggest = 15, }, - on_attach = function() - vim.api.nvim_buf_create_user_command(0, 'LspDsPinyinCompletionOff', function() - ds_pinyin_lsp_off(0) + on_attach = function(_, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspDsPinyinCompletionOff', function() + ds_pinyin_lsp_off(bufnr) end, { desc = 'Turn off the ds-pinyin-lsp completion' }) - vim.api.nvim_buf_create_user_command(0, 'LspDsPinyinCompletionOn', function() - ds_pinyin_lsp_on(0) + vim.api.nvim_buf_create_user_command(bufnr, 'LspDsPinyinCompletionOn', function() + ds_pinyin_lsp_on(bufnr) end, { desc = 'Turn on the ds-pinyin-lsp completion' }) end, } -- cgit v1.2.3-70-g09d2