Support case-insensitive completion
Continued from #139. My comment:
I feel like the choices completer (and probably the others too) should not filter their results and defer to the validator to do the filtering. As it stands, if I want to do something like case-insensitive completion, I have to override the choices completer because the results are already filtered before they get to the validator. Or am I misunderstanding the purpose of the validator?
@kislyuk's response:
@evanunderscore, the choices completer is presented as an example. The validator was added to this architecture after I first designed it, so I'm treating it as a general purpose filtering step. One of its functions is to filter the completions by prefix. The completer may also do so, for example if filtering will reduce the amount of work done (like when requesting completions from a remote API). Case insensitive completion is not generally supported. If you want it supported, please open another issue. We'll need to update the docs, think about how to communicate case insensitivity to completers, and add a CaseInsensitiveValidator.
In the simple case, filtering completions in the completer itself is generally an unnecessary step and actually results in more work when the validator is run over already filtered results. ChoicesCompleter and EnvironCompleter could just return self.choices and os.environ respectively. This way, specifying validator=lambda completion, prefix: completion.lower().startswith(prefix.lower()) is enough to make these case-insensitive.
FilesCompleter and DirectoriesCompleter are a bit trickier and serve as good examples of where this isn't so straightforward. Also mentioned was cases where completions are being queried from a remote API.
I don't really have a pressing need for this but I'm interested to see if other people want this or have ideas on how it could work.
In bash, I've used bind 'set completion-ignore-case on' for a long time and I love it. It feels much more natural. I've wanted this feature in argcomplete, but before I ran across this post, I didn't know how to turn it on. I turned it on by calling autocomplete with the validator= argument as you mentioned above. Excellent!