forked from donnemartin/gitsome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt_toolkit_completer.py
43 lines (37 loc) · 1.71 KB
/
prompt_toolkit_completer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Completer implementation to use with prompt_toolkit."""
from prompt_toolkit.completion import Completer, Completion
from gitsome.completer import CompleterGitsome
class PromptToolkitCompleter(Completer):
"""Simple prompt_toolkit Completer object.
It just redirects requests to normal Xonsh completer.
"""
def __init__(self, completer, ctx):
"""Takes instance of xonsh.completer.Completer and dict with context."""
self.completer = completer
self.completer_gitsome = CompleterGitsome()
self.ctx = ctx
def get_completions(self, document, complete_event):
"""Returns a generator for list of completions."""
line = document.current_line
endidx = document.cursor_position_col
space_pos = document.find_backwards(' ')
if space_pos is None:
begidx = 0
else:
begidx = space_pos + endidx + 1
prefix = line[begidx:endidx]
completions = self.completer.complete(prefix,
line,
begidx,
endidx,
self.ctx)
completions_gitsome = \
self.completer_gitsome.get_completions(document,
complete_event)
completions_with_meta = \
self.completer_gitsome.build_completions_with_meta(line,
prefix,
completions)
completions_gitsome.extend(completions_with_meta)
for comp in completions_gitsome:
yield comp