linux-cultist / venv-selector.nvim

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

add hidden venvs in workspace path to default config #115

Closed smorokin closed 1 month ago

smorokin commented 1 month ago

Some people prefer hiding their virtual env directories.

linux-cultist commented 1 month ago

This is actually again a very good usecase for the new regexp branch of the plugin I'm working on. Since you can write your own fd queries in that one, you can make it work exactly how you need. You can check out the Readme and try the branch if you like. It works well for Linux and Mac users at this point I believe, but more work is ongoing to support windows properly as well.

smorokin commented 1 month ago

@linux-cultist do you think it's a bad idea to have hidden files included by default? I would love to have this, since it would mean that I don't have to configure anything at all.

linux-cultist commented 1 month ago

I think maybe the default should not be to force fd to parse hidden files. Often in a workspace, there is a git repository or other hidden files, and then fd would have to go through all of those when looking for venvs. It would make the search slower for everyone who doesn't have hidden venvs.

Sometimes people also have stuff like .vscode or .idea folders with even more hidden files to go through. But that's why the regexp code is written so you can override this behavior how you want. But it does require a bit of config though.

I will add to the Readme how you can override the existing search with your own later today since it's a very good thing to document. :)

smorokin commented 1 month ago

Yes, you are right. Especially the .git folder is a huge problem. Will wait for the documentation!

linux-cultist commented 1 month ago

Its actually really easy to override the build-in searches:

If you look in the https://github.com/linux-cultist/venv-selector.nvim/blob/regexp/lua/venv-selector/config.lua file, you see the default searches.

If you want to override one of them, just create a search with the same name. So to override the workspace search with what you wanted:

settings = {
  search = {
    workspace = {
      command = "fd '/bin/python$' $WORKSPACE_PATH --full-path --color never -E /proc -unrestricted",
    }
  }
}

And thats it. :)

Just run it in a command prompt first to make sure it seems to list what you want, replacing $WORKSPACE_PATH with your project folder path. You can also use $CWD to make the plugin search whatever working directory you are in.

linux-cultist commented 1 month ago

After thinking about this some more, I changed the default behavior to search for hidden files in current working directory and the workspace dirs. Because even if its slightly slower, its more useful to users if their venvs show up without configuration. And if users feel like the plugin is too slow, they can change the default search very easily. Most will probably be OK with it not being instant.

So thanks for this idea, appreciate it. :)

If you try the plugin now without config, it should find all venvs in your project directory and below.

smorokin commented 1 month ago

Thank you @linux-cultist, it just works now!

P.S.: You could also add rye to the list of supported package managers.

linux-cultist commented 1 month ago

Sure, should be easy to to. Thanks for responding, always nice to get feedback so I know things are working as they should. :)

linux-cultist commented 1 month ago

I think rye just creates ordinary venvs under the project directory so they should be found without doing anything. Let me know if you have any issues. :)

smorokin commented 1 month ago

Yes, rye works very well with venv-selector. I meant that you could add it to the list so people will see that it is supported.

linux-cultist commented 1 month ago

Oh yes, makes sense. :)