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

Custom entry maker fails with warning "table index is nil" #3374

Open
jzbyers opened this issue Dec 3, 2024 · 3 comments
Open

Custom entry maker fails with warning "table index is nil" #3374

jzbyers opened this issue Dec 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@jzbyers
Copy link

jzbyers commented Dec 3, 2024

Description

I have a custom entry maker for listing functions and methods in Go programs, and it fails with a "table index is nil" error coming from the lua/telescope/sorters.lua program.

Here's the configuration I'm using:

function ListFunctionsAndMethods()
  require('telescope.builtin').lsp_document_symbols({
    symbols = { 'function', 'method' },
    entry_maker = function(entry)
      local formatted = string.format("%s [line %d]", entry.text, entry.lnum)
      return {
        value = entry.text,
        valid = true,
        ordinal = entry.text,
        display = formatted,
        lnum = entry.lnum,
        kind = entry.kind,
        col = entry.col,
        filename = entry.filename,
      }
    end
  })
end


vim.api.nvim_set_keymap('n', '<leader>lf', 
  ":lua ListFunctionsAndMethods()<CR>", 
  { noremap = true, silent = true }
)

Here's the warning message I see in Neovim:

[telescope] [WARN  15:04:47] /Users/jzbyers/.local/share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:498: Finder failed with msg:  ...share/nvim/lazy/telescope.nvi
m/lua/telescope/sorters.lua:597: table index is nil

Neovim version

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1727870382

Operating system and version

macOS 15.1

Telescope version / branch / rev

telescope 0.1.8

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
- OK fd: found fd 10.2.0

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

Steps to reproduce

  1. Add a mapping to trigger this function:
function ListFunctionsAndMethods()
  require('telescope.builtin').lsp_document_symbols({
    symbols = { 'function', 'method' },
    entry_maker = function(entry)
      local formatted = string.format("%s [line %d]", entry.text, entry.lnum)
      return {
        value = entry.text,
        valid = true,
        ordinal = entry.text,
        display = formatted,
        lnum = entry.lnum,
        kind = entry.kind,
        col = entry.col,
        filename = entry.filename,
      }
    end
  })
end


vim.api.nvim_set_keymap('n', '<leader>lf', 
  ":lua ListFunctionsAndMethods()<CR>", 
  { noremap = true, silent = true }
)
  1. Open any Go program (or any program with functions, for that matter).

  2. Use the mapping you setup or just call the function yourself: :lua ListFunctionsAndMethods()

  3. You will probably see nothing. Check :messages to see any warnings:

[telescope] [WARN  15:16:08] /Users/jzbyers/.local/share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:498: Finder failed with msg:  ...share/nvim/lazy/telescope.nvi
m/lua/telescope/sorters.lua:597: table index is nil

Expected behavior

I expect the finder to be populated with results

Actual behavior

The finder is empty because Telescope failed to sort the table results

Minimal config

function ListFunctionsAndMethods()
  require('telescope.builtin').lsp_document_symbols({
    symbols = { 'function', 'method' },
    entry_maker = function(entry)
      local formatted = string.format("%s [line %d]", entry.text, entry.lnum)
      return {
        value = entry.text,
        valid = true,
        ordinal = entry.text,
        display = formatted,
        lnum = entry.lnum,
        kind = entry.kind,
        col = entry.col,
        filename = entry.filename,
      }
    end
  })
end


vim.api.nvim_set_keymap('n', '<leader>lf', 
  ":lua ListFunctionsAndMethods()<CR>", 
  { noremap = true, silent = true }
)
@jzbyers jzbyers added the bug Something isn't working label Dec 3, 2024
@jzbyers
Copy link
Author

jzbyers commented Dec 3, 2024

FWIW, things work when I don't use a custom entry_maker:

vim.api.nvim_set_keymap('n', '<leader>lf', 
  ":lua require('telescope.builtin').lsp_document_symbols({ symbols={'function', 'method'} })<CR>", 
  { noremap = true, silent = true }
)
Screenshot 2024-12-03 at 3 28 10 PM

The reason why I want the custom entry_maker is so I can format the results the way I want (the function and method names often get cutoff by the symbol kind).

@Conni2461
Copy link
Member

does it work if value = entry?

@jzbyers
Copy link
Author

jzbyers commented Dec 4, 2024

does it work if value = entry?

Sadly, no. Same error as before:

[telescope] [WARN  11:16:09] /Users/jzbyers/.local/share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:498: Finder failed with msg:  ...share/nvim/lazy/telescope.nvim/lua/telescope/sorters.lua:597: table index is nil

I'm using vim.notify to debug and I'm seeing entries...

Here's the config I'm using:

function ListFunctionsAndMethods()
  require('telescope.builtin').lsp_document_symbols({
    symbols = { 'function', 'method' },
    entry_maker = function(entry)
      vim.notify(vim.inspect(entry), vim.log.levels.DEBUG)
      local formatted = string.format("%s [line %d]", entry.text, entry.lnum)
      return {
        value = entry,
        valid = true,
        ordinal = entry.text,
        display = formatted,
        lnum = entry.lnum,
        kind = entry.kind,
        col = entry.col,
        filename = entry.filename,
      }
    end
  })
end


vim.api.nvim_set_keymap('n', '<leader>lf', 
  ":lua ListFunctionsAndMethods()<CR>", 
  { noremap = true, silent = true }
)

And here's what notify outputs:

{
  bufnr = 1,
  col = 6,
  filename = "/Users/jzbyers/src/github.com/odentech/goden/cmd/filestorageproxy/main.go",
  kind = "Function",
  lnum = 19,
  text = "[Function] main"
}

But the results are still empty and I'm getting the same error I posted above.

Screenshot 2024-12-04 at 11 26 52 AM

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

2 participants