Open famzah opened 3 years ago
I'm having the same issue, but for a different reason: my commands start with a special character.
I'm pretty sure your fix is not the correct solution. From the doc of the WordCompleter
class:
:param pattern: Optional compiled regex for finding the word before
the cursor to complete. When given, use this regex pattern instead of
default one (see document._FIND_WORD_RE)
So in effect your regex is completely defeating the _FIND_WORD_RE
regex, which is probably too permissive.
What I'm doing right now is just monkey patching document
at the top of my code, and adjusting document._FIND_WORD_RE
:
import prompt_toolkit.document as document
document._FIND_WORD_RE = re.compile(r"([a-zA-Z0-9_" + COMMAND_LEADER + r"]+|[^a-zA-Z0-9_\s]+)")
Still not a perfect regex, but better.
It would be very helpful to be able to pass arguments to NestedCompleter
that would be passed on to the WordCompleter
instance -- neither one of the cases discussed in this issue seem too crazy, and it would be nice to have a little more control.
If I have the word "multi-test", for example, auto-completion treats the dash "-" as a whitespace separator. It won't continue after "multi".
To fix this I used the following patch:
I don't know if this is a correct fix but it works for me.
If this is the correct solution, then maybe you can add this as an argument in __init__().