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`. --- lua/lspconfig/configs/tinymist.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/configs/tinymist.lua b/lua/lspconfig/configs/tinymist.lua index 9146fdc1..8112adcd 100644 --- a/lua/lspconfig/configs/tinymist.lua +++ b/lua/lspconfig/configs/tinymist.lua @@ -50,7 +50,7 @@ return { return vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1]) end, single_file_support = true, - on_attach = function(_) + on_attach = function(_, bufnr) for _, command in ipairs { 'tinymist.exportSvg', 'tinymist.exportPng', @@ -66,7 +66,7 @@ return { 'tinymist.getDocumentMetrics', } do local cmd_func, cmd_name, cmd_desc = create_tinymist_command(command) - vim.api.nvim_create_user_command(cmd_name, cmd_func, { nargs = 0, desc = cmd_desc }) + vim.api.nvim_buf_create_user_command(bufnr, cmd_name, cmd_func, { nargs = 0, desc = cmd_desc }) end end, }, -- cgit v1.2.3-70-g09d2