NestedCompleter doesn't work if there is a dash in the word

Open
#1,280 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Start in prompt_toolkit/completion/nested.py, focusing on NestedCompleter's WordCompleter call and its handling of the current document. Reproduce completion for the example "multi-test" and compare the proposed pattern change with existing behavior. Done means hyphenated words continue completing without breaking other nested completion cases.

Written by the indexing model from the issue text.

Description

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:

--- /usr/local/lib/python3.7/dist-packages/prompt_toolkit/completion/nested.py  2020-10-23 19:54:59.873439073 +0000
+++ NestedCompleterFixed.py     2020-10-25 14:40:35.306087935 +0000
@@ -7,6 +7,8 @@
 from prompt_toolkit.completion.word_completer import WordCompleter
 from prompt_toolkit.document import Document
 
+import re
+
 __all__ = ["NestedCompleter"]
 
 # NestedDict = Mapping[str, Union['NestedDict', Set[str], None, Completer]]
@@ -103,7 +105,8 @@
         # No space in the input: behave exactly like `WordCompleter`.
         else:
             completer = WordCompleter(
-                list(self.options.keys()), ignore_case=self.ignore_case
+                list(self.options.keys()), ignore_case=self.ignore_case,
+                pattern=re.compile(r'.*') # or else "-" breaks the completion
             )
             for c in completer.get_completions(document, complete_event):
                 yield c

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__().

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prompt-toolkit/python-prompt-toolkit

All issues in prompt-toolkit/python-prompt-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.