prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.13k stars 716 forks source link

Allow `sentence=True` in NestedCompleter #1400

Open mmatthebi opened 3 years ago

mmatthebi commented 3 years ago

Given a complete dict like

{ 'a': { 'b.c.d' } }

for NestedCompleter does not allow completing after typing a b., because the WordCompleter for b. doesn't use sentence=True.

Is it possible to have sentence=True as a default or a configuration option?

https://github.com/prompt-toolkit/python-prompt-toolkit/blob/b76946c3d046dfa0a00fee6c393ba1c936f5a435/prompt_toolkit/completion/nested.py#L106

Claudemirovsky commented 2 years ago

A problem I encountered (probably caused by missing sentence=True in NestedCompleter too) is that, in addition to not completing after the first non-letter character, it shows wrong completions.

for example, consider this dict

{
    '/an-option': {'on', 'off'},
    'an-strange-option': {'yes', 'no'},
    'another-option': {'some', 'nested', 'option'}
}

writing / on prompt will show /an-option as expected... but writing /an do not show /an-option and shows instead an-strange and another, and this does not occur in WordCompleter when called with sentence=True.