Skip to content
This repository was archived by the owner on May 25, 2019. It is now read-only.

Commit 99c74d1

Browse files
committed
- Fixes Goto Definition
- Adds grangular control on what types of completions to show
1 parent 7674166 commit 99c74d1

File tree

3 files changed

+83
-49
lines changed

3 files changed

+83
-49
lines changed

AngularJS-sublime-package.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@ def add_indexes_to_cache(self, indexes):
7272
j_data.write(json.dumps(self.projects_index_cache))
7373
j_data.close()
7474

75+
def find_word(self, region):
76+
non_char = re.compile(self.settings.get('non_word_chars'))
77+
look_up_found = ""
78+
start_point = region.end()
79+
begin_point = start_point-1
80+
end_point = start_point+1
81+
82+
while (not non_char.search(self.active_view().substr(sublime.Region(start_point, end_point)))
83+
and end_point):
84+
end_point += 1
85+
while (not non_char.search(self.active_view().substr(sublime.Region(begin_point, start_point)))):
86+
begin_point -= 1
87+
88+
look_up_found = self.active_view().substr(sublime.Region(begin_point+1, end_point-1))
89+
self.alert('Looking up: ' + look_up_found)
90+
return look_up_found
91+
92+
def handle_file_open_go_to(self, line):
93+
if not self.active_view().is_loading():
94+
self.active_view().run_command('goto_line', {'line': line} )
95+
else:
96+
sublime.set_timeout(lambda: self.handle_file_open_go_to(line), 100)
97+
7598
def alert(self, status_message):
7699
sublime.status_message('AngularJS: %s' % status_message)
77100

@@ -83,13 +106,13 @@ def completions(self, view, prefix, locations, is_inside_tag):
83106
if is_inside_tag:
84107
pt = locations[0] - len(prefix) - 1
85108
ch = view.substr(sublime.Region(pt, pt + 1))
86-
if(ch != '<'):
87-
attrs = self.attributes[:]
88-
else:
89-
attrs = []
90-
if ng.settings.get('add_indexed_directives'):
91-
attrs += self.get_attribute_completions(view, prefix, locations, pt)
92-
attrs += self.add_indexed_directives()
109+
110+
if(ch != '<'
111+
and not ng.settings.get('disable_default_directive_completions')): attrs = self.attributes[:]
112+
else: attrs = []
113+
attrs += self.get_isolate_completions(view, prefix, locations, pt)
114+
attrs += self.add_indexed_directives()
115+
93116
return (attrs, 0)
94117

95118
def convertDirectiveToTagCompletion(directive):
@@ -99,9 +122,9 @@ def convertDirectiveToTagCompletion(directive):
99122
return directive.replace('="$1"$0','')+'${1:($2)}$0'
100123
if not is_inside_tag:
101124
if not ng.isST2:
102-
if(view.substr(view.sel()[0].b-1) == '<'): return
125+
if(view.substr(view.sel()[0].b-1) == '<'): return []
103126
if ng.isST2:
104-
if(view.substr(view.sel()[0].b-1) != '<'): return
127+
if(view.substr(view.sel()[0].b-1) != '<'): return []
105128
in_scope = False
106129

107130
for scope in ng.settings.get('component_defined_scopes'):
@@ -114,12 +137,15 @@ def convertDirectiveToTagCompletion(directive):
114137
completions += [
115138
(directive[0], convertDirectiveToTagCompletion(directive[1])) for directive in self.add_indexed_directives()
116139
]
117-
completions += [tuple(element) for element in list(ng.settings_completions.get('angular_elements', []))]
140+
if not ng.settings.get('disable_default_element_completions'):
141+
completions += [tuple(element) for element in list(ng.settings_completions.get('angular_elements', []))]
118142
return (completions, 0)
119143
else:
120144
return []
121145

122-
def get_attribute_completions(self, view, prefix, locations, pt):
146+
def get_isolate_completions(self, view, prefix, locations, pt):
147+
if ng.settings.get('disable_indexed_isolate_completions'): return []
148+
123149
# pulled lots from html_completions.py
124150
SEARCH_LIMIT = 500
125151
search_start = max(0, pt - SEARCH_LIMIT - len(prefix))
@@ -167,6 +193,8 @@ def filter_completions(self):
167193
return []
168194

169195
def add_indexed_directives(self):
196+
if ng.settings.get('disable_indexed_directive_completions'): return []
197+
170198
try:
171199
indexes = ng.get_current_project_indexes().get('definitions')
172200
except:
@@ -220,7 +248,7 @@ class AngularJSEventListener(sublime_plugin.EventListener):
220248
global ng
221249

222250
def on_query_completions(self, view, prefix, locations):
223-
if ng.settings.get('disable_plugin'):
251+
if ng.settings.get('disable_all_completions'):
224252
return []
225253
if ng.settings.get('show_current_scope'):
226254
print(view.scope_name(view.sel()[0].a))
@@ -373,7 +401,7 @@ def run(self):
373401
# no selection has been made
374402
# so begin expanding to find word
375403
if not region.size():
376-
definition = self.find_word(region)
404+
definition = ng.find_word(region)
377405
else:
378406
definition = self.active_view.substr(region)
379407

@@ -387,10 +415,11 @@ def run(self):
387415
for item in ng.get_current_project_indexes().get('definitions'):
388416
if(re.search('. '+definition+'$', item[0])):
389417
self.active_view = ng.active_window().open_file(item[1])
390-
self.handle_file_open_go_to(int(item[2]))
418+
ng.handle_file_open_go_to(int(item[2]))
391419
return
392420
ng.alert('definition "%s" could not be found' % definition)
393421

422+
394423
class AngularjsGoToDocumentationCommand(sublime_plugin.WindowCommand):
395424

396425
global ng
@@ -406,7 +435,7 @@ def run(self):
406435
# no selection has been made
407436
# so begin expanding to find word
408437
if not region.size():
409-
definition = self.find_word(region)
438+
definition = ng.find_word(region)
410439
else:
411440
definition = self.active_view.substr(region)
412441

@@ -420,29 +449,6 @@ def run(self):
420449

421450
webbrowser.open('http://docs.angularjs.org/api/ng.directive:' + definition)
422451

423-
def find_word(self, region):
424-
non_char = re.compile(ng.settings.get('non_word_chars'))
425-
look_up_found = ""
426-
start_point = region.end()
427-
begin_point = start_point-1
428-
end_point = start_point+1
429-
430-
while (not non_char.search(self.active_view.substr(sublime.Region(start_point, end_point)))
431-
and end_point):
432-
end_point += 1
433-
while (not non_char.search(self.active_view.substr(sublime.Region(begin_point, start_point)))):
434-
begin_point -= 1
435-
436-
look_up_found = self.active_view.substr(sublime.Region(begin_point+1, end_point-1))
437-
ng.alert('Looking up: ' + look_up_found)
438-
return look_up_found
439-
440-
def handle_file_open_go_to(self, line):
441-
if not self.active_view.is_loading():
442-
self.active_view.run_command('goto_line', {'line': line} )
443-
else:
444-
sublime.set_timeout(lambda: self.handle_file_open_go_to(line), 100)
445-
446452

447453
class AngularJSThread(threading.Thread):
448454

AngularJS-sublime-package.sublime-settings

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,63 @@
11
{
22
/**
3-
Basic Options
3+
Completion Options
44
**/
55

6+
// turns all completion help off
7+
"disable_all_completions": false,
8+
// turns off completions for indexed directives
9+
"disable_indexed_directive_completions": false,
10+
// turns off completions for directives isolate attributes
11+
"disable_indexed_isolate_completions": false,
12+
// turns off default completions
13+
"disable_default_directive_completions": false,
14+
// turns off default element completions
15+
"disable_default_element_completions": false,
16+
// for future usage
17+
"disable_default_js_completions": false,
18+
619
// flag to add the `data-` prefix to the completions
720
"enable_data_prefix": false,
21+
// flag to add AngularUI directives to completion list
22+
"enable_AngularUI_directives": false,
23+
24+
25+
/**
26+
Indexing Options
27+
**/
828

29+
// AngularJS definitions to search for
30+
"match_definitions": ["controller", "directive", "module", "factory", "filter"],
931
// directories you wish to ignore within your current working directory
1032
"exclude_dirs":[
1133
"node_modules/"
1234
],
13-
1435
// file suffixes to ignore (uses string.endswith(...))
1536
"exclude_file_suffixes":[
1637
"angular.js",
1738
"min.js"
1839
],
1940

20-
// Adds any indexed directives to the completion list
21-
"add_indexed_directives": true,
41+
42+
/**
43+
Quick Panel Options
44+
**/
2245

2346
// Shows preview of file where currently highlighted definition is
2447
// (Only works in Sublime Text 3)
2548
"show_file_preview": true,
2649

27-
// AngularJS definitions to search for
28-
"match_definitions": ["controller", "directive", "module", "factory", "filter"],
2950

30-
// flag to add AngularUI directives to completion list
31-
"enable_AngularUI_directives": false,
51+
/**
52+
Definition Lookup Options
53+
**/
3254

3355
// Characters considered to separate directives (words)
3456
// this is a modified version of what Sublime Text uses by default
3557
// It's modified to allow for - to be considered part of a word
3658
// for cases such as my-new-directive
3759
"non_word_chars": "[\\./\\\\(\\)\"':,;<>~!@#\\$%\\^&\\*\\|\\+=\\[\\]{}`~\\? ]",
3860

39-
// turns completion help off
40-
"disable_plugin": false,
4161

4262

4363

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,15 @@ Completion Settings
165165
Preferences > Package Settings > AngularJS > **Settings - User**
166166
167167
168-
**add_indexed_directives**: bool (true); *bare-bones completion of any directives that have been index*
168+
**disable_all_completions**: false,
169+
170+
**disable_indexed_directive_completions**: false; *bare-bones completion of any directives that have been index*
171+
172+
**disable_indexed_isolate_completions**: false; *attempts to provide isolate scope completions when a directive is used as an element*
173+
174+
**disable_default_directive_completions**: false;
175+
176+
**disable_default_element_completions**: false;
169177
170178
**enable_data_prefix**: bool (false); *adds the 'data-' prefix to attribute completions*
171179

0 commit comments

Comments
 (0)