linux-cultist / venv-selector.nvim

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

Takes more than a minute to show results #127

Closed 80avin closed 1 month ago

80avin commented 1 month ago

This is too slow and searches lot many directories than expected. Example, on my mac I have a python project in /Users/80avin/myproject But it searches everything under /Users directory taking around a minute to get all results.

Issue

While config.settings.parents limits how many level up should we search, there is no limit how much deep. Also, fd appears to iterate almost every path and tests it against the regex.

Suggestions:

  1. Optimize the directory search

    Example, just like find has --prune method which can be used to early return from a directory. Or, add some heuristics to not search in some directories. node_modules is the biggest candidate. .cache, etc might be more.

  2. Either, search only fixed level depth from a parent directory. This may remove the need of config.settings.parents

    Explanation: If the buffer directory is /a/b/c/d/e/f, we should: For every parent directory( /a, /a/b, /a/b/c, /a/b/c/d, /a/b/c/d/e, /a/b/c/d/e/f ), search if <dir>/.venv exists or <dir>/*/.venv. Idea is to limit how much depth to go from <dir>

  3. Refer vscode's implementation to find what to search: https://github.com/microsoft/vscode-python/blob/975010ee14f61c5b9239ee125e57fbfb58f8e963/src/client/interpreter/configuration/interpreterSelector/commands/setInterpreter.ts#L248-L268

linux-cultist commented 1 month ago

Hi,

There is a rewrite of the plugin you should try. :) See the Readme at the top. You can define your own searches very easily if you need in that version and it fixes a lot of edge cases and bugs. I think you will like it.