Skip to content

Add container name to lsp symbol entry #3447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

benjiwolff
Copy link

@benjiwolff benjiwolff commented Apr 13, 2025

Description

worspace/symbol returns context information (containerName) for each symbol (see spec).
However, neovims symbols_to_items ignores containerName, so we add it manually to the picker entry.

This is the smallest change required to use the existing lsp_dynamic_workspace_symbols picker and friends with a custom entry_maker, that includes containerName.

I am new to this codebase and don't know the reason behind using symbols_to_items. It returns vim.quickfix.entry[] which seems inappropriate for workspace/symbols. Maybe, it could be dropped altogether.

Fixes #2695

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update ❓

How Has This Been Tested?

I used the following custom entry_maker with seblyng/roslyn.nvim.

custom entry_maker M.workspace_symbols = function() telescope_builtin.lsp_dynamic_workspace_symbols({ entry_maker = workspace_symbols_entry_maker, }) end

local lsp_type_highlight;
workspace_symbols_entry_maker = function(entry)
local symbol_type, symbol_name = entry.text:match("%[(.+)%]%s+(.*)")

local displayer = entry_display.create({
	separator = " | ",
	items = {
		{ width = 8 },
		{ width = 10 },
		{ remaining = true },
	},
})

local make_display = function()
	return displayer({
		{ symbol_type:lower(), lsp_type_highlight[symbol_type] },
		symbol_name,
		entry.container_name,
	})
end

return {
	value = entry,
	ordinal = symbol_type,
	display = make_display,
	lnum = entry.lnum,
	col = entry.col,
	filename = entry.filename,
}

end

lsp_type_highlight = {
["Class"] = "TelescopeResultsClass",
["Constant"] = "TelescopeResultsConstant",
["Field"] = "TelescopeResultsField",
["Function"] = "TelescopeResultsFunction",
["Method"] = "TelescopeResultsMethod",
["Property"] = "TelescopeResultsOperator",
["Struct"] = "TelescopeResultsStruct",
["Variable"] = "TelescopeResultsVariable",
}

image

Configuration:

  • Neovim version (nvim --version):
    NVIM v0.12.0-dev-92+gfece489794
    Build type: RelWithDebInfo
    LuaJIT 2.1.1741730670

  • Operating system and version: macOS 15.3.1

Checklist:

  • My code follows the style guidelines of this project (stylua)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (lua annotations)

@benjiwolff benjiwolff marked this pull request as ready for review April 13, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lsp symbol search show context
1 participant