prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Bug: get_word_before_cursor() doesn't return strings starting with hyphen/s

Open
#1,609 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Consider a simple application as one given below.

from prompt_toolkit.completion import WordCompleter
from prompt_toolkit import prompt

mycompleter = WordCompleter(['-a', '-app', '--apple', '--apricot' ,'build', 'builder', 'buildx'])

text = prompt('prompt: ', completer=mycompleter)
print('You said: %s' % text)

Running the above code and then entering - or -- on the prompt generates completions correctly. However if a alphanumeric character is entered after the hyphen/s no completions are generated. For e.g --a does not cause --apple and --apricot to be displayed.

On testing and debugging I found out that the get_word_before_cursor() function used by WordCompleter does not correctly return the hyphenated words as specified above which causes this issue.

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.

Research direction

Start by tracing WordCompleter to the get_word_before_cursor() function and reproduce the reported behavior with '-', '--', and '--a'. Done means hyphenated words such as --apple and --apricot are returned and displayed as completions when typing their prefixes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.