forked from sriv/SublimeREPL_posh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
completions.py
34 lines (26 loc) · 1.01 KB
/
completions.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
import sublime
import sublime_plugin
class SublimeREPLCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if not view.settings().get("repl"):
return True
from sublimerepl import manager
rv = manager.repl_view(view)
if not rv:
return []
repl = rv.repl
if not repl.autocomplete_available():
return []
line = view.line(locations[0])
start = max(line.begin(), rv._output_end)
end = line.end()
whole_line = view.substr(sublime.Region(start, end))
pos_in_line = locations[0] - start
whole_prefix = whole_line[:pos_in_line]
completions = repl.autocomplete_completions(
whole_line=whole_line,
pos_in_line=pos_in_line,
prefix=prefix,
whole_prefix=whole_prefix,
locations=locations)
return completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS