From 5c40f3e86a81f78f821b8c75dafc3ce2ce67e1c5 Mon Sep 17 00:00:00 2001 From: tom-anders <13141438+tom-anders@users.noreply.github.com> Date: Sat, 4 May 2024 10:13:08 +0200 Subject: [PATCH] feat(lsp): support vim.lsp.ListOpts.loclist in location_handler() --- runtime/doc/news.txt | 3 +++ runtime/lua/vim/lsp/handlers.lua | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index ed994472ac..60cc3c48a4 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -266,6 +266,9 @@ The following new APIs and features were added. respective capability can be unset. • |vim.lsp.start()| accepts a "silent" option for suppressing messages if an LSP server failed to start. + • |vim.lsp.buf.definition()|, |vim.lsp.buf.declaration()|, + |vim.lsp.buf.type_definition()|, and |vim.lsp.buf.implementation()| now + support the `loclist` field of |vim.lsp.ListOpts|. • Treesitter • Bundled parsers and queries (highlight, folds) for Markdown, Python, and diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 205de68101..eec16d7298 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -443,8 +443,13 @@ local function location_handler(_, result, ctx, config) util.jump_to_location(result[1], client.offset_encoding, config.reuse_win) return end - vim.fn.setqflist({}, ' ', { title = title, items = items }) - vim.cmd('botright copen') + if config.loclist then + vim.fn.setloclist(0, {}, ' ', { title = title, items = items }) + vim.cmd.lopen() + else + vim.fn.setqflist({}, ' ', { title = title, items = items }) + vim.cmd('botright copen') + end end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration