@@ -72,6 +72,29 @@ def add_indexes_to_cache(self, indexes):
72
72
j_data .write (json .dumps (self .projects_index_cache ))
73
73
j_data .close ()
74
74
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
+
75
98
def alert (self , status_message ):
76
99
sublime .status_message ('AngularJS: %s' % status_message )
77
100
@@ -83,13 +106,13 @@ def completions(self, view, prefix, locations, is_inside_tag):
83
106
if is_inside_tag :
84
107
pt = locations [0 ] - len (prefix ) - 1
85
108
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
+
93
116
return (attrs , 0 )
94
117
95
118
def convertDirectiveToTagCompletion (directive ):
@@ -99,9 +122,9 @@ def convertDirectiveToTagCompletion(directive):
99
122
return directive .replace ('="$1"$0' ,'' )+ '${1:($2)}$0'
100
123
if not is_inside_tag :
101
124
if not ng .isST2 :
102
- if (view .substr (view .sel ()[0 ].b - 1 ) == '<' ): return
125
+ if (view .substr (view .sel ()[0 ].b - 1 ) == '<' ): return []
103
126
if ng .isST2 :
104
- if (view .substr (view .sel ()[0 ].b - 1 ) != '<' ): return
127
+ if (view .substr (view .sel ()[0 ].b - 1 ) != '<' ): return []
105
128
in_scope = False
106
129
107
130
for scope in ng .settings .get ('component_defined_scopes' ):
@@ -114,12 +137,15 @@ def convertDirectiveToTagCompletion(directive):
114
137
completions += [
115
138
(directive [0 ], convertDirectiveToTagCompletion (directive [1 ])) for directive in self .add_indexed_directives ()
116
139
]
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' , []))]
118
142
return (completions , 0 )
119
143
else :
120
144
return []
121
145
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
+
123
149
# pulled lots from html_completions.py
124
150
SEARCH_LIMIT = 500
125
151
search_start = max (0 , pt - SEARCH_LIMIT - len (prefix ))
@@ -167,6 +193,8 @@ def filter_completions(self):
167
193
return []
168
194
169
195
def add_indexed_directives (self ):
196
+ if ng .settings .get ('disable_indexed_directive_completions' ): return []
197
+
170
198
try :
171
199
indexes = ng .get_current_project_indexes ().get ('definitions' )
172
200
except :
@@ -220,7 +248,7 @@ class AngularJSEventListener(sublime_plugin.EventListener):
220
248
global ng
221
249
222
250
def on_query_completions (self , view , prefix , locations ):
223
- if ng .settings .get ('disable_plugin ' ):
251
+ if ng .settings .get ('disable_all_completions ' ):
224
252
return []
225
253
if ng .settings .get ('show_current_scope' ):
226
254
print (view .scope_name (view .sel ()[0 ].a ))
@@ -373,7 +401,7 @@ def run(self):
373
401
# no selection has been made
374
402
# so begin expanding to find word
375
403
if not region .size ():
376
- definition = self .find_word (region )
404
+ definition = ng .find_word (region )
377
405
else :
378
406
definition = self .active_view .substr (region )
379
407
@@ -387,10 +415,11 @@ def run(self):
387
415
for item in ng .get_current_project_indexes ().get ('definitions' ):
388
416
if (re .search ('. ' + definition + '$' , item [0 ])):
389
417
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 ]))
391
419
return
392
420
ng .alert ('definition "%s" could not be found' % definition )
393
421
422
+
394
423
class AngularjsGoToDocumentationCommand (sublime_plugin .WindowCommand ):
395
424
396
425
global ng
@@ -406,7 +435,7 @@ def run(self):
406
435
# no selection has been made
407
436
# so begin expanding to find word
408
437
if not region .size ():
409
- definition = self .find_word (region )
438
+ definition = ng .find_word (region )
410
439
else :
411
440
definition = self .active_view .substr (region )
412
441
@@ -420,29 +449,6 @@ def run(self):
420
449
421
450
webbrowser .open ('http://docs.angularjs.org/api/ng.directive:' + definition )
422
451
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
-
446
452
447
453
class AngularJSThread (threading .Thread ):
448
454
0 commit comments