Skip to content
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

Bug: Telescope lsp_document_symbols errors out #3380

Open
dpetka2001 opened this issue Dec 6, 2024 · 0 comments
Open

Bug: Telescope lsp_document_symbols errors out #3380

dpetka2001 opened this issue Dec 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@dpetka2001
Copy link

Description

When you do :lua require("telescope.builtin").lsp_document_symbols({symbols = {"Class"}}) in a file that has no such symbols then you get error

[telescope.filter_symbols]: class symbol(s) were not part of the query results                                              
Error executing vim.schedule lua callback: vim/shared.lua:0: t: expected table, got nil                                     
stack traceback:                                                                                                            
        [C]: in function 'error'                                                                                            
        vim/shared.lua: in function 'validate'                                                                              
        vim/shared.lua: in function 'tbl_isempty'                                                                           
        ...o/plugins/telescope.nvim/lua/telescope/builtin/__lsp.lua:364: in function 'handler'                              
        ...re/bob/nightly/share/nvim/runtime/lua/vim/lsp/client.lua:669: in function ''                                     
        vim/_editor.lua: in function <vim/_editor.lua:0>         

That means that we get up to this point in this function, thus we get the warning and then the error. Since, the function doesn't explicitly return anything after these 2 warnings happen, it should implicitly return nil, thus the error we get.

Returning an empty table between lines 182-183 return {} or changing this line to locations = utils.filter_symbols(locations, opts, symbols_sorter) or {} seems to solve the error.

Not familiar with Telescope codebase overall and fairly new to programming, so I'm not sure which the best implementation is and if what I proposed in the previous paragraph might result to some other side-effects, so I'll just leave it up to you how to best solve this situation.

Neovim version

NVIM v0.11.0-dev-1295+gbf5c1346c5
Build type: RelWithDebInfo
LuaJIT 2.1.1732813678

Operating system and version

Linux Mint 21.3

Telescope version / branch / rev

commit 2eca9ba

checkhealth telescope

telescope:                                              health#telescope#check

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 14.1.1 (rev 4649aa9700)
- OK fd: found fd 10.2.0

===== Installed extensions ===== ~

Steps to reproduce

Run the minimal config with nvim -u minimal.lua and after you open a file (I opened minimal.lua myself) and did :lua require("telescope.builtin").lsp_document_symbols({symbols = {"Class"}}) and I got the error I described.

Expected behavior

Should not error.

Actual behavior

Errors with

Error executing vim.schedule lua callback: vim/shared.lua:0: t: expected table, got nil                                     
stack traceback:                                                                                                            
        [C]: in function 'error'                                                                                            
        vim/shared.lua: in function 'validate'                                                                              
        vim/shared.lua: in function 'tbl_isempty'                                                                           
        ...o/plugins/telescope.nvim/lua/telescope/builtin/__lsp.lua:364: in function 'handler'                              
        ...re/bob/nightly/share/nvim/runtime/lua/vim/lsp/client.lua:669: in function ''                                     
        vim/_editor.lua: in function <vim/_editor.lua:0>         

Minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	{
		"neovim/nvim-lspconfig",
	},
	{
		"williamboman/mason.nvim",
		opts = {},
	},
	{
		"williamboman/mason-lspconfig.nvim",
		opts = {
			ensure_installed = {
				"lua_ls",
			},
		},
	},
	{
		"nvim-treesitter/nvim-treesitter",
		opts = {
			ensure_installed = { "lua" },
		},
		config = function(_, opts)
			require("nvim-treesitter.configs").setup(opts)
		end,
	},
	{
		"nvim-telescope/telescope.nvim",
		dependencies = {
			"nvim-lua/plenary.nvim",
		},
		config = function()
			-- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
			require("telescope").setup({})
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})
require("lspconfig").lua_ls.setup {}
@dpetka2001 dpetka2001 added the bug Something isn't working label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant