Skip to content

Error with get_venvs at scan_dir #52

@tmwatchanan

Description

@tmwatchanan

When I call pick_venv, I get the following error message:

E5108: Error executing lua: .../neovim/HEAD-9952957/share/nvim/runtime/lua/vim/iter.lua:251: flatten() requires an array-like table
stack traceback:
        [C]: in function 'error'
        .../neovim/HEAD-9952957/share/nvim/runtime/lua/vim/iter.lua:251: in function 'flatten'
        /tmp/lazy/plenary.nvim/lua/plenary/compat.lua:6: in function 'flatten'
        /tmp/lazy/plenary.nvim/lua/plenary/scandir.lua:155: in function 'scan_dir'
        /tmp/lazy/swenv.nvim/lua/swenv/api.lua:101: in function 'get_venvs_for'
        /tmp/lazy/swenv.nvim/lua/swenv/api.lua:167: in function 'get_venvs'
        /tmp/lazy/swenv.nvim/lua/swenv/api.lua:176: in function 'pick_venv'
        /Users/watchanan.c/dev/foo/minimal.lua:16: in function </Users/watchanan.c/dev/foo/minimal.lua:16>

Is it only me that has this issue?

Neovim

NVIM v0.12.0-dev-5275+g99529577cc-Homebrew
Build type: Release
LuaJIT 2.1.1741730670

Minimal repro

local lazypath = '/tmp/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system { 'git', 'clone', '--filter=blob:none', 'https://github.com/folke/lazy.nvim.git', '--branch=stable', lazypath }
end
vim.opt.rtp:prepend(lazypath)
vim.opt.termguicolors = true

require('lazy').setup({
    { 'nvim-lua/plenary.nvim', },
    {
        'AckslD/swenv.nvim',
        config = function()
        end,
        keys = function()
            return {
                { '<space>pe', function() require('swenv.api').pick_venv() end, mode = 'n' },
            }
        end,
    },
}, { root = '/tmp/lazy' })

Solution

At least, my quick solution is to fix where Path objects are passed to the get_venvs_for function, for instance,

local get_conda_base_path = function()
  local conda_exe = vim.fn.getenv('CONDA_EXE')
  if conda_exe == vim.NIL then
    return nil
  else
-   return Path:new(conda_exe):parent():parent() / 'envs'
+   return (Path:new(conda_exe):parent():parent() / 'envs').filename
  end
end

Not sure whether others found this same issue. If this is the actual solution, I'm happy to help create a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions