nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.45k stars 823 forks source link

Error on open telescope find file => attempt to upvalue 'flatten' (a nil value) #3187

Closed sfwnisme closed 2 months ago

sfwnisme commented 2 months ago

Description

I'am using neovim with lazy.nvim package manager. the keymap I set for find_file is vim.keymap.set("n", "<C-p>", builtin.find_files, {})

sometimes I face this error and not showing the find_file


E5108: Error executing lua: ...im/lazy/telescope.nvim/lua/telescope/builtin/__files.lua:295: attempt to call upvalue 'flatten' (a nil value)
stack traceback:
        ...im/lazy/telescope.nvim/lua/telescope/builtin/__files.lua:295: in function 'v'
        ...im/lazy/telescope.nvim/lua/telescope/builtin/__files.lua:595: in function 'v'
        ...cker/start/telescope.nvim/lua/telescope/builtin/init.lua:542: in function <...cker/start/telescope.nvim/lua/telescope/builtin/init.lua:501>

you can check may config for nvim in this repo

Neovim version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1716656478
Run "nvim -V1 -v" for more info

Operating system and version

windows 11 with wsl2

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 ~
- ERROR rg: not found. `live-grep` finder will not function without [BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) installed.
- WARNING fd: not found. Install [sharkdp/fd](https://github.com/sharkdp/fd) for extended capabilities

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

Telescope Extension: `ui-select` ~
- No healthcheck provided

Steps to reproduce

return {
    {
        -- plugin: telescope-ui-select.nvim
        -- function: display vim.lsp.buf.code_action() in floating telescope
        -- src: https://github.com/nvim-telescope/telescope-ui-select.nvim
        "nvim-telescope/telescope-ui-select.nvim",
    },
    {
        -- plugin: nvim-telescope
        -- function: files finder and filter
        -- src: https://github.com/nvim-telescope/telescope.nvim
        "nvim-telescope/telescope.nvim",
        tag = "0.1.8",
        -- or                              , branch = '0.1.x',
        -- defaults = { file_ignore_patterns = { ".git", "node_modules", ".cache" } },
        dependencies = { "nvim-lua/plenary.nvim" },
        config = function()
            require("telescope").setup({
                extensions = {
                    ["ui-select"] = {
                        require("telescope.themes").get_dropdown({}),
                    },
                },
            })
            local builtin = require("telescope.builtin")
            vim.keymap.set("n", "<C-p>", builtin.find_files, {})
            vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
            vim.keymap.set("n", "<leader><leader>", builtin.oldfiles, {})

            require("telescope").load_extension("ui-select")
        end,
    },
}

Expected behavior

the extended behavior is opening the file finder on its regular shape

Actual behavior

it shows me the following error and cant use the file finder feature


E5108: Error executing lua: ...im/lazy/telescope.nvim/lua/telescope/builtin/__files.lua:295: attempt to call upvalue 'flatten' (a nil value)
stack traceback:
        ...im/lazy/telescope.nvim/lua/telescope/builtin/__files.lua:295: in function 'v'
        ...im/lazy/telescope.nvim/lua/telescope/builtin/__files.lua:595: in function 'v'
        ...cker/start/telescope.nvim/lua/telescope/builtin/init.lua:542: in function <...cker/start/telescope.nvim/lua/telescope/builtin/init.lua:501>

Minimal config

init.lua

-- lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("options")
require("lazy").setup("plugins")

return {
    {
        -- plugin: telescope-ui-select.nvim
        -- function: display vim.lsp.buf.code_action() in floating telescope
        -- src: https://github.com/nvim-telescope/telescope-ui-select.nvim
        "nvim-telescope/telescope-ui-select.nvim",
    },
    {
        -- plugin: nvim-telescope
        -- function: files finder and filter
        -- src: https://github.com/nvim-telescope/telescope.nvim
        "nvim-telescope/telescope.nvim",
        tag = "0.1.8",
        -- or                              , branch = '0.1.x',
        -- defaults = { file_ignore_patterns = { ".git", "node_modules", ".cache" } },
        dependencies = { "nvim-lua/plenary.nvim" },
        config = function()
            require("telescope").setup({
                extensions = {
                    ["ui-select"] = {
                        require("telescope.themes").get_dropdown({}),
                    },
                },
            })
            local builtin = require("telescope.builtin")
            vim.keymap.set("n", "<C-p>", builtin.find_files, {})
            vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
            vim.keymap.set("n", "<leader><leader>", builtin.oldfiles, {})

            require("telescope").load_extension("ui-select")
        end,
    },
}
jamestrew commented 2 months ago

Please try this 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 = {
  {
    "nvim-telescope/telescope.nvim",
    tag = "0.1.8",
    dependencies = { "nvim-lua/plenary.nvim" },
    config = function()
      require("telescope").setup({})
      local builtin = require("telescope.builtin")
      vim.keymap.set("n", "<C-p>", builtin.find_files, {})
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

save this somewhere and start neovim with nvim -u minimal.lua

I'm not able to replicate this and I'm not even sure how this error is possible without some broken telescope installation.

sfwnisme commented 2 months ago

@jamestrew thank you, but it seems due to the previous package manager I used 'packer', after I deleted it every thing work fine. At all I switched to LazyVim.