From 8b5d8dfc732eff3a7ba1cc25d6e5b7c210f761a4 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Tue, 22 Jul 2025 10:30:16 -0700 Subject: [PATCH] fix(lsp): support `containerName` in symbol requests #35029 The field is present for SymbolInformation and WorkspaceSymbol. --- runtime/doc/lsp.txt | 2 +- runtime/lua/vim/lsp/util.lua | 11 ++++++++--- test/functional/plugin/lsp_spec.lua | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index df7452679e..c7098bc9af 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -2681,7 +2681,7 @@ symbols_to_items({symbols}, {bufnr}, {position_encoding}) Converts symbols to quickfix list items. Parameters: ~ - • {symbols} (`lsp.DocumentSymbol[]|lsp.SymbolInformation[]`) + • {symbols} (`lsp.DocumentSymbol[]|lsp.SymbolInformation[]|lsp.WorkspaceSymbol[]`) list of symbols • {bufnr} (`integer?`) buffer handle or 0 for current, defaults to current diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 28d00d6cd3..8188af99d9 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1867,7 +1867,7 @@ end --- Converts symbols to quickfix list items. --- ----@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[] list of symbols +---@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[]|lsp.WorkspaceSymbol[] list of symbols ---@param bufnr? integer buffer handle or 0 for current, defaults to current ---@param position_encoding? 'utf-8'|'utf-16'|'utf-32' --- default to first client of buffer @@ -1907,8 +1907,13 @@ function M.symbols_to_items(symbols, bufnr, position_encoding) local is_deprecated = symbol.deprecated or (symbol.tags and vim.tbl_contains(symbol.tags, protocol.SymbolTag.Deprecated)) - local text = - string.format('[%s] %s%s', kind, symbol.name, is_deprecated and ' (deprecated)' or '') + local text = string.format( + '[%s] %s%s%s', + kind, + symbol.name, + symbol.containerName and ' in ' .. symbol.containerName or '', + is_deprecated and ' (deprecated)' or '' + ) items[#items + 1] = { filename = filename, diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index a88d00afaa..68db45006c 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3328,7 +3328,7 @@ describe('LSP', function() filename = '/test_a', kind = 'File', lnum = 2, - text = '[File] TestA', + text = '[File] TestA in TestAContainer', }, { col = 1, @@ -3337,7 +3337,7 @@ describe('LSP', function() filename = '/test_b', kind = 'Module', lnum = 4, - text = '[Module] TestB', + text = '[Module] TestB in TestBContainer (deprecated)', }, } eq( @@ -3364,7 +3364,7 @@ describe('LSP', function() containerName = 'TestAContainer', }, { - deprecated = false, + deprecated = true, kind = 2, name = 'TestB', location = {