Open Grokzen opened 1 year ago
I think being able to switch to a different search algorithm would be useful.
I would prefer to not use dependencies. Mostly to make it simple to install: just copy the single Python file.
However, rlselect
already depends on wx
for the --gui
version, but it is not required. I would be fine with this as well. That is, use a dependency for a new search algorithm, but only import it when explicitly specified via RLSELECT_MATCH_ALOG
or similar flag.
I think that since we don't really need to care super much about speed it should be fairly simple to build an algo in a single python method. Non blocking/breaking imports of alternative dependencies if you do not want to make them forced is to wrap them in a try/except and just use a internal feature flag. The other way with a regular setuptools packaging is to use https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies where the installer decides what dependencies to include and what to not include that would open up different choices via env variables.
There is an alternative matching algorithm that is used within SublimeText and possibly VSCode when you run any command or action panel within those applications. The core algorithm that they use is this one https://python-course.eu/applications-python/levenshtein-distance.php and i would like this to be implemented so that we can switch between different modes for a few things. To reconfigure a run with
rlselect
command it would be easiest to use environment variables likeRLSELECT_MATCH_ALGO
eller något sådant namn där man kan byta ut den on-demand.There is plenty of implementations of levenshtein-distance and a suitable and short implementation that do not require any dependencies might be needed to found out somewhere in github. If we had dependencies we might use some pre-built solution.
So the most basic example is the following. I implemented a
find
directories command and pipe:d intorlselect
and right now i we have unordered token matching that in most cases is not the fastest or simplest to type. In SublimeText i would not typein Jo 2
but i would typeinjo2
and it would do a left to right matching with levenshtein-distance and sort them based on the output from it. Also note that with current solution that is unordered, i would not expect to find the last few items as the search order i inputed do not match from left to right, i would not expect the last 3 items to even show up given this alternate solution