From 15abde1676575cd4b938087b4fe7bed5d7182951 Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Sat, 5 Jun 2021 14:46:10 -0700 Subject: fix(lsp): set_loclist should target current win Currently, for large number of diagnostics, the delay in populating loclist may be sufficient for a user to switch to another window, resulting in the loclist being populated on the wrong window. --- runtime/lua/vim/lsp/diagnostic.lua | 4 +++- runtime/lua/vim/lsp/util.lua | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 6a7dc1bbb0..03d7121caa 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -1202,6 +1202,8 @@ function M.set_loclist(opts) local open_loclist = if_nil(opts.open_loclist, true) + local win_id = vim.api.nvim_get_current_win() + local bufnr = vim.api.nvim_get_current_buf() local buffer_diags = M.get(bufnr, opts.client_id) @@ -1234,7 +1236,7 @@ function M.set_loclist(opts) table.sort(items, function(a, b) return a.lnum < b.lnum end) - util.set_loclist(items) + util.set_loclist(items, win_id) if open_loclist then vim.cmd [[lopen]] end diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index a986bd6f81..d442f9424c 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1599,8 +1599,8 @@ end --- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|. --- --@param items (table) list of items -function M.set_loclist(items) - vim.fn.setloclist(0, {}, ' ', { +function M.set_loclist(items, win_id) + vim.fn.setloclist(win_id or 0, {}, ' ', { title = 'Language Server'; items = items; }) -- cgit