forked from wuub/SublimeREPL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
completions.py
41 lines (30 loc) · 1.2 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
35
36
37
38
39
40
41
from __future__ import absolute_import, unicode_literals, print_function, division
import sublime
import sublime_plugin
class SublimeREPLCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
try:
from .sublimerepl import manager
except ValueError:
from sublimerepl import manager
if not view.settings().get("repl"):
return True
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