linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
378 stars 40 forks source link

windows conda_prefix error #116

Closed qanyue closed 1 month ago

qanyue commented 1 month ago
    local conda_base_path_std = string.gsub(config.settings.anaconda_base_path, '/', '\\')
    local conda_envs_path_std = string.gsub(config.settings.anaconda_envs_path, '/', '\\')
    local is_conda_base = string.find(venv_path_std, conda_base_path_std)
    local is_conda_env = string.find(venv_path, conda_envs_path_std)
    if is_conda_base == 1 or is_conda_env == 1 then
      vim.fn.setenv('CONDA_PREFIX', venv_path)
    else
      vim.fn.setenv('VIRTUAL_ENV', venv_path)
    end
  else
    vim.fn.setenv('VIRTUAL_ENV', venv_path)
  end

in venv.lua :118. due to anaconda_base_path will be empty ,string.find will always return 1 at the beginning of the string, which could be the cause the is_conda always equal to 1 . here is a solution. I know you are wring a new branch, May be you can change it .

if vim.fn.has 'win32' == 1 then
  local venv_path_std = string.gsub(venv_path, '/', '\\')
  local conda_base_path_std = string.gsub(config.settings.anaconda_base_path, '/', '\\')
  local conda_envs_path_std = string.gsub(config.settings.anaconda_envs_path, '/', '\\')

  -- Check if it starts with the Conda base path
  local is_conda_base = (string.sub(venv_path_std, 1, #conda_base_path_std) == conda_base_path_std)
  -- Check if it starts with the Conda environments path
  local is_conda_env = (string.sub(venv_path_std, 1, #conda_envs_path_std) == conda_envs_path_std)

  if is_conda_base or is_conda_env then
    vim.fn.setenv('CONDA_PREFIX', venv_path)
  else
    vim.fn.setenv('VIRTUAL_ENV', venv_path)
  end
else
  vim.fn.setenv('VIRTUAL_ENV', venv_path)
end
linux-cultist commented 1 month ago

Thank you, I can add it to the existing code.

I think the code sample above is a good example why a rewrite was needed. All those special cases to handle different paths, they all go away when users can write their own fd queries.

I'm working on windows support right now in the regexp branch and I think it will be ready soon. I installed windows in a virtual machine and added neovim there so I can properly test it.

qanyue commented 1 month ago

thanks for your job