-
Notifications
You must be signed in to change notification settings - Fork 74
/
main.py
58 lines (43 loc) · 2.09 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sublime, sublime_plugin
import string
class PleasurazyAPICompletionsPackage():
def init(self):
self.api = {}
self.settings = sublime.load_settings('sbc-setting.sublime-settings')
self.API_Setup = self.settings.get('completion_active_list')
# Caching completions
if self.API_Setup:
for API_Keyword in self.API_Setup:
self.api[API_Keyword] = sublime.load_settings('sbc-api-' + API_Keyword + '.sublime-settings')
# Caching extended completions(deprecated)
if self.settings.get('completion_active_extend_list'):
for API_Keyword in self.settings.get('completion_active_extend_list'):
self.api[API_Keyword] = sublime.load_settings('sbc-api-' + API_Keyword + '.sublime-settings')
# In Sublime Text 3 things are loaded async, using plugin_loaded() callback before try accessing.
pleasurazy = PleasurazyAPICompletionsPackage()
if int(sublime.version()) < 3000:
pleasurazy.init()
else:
def plugin_loaded():
global pleasurazy
pleasurazy.init()
class PleasurazyAPICompletionsPackageEventListener(sublime_plugin.EventListener):
global pleasurazy
def on_query_completions(self, view, prefix, locations):
self.completions = []
for API_Keyword in pleasurazy.api:
# If completion active
if (pleasurazy.API_Setup and pleasurazy.API_Setup.get(API_Keyword)) or (pleasurazy.settings.get('completion_active_extend_list') and pleasurazy.settings.get('completion_active_extend_list').get(API_Keyword)):
scope = pleasurazy.api[API_Keyword].get('scope')
if scope and view.match_selector(locations[0], scope):
self.completions += pleasurazy.api[API_Keyword].get('completions')
if not self.completions:
return []
# extend word-completions to auto-completions
compDefault = [view.extract_completions(prefix)]
compDefault = [(item, item) for sublist in compDefault for item in sublist if len(item) > 3]
compDefault = list(set(compDefault))
completions = list(self.completions)
completions = [tuple(attr) for attr in self.completions]
completions.extend(compDefault)
return (completions)