linux-cultist / venv-selector.nvim

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

Add ability to activate venv without running lsp server #138

Open igrikus opened 4 weeks ago

igrikus commented 4 weeks ago

I work with projects that don't even contain Python files, but still I need venv (ansible, awscli are mostly installed via pip)

On the old version I had a startup function that activated cached venv, and I could use CLI tools directly from the nvim terminal

On the new version I have to open (create) a temporary python file for the same logic. This doesn't work for me at all :(

igrikus commented 4 weeks ago

This is my auto-activation code from old version, just for reference:

vim.api.nvim_create_autocmd("VimEnter", {
  desc = "Auto select virtualenv Nvim open",
  pattern = "*",
  callback = function()
    local venv = vim.fn.finddir("venv", vim.fn.getcwd())
    if venv ~= "" then
      require("venv-selector").retrieve_from_cache()
    end
  end,
  once = true,
})
linux-cultist commented 4 weeks ago

Oh I see. There are always usecases I dont consider out there. :)

The new version automatically sets the terminal paths and activates the venv for the vim.fn.getcwd() but only if a python file is opened, like you said.

But it would be nice if the plugin was more flexible and set the terminal paths from a cached venv if there is one. It could skip the activation of the lsp if there is no python file opened and do everything else.

I will have a look at the code and see what can be done.