otavioschwanck/telescope-alternate.nvim

Error when running Telescope telescope-alternate command

dbolson opened this issue · 1 comments

I'm excited for this plugin to speed up my workflow and hope I can get it working properly.

I get this error when I run Telescope telescope-alternate for a *.go file to open its corresponding *_test.go file:

Error executing Lua callback: ...ny/.vim/plugged/telescope.nvim/lua/telescope/command.lua:193: attempt to call a nil value
stack traceback:
        ...ny/.vim/plugged/telescope.nvim/lua/telescope/command.lua:193: in function 'run_command'
        ...ny/.vim/plugged/telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
        ...s/danny/.vim/plugged/telescope.nvim/plugin/telescope.lua:109: in function <...s/danny/.vim/plugged/telescope.nvim/plugin/telescope.lua:108>

Here's my setup:

local telescope = require("telescope")
telescope.setup {
    extensions = {
        ["telescope-alternate"] = {
            mappings = {
                {
                    "(.*).go",
                    {
                        {
                            "[1]_test.go",
                            "Test",
                            true,
                        },
                    },
                },
                {
                    "(.*)_test.go",
                    {
                        {
                            "[1].go",
                            "Other",
                            true,
                        },
                    },
                },
            },
        },
    },
}
telescope.load_extension("telescope-alternate")

Looking at telescope.nvim/lua/telescope/command.lua#L193, it expects cmd to have the same name in the extensions[cmd] table, so in this case . I believe it's set when you register the extension with telescope. I updated the telescope code that gets it working:

if rawget(extensions, cmd) then
    -- cmd = "telescope-alternate"
    -- extensions[cmd] = {["alternate_file"] = function: 0x0101715e48,}
    if cmd == "telescope-alternate" then
      -- this works
      extensions[cmd]["alternate_file"](opts)
      return
    end

    extensions[cmd][cmd](opts)
    return
end

I also was able to get it working when updating the telescope-alternate code:

return require("telescope").register_extension {
    setup = require("telescope-alternate").setup,
    exports = {
        -- update the key name
        ["telescope-alternate"] = require("telescope-alternate.telescope").alternate,
    },
}

Do I get this error because my setup is wrong, or does the "alternate_file" key need to change to "telescope-alternate"?

I'm excited for this plugin to speed up my workflow and hope I can get it working properly.

The full command is:
:Telescope telescope-alternate alternate_file

Not:
Telescope telescope-alternate

i've planed to create new commands, like go to last alternation, etc. So the telescope has two arguments.

I Recommend to add this to a keybinding.