This repository was archived by the owner on May 25, 2019. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathjscompletions.py
53 lines (45 loc) · 1.98 KB
/
jscompletions.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
importsublime, itertools
defjs_disabled():
package_settings=sublime.load_settings('AngularJS-sublime-package.sublime-settings')
returnpackage_settings.get('disable_default_js_completions', False)
defglobal_completions(word=None):
js_completions=sublime.load_settings('AngularJS-js-completions.sublime-settings')
ifjs_disabled():
return []
ifword:
symbol=js_completions.get(word, [])
# in the settings we have strings, instead of a list of completions
# since multiple symbols can have the same set of completions
# which we prefix with '_'
iflen(symbol) andsymbol[0] =='_':
symbol=js_completions.get(symbol, [])
return [tuple(completion) forcompletioninlist(symbol)]
else:
return [tuple(completion) forcompletioninlist(js_completions.get('js_completions', []))]
defin_string_completions(prefix, project_index):
js_completions=sublime.load_settings('AngularJS-js-completions.sublime-settings')
ifjs_disabled():
return []
events= []
injectables_list= []
ifprefix=='$':
events=list(js_completions.get('events', []))
events= [tuple(event) foreventinevents]
injectables=list(js_completions.get('js_completions', []))
# filter out the js_completions list so that we only include
# items prefixed with '$' and use their simple form for the completion
# Also, suffix them with (DI) to signify that they're a Dependency Injection
forinjectableininjectables:
ifinjectable[0][0] =='$':
injectables_list.append((injectable[0] +'(DI)', '\\'+injectable[0].split('\t')[0]))
custom_list=get(('constant', 'factory', 'service', 'value'), project_index)
returnevents+injectables_list+custom_list
defget(type, project_index):
all_defs=project_index.get('definitions')
types= []
forcompletioninall_defs:
ifcompletion[0].startswith(type):
trigger=completion[0].split(': ')[1].replace('.', '_') +'\tAngularJS'
result=completion[0].split(': ')[1]
types.append((trigger, result))
returnlist(set(types))