completions

Use both jedi and prompt_toolkit to aide IPython in generating completions.

The function from this module that will be easiest for end users to utilize is.:

create_pt_completers()[source][source]

Return a MergedCompleter combining all of the public facing completers initialized in this module. This includes all of the concrete prompt_toolkit.completion.Completers as well as subclasses of the abstract base class.

This creates a combination of almost all of prompt_toolkits completion mechanisms and combines them.

combined_completers[source]

A ThreadedCompleter instantiated with a MergedCompleter that combines FuzzyWordCompleter, FuzzyCompleter, PathCompleter, WordCompleter and IPython’s IPythonPTCompleter.

In addition, auto-suggestions are generated in a manner similar to fish from an prompt_toolkit.auto_suggest.AutoSuggestFromHistory instance wrapped in a prompt_toolkit.auto_suggest.ThreadedAutoSuggest instance as this dramatically speeds the completions up.

See Also – prompt_toolkit docs

Prompt Toolkit

More documentation on use of the prompt_toolkit API.

Completions API

class SimpleCompleter(shell=None, completer=None, min_input_len=0, *args, **kwargs)[source][source]

Bases: prompt_toolkit.completion.base.Completer

Building up a customized Completer using the prompt_toolkit API.

Utilizes the min_input_len of the PathCompleter along with adding more necessary dunders and functionally useful fallbacks in case of being called incorrectly, rather adding dozens of assert statements.

__init__(shell=None, completer=None, min_input_len=0, *args, **kwargs)[source][source]
property user_ns[source][source]
property document[source][source]

Instance of prompt_toolkit.document.Document.

get_completions(complete_event, doc=None)[source][source]

For now lets not worry about CompleteEvent too much.

But we will need to add a get_async_completions method.

Todo

Possibly alias this to complete for readline compat.

get_completions_async(document: prompt_toolkit.document.Document, complete_event: prompt_toolkit.completion.base.CompleteEvent) → AsyncGenerator[prompt_toolkit.completion.base.Completion, None][source][source]

Asynchronous generator of completions.

class PathCallable(only_directories: bool = False, get_paths: Optional[Callable[], List[str]]] = None, file_filter: Optional[Callable[[str], bool]] = None, min_input_len: int = 0, expanduser: bool = False)[source][source]

Bases: prompt_toolkit.completion.filesystem.PathCompleter

PathCompleter with __call__ defined.

The superclass PathCompleter is initialized with a set of parameters, and ‘expanduser’ defaults to False.

The ‘expanduser’ attribute is set to True in contrast with the superclass PathCompleter's default; however, that can be overridden in a subclass.

expanduser = True[source]
create_path_completer()[source][source]

Basically took this from Jon’s unit tests.

create_fuzzy_keyword_completer()[source][source]

Return FuzzyWordCompleter initialized with all valid Python keywords.

create_word_completer()[source][source]

Return WordCompleter initialized with all valid Python keywords.

venvs()[source][source]

Use jedi.api.find_virtualenvs and return all values.

class MergedCompleter(completers)[source][source]

Bases: prompt_toolkit.completion.base.Completer

Combine several completers into one.

__init__(completers)[source][source]

His _MergedCompleter class without the asserts.

get_completions(document, complete_event)[source][source]
get_completions_async(document, complete_event)[source][source]

Get all completions from completers in a non-blocking way.

Checks that the completer actually defined this method before calling it so we don’t force the method definition.

class FuzzyCallable(WORD: Optional[bool] = False, pattern: Optional[Pattern[str]] = None, enable_fuzzy: Optional[Union[prompt_toolkit.filters.base.Filter, bool]] = True, meta_dict: Optional[Dict[str, str]] = None, words: Optional[Union[List[str], Callable[], List[str]]]] = None, ignore_case: Optional[bool] = False, sentence: Optional[bool] = False, match_middle: Optional[bool] = False)[source][source]

Bases: prompt_toolkit.completion.fuzzy_completer.FuzzyWordCompleter

A FuzzyCompleter with __call__ defined.

__init__(WORD: Optional[bool] = False, pattern: Optional[Pattern[str]] = None, enable_fuzzy: Optional[Union[prompt_toolkit.filters.base.Filter, bool]] = True, meta_dict: Optional[Dict[str, str]] = None, words: Optional[Union[List[str], Callable[], List[str]]]] = None, ignore_case: Optional[bool] = False, sentence: Optional[bool] = False, match_middle: Optional[bool] = False)[source][source]

Mostly FuzzyWordCompleter…except callable.

And the superclasses are initialized a little better.

Parameters
  • completer – A Completer instance.

  • WORD – When True, use WORD characters.

  • pattern – Regex pattern which selects the characters before the cursor that are considered for the fuzzy matching.

  • enable_fuzzy – (bool or Filter) Enabled the fuzzy behavior. For easily turning fuzzyness on or off according to a certain condition.

  • words – List of words or callable that returns a list of words.

  • ignore_case – If True, case-insensitive completion.

  • meta_dict – Optional dict mapping words to their meta-text. (This should map strings to strings or formatted text.)

  • WORD – When True, use WORD characters.

  • sentence – When True, don’t complete by comparing the word before the cursor, but by comparing all the text before the cursor. In this case, the list of words is just a list of strings, where each string can contain spaces. (Can not be used together with the WORD option.)

  • match_middle – When True, match not only the start, but also in the middle of the word.

get_completions(document, complete_event)[source][source]
create_jedi_script()[source][source]

Initialize a jedi.Script with the prompt_toolkit.default_buffer.document.

create_pt_completers()[source][source]

Return a combination of all the completers in this module.

Still needs to factor in magic completions before its officially integrated into the rest of the app.