forked from xjsender/haoide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletions.py
More file actions
757 lines (633 loc) · 36.2 KB
/
completions.py
File metadata and controls
757 lines (633 loc) · 36.2 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
import sublime
import sublime_plugin
import os
import re
import json
from . import context
from . import util
from .salesforce import xmltodict
from .salesforce.lib import apex
from .salesforce.lib import vf
from .salesforce.lib import html
from .salesforce.lib import bootstrap
from .salesforce.lib.panel import Printer
def load_sobject_cache(reload_cache=False, username=None):
""" Reload component cache in globals()
"""
if reload_cache or "metadata" not in globals():
if not username:
username = context.get_setting("username")
metadata = util.get_sobject_metadata(username)
globals()["metadata"] = metadata
return globals()["metadata"]
class PackageCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], "text.xml"):
return []
# Check whether current file is package file
pattern = "<types>[\s.*<>\-\w/\%1-9]+</types>"
if not view.find_all(pattern): return
location = locations[0]
pt = locations[0] - len(prefix) - 1
ch = view.substr(sublime.Region(pt, pt + 1))
variable_name = view.substr(view.word(pt-1))
# Get plugin settings
settings = context.get_settings()
completion_list = []
describe_metadata = util.get_described_metadata(settings)
if not describe_metadata:
if settings["debug_mode"]:
print ("You must execute describe_metadata command before have completion")
return completion_list
metadata_objects = describe_metadata["metadataObjects"]
# <name></name> completion
full_line = view.full_line(pt)
if "<name>" in view.substr(full_line):
for mo in metadata_objects:
display = "%s\t%s" % (mo["xmlName"], "Metadata Type")
completion_list.append((display, mo["xmlName"]))
# Get all Children
childXmlNames = mo.get("childXmlNames", [])
if isinstance(childXmlNames, str):
childXmlNames = [childXmlNames]
for child in childXmlNames:
display = "%s\t%s" % (child, mo["xmlName"])
completion_list.append((display, child))
return completion_list
# <members></members> completion
elif "<members>" in view.substr(full_line):
# Check whether package cache is exist in `.config/package.json`
package_cache = util.get_package_info(settings)
if not package_cache:
message = "No completion before reload_project_cache"
Printer.get("error").write(message)
return completion_list
matched_region = view.find("<name>\\w+</name>", full_line.begin())
if not matched_region: return []
matched_content = view.substr(matched_region)
meta_type = matched_content[6:-7].strip()
# List all members in `.config/package.json`
if meta_type in package_cache:
for member in package_cache[meta_type]:
completion_list.append(("%s\t%s" % (member, meta_type), member))
return (completion_list, sublime.INHIBIT_WORD_COMPLETIONS or sublime.INHIBIT_EXPLICIT_COMPLETIONS)
class ApexCompletions(sublime_plugin.EventListener):
""" There are two type of completions:
1. Keyword Completion, including Standard Class Names, Custom Class Names and All Sobject Names
2. Method and Properties Completion of Apex Standard Class and Custom Class
3. Sobject Completion, e.g.
2.1 Field Completion, including fields, parentRelationships and childRelationships
2.2 Picklist Value Completion
2.3 Fields of parentRelationships
2.4 SOQL Field List Completion
"""
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], "source.java"):
return []
location = locations[0]
pt = locations[0] - len(prefix) - 1
ch = view.substr(sublime.Region(pt, pt + 1))
variable_name = view.substr(view.word(pt-1))
# Get plugin settings
settings = context.get_settings()
username = settings["username"]
# In order to speed up code completion,
# store the "metadata" into globals()
metadata = load_sobject_cache(username=username)
# Get sobjects describe and symbol tables
sobjects_describe = metadata.get("sobjects", {})
parentRelationships = metadata.get("parentRelationships", {})
symbol_tables = util.get_symbol_tables(username)
completion_list = []
if ch not in [".", "="]:
if not settings["disable_keyword_completion"]:
# Check whether has SOQL Completion
is_between_start_and_from = False
if not settings["disable_soql_field_completion"]:
matched_region, is_between_start_and_from, sobject_name =\
util.get_soql_match_region(view, pt)
if not is_between_start_and_from:
# Add namespace to keyword completions
for namespace in apex.apex_namespaces:
completion_list.append(("%s\tNameSpace" % namespace, namespace))
# Add all object name to keyword completions
for key in sorted(sobjects_describe.keys()):
sobject_name = sobjects_describe[key]["name"]
completion_list.append((sobject_name + "\tSobject", sobject_name))
# Add all standard class to keyword completions
for key in sorted(apex.apex_completions):
class_attrs = apex.apex_completions[key]
if isinstance(class_attrs, dict):
completion_list.append(("%s\t%s" % (class_attrs["name"],
class_attrs["namespace"]), class_attrs["name"]))
elif isinstance(class_attrs, list):
for class_attr in class_attrs:
completion_list.append(("%s\t%s" % (class_attr["name"],
class_attr["namespace"]), class_attr["name"]))
# Add all custom class to keyword completions
apex_class_completion = util.get_component_completion(username, "ApexClass")
if apex_class_completion:
completion_list.extend(apex_class_completion)
return completion_list
# SOQL Field List Completion
if ch == " ":
if not settings["disable_soql_field_completion"]:
matched_region, is_between_start_and_from, sobject_name = util.get_soql_match_region(view, pt)
if not is_between_start_and_from or not sobject_name: return []
matched_soql = view.substr(matched_region)
# Check whether there has fields completions
if sobject_name.lower() in sobjects_describe:
sobject_describe = sobjects_describe.get(sobject_name.lower())
# Find all matched parent-to-child query in this view
matches = view.find_all("\(\s*SELECT([\s\S]+?)\)", sublime.IGNORECASE)
child_relationship_name = None
is_cursor_in_child_query = False
for m in matches:
# This child query is not in the whole soql region
if not matched_region.contains(m):
continue
# Cursor point is not located in this child soql region
if not m.contains(pt):
continue
# Cursor point is in child query
is_cursor_in_child_query = True
# Cursor point is not located between select and from
if variable_name.lower() == "from":
continue
ms = view.substr(m)
from_pos = ms.lower().find("from")
pos_of_space_after_from = ms.find(" ", from_pos+6)
child_relationship_name = ms[from_pos+5:pos_of_space_after_from].strip()
# There have three criteria when cursor point is different:
# 1. SELECT (SELECT FROM <CursorPoint> ORDER BY Name ASC) FROM Account
# - Just display parent to child relationship names
#
# 2. SELECT (SELECT Id, <CursorPoint> FROM Opportunities) FROM Account
# - Display fields and parent relationship names for child sObject
#
# 3. SELECT Id, <CursorPoint>, (SELECT Id FROM Opportunities), <CursorPoint> FROM Account
# - Display fields and parent relationship names for parent sObject
if not child_relationship_name:
if is_cursor_in_child_query:
# Just display child relationship names
completion_list = util.get_sobject_completion_list(
sobject_describe,
display_fields=False,
display_parent_relationships=False
)
else:
# Display all
completion_list = util.get_sobject_completion_list(
sobject_describe,
display_child_relationships=False
)
else:
childRelationships = sobject_describe.get("childRelationships")
if child_relationship_name in childRelationships:
child_sobject_name = childRelationships[child_relationship_name]
if child_sobject_name.lower() in sobjects_describe:
completion_list = util.get_sobject_completion_list(
sobjects_describe.get(child_sobject_name.lower()),
prefix=child_sobject_name+".",
display_child_relationships=False
)
return (completion_list, sublime.INHIBIT_WORD_COMPLETIONS or sublime.INHIBIT_EXPLICIT_COMPLETIONS)
elif ch == ".":
# Input Page., list all custom ApexPages
if variable_name.lower() == 'page':
return util.get_component_completion(username, "ApexPage")
# Get the variable type by variable name
pattern = "([a-zA-Z_1-9]+[\\[\\]]*|(map+|list|set)[^\\n^(][<,.\\s>a-zA-Z_1-9]+)\\s+%s[,;\\s:=){]" % variable_name
variable_type = util.get_variable_type(view, pt, pattern)
variable_type = variable_type.lower()
if not settings["disable_fields_completion"]:
if variable_type.lower() in sobjects_describe:
sobject_name = variable_type.lower()
elif variable_name.lower() in sobjects_describe:
sobject_name = variable_name.lower()
else:
sobject_name = ""
if sobject_name != "" and sobject_name in sobjects_describe:
sobject_describe = sobjects_describe.get(sobject_name)
completion_list = util.get_sobject_completion_list(sobject_describe)
# If variable_name is not empty, show the methods extended from sobject
if variable_type:
methods = apex.apex_completions["sobject"]["methods"]
for key in sorted(methods.keys()):
completion_list.append(("Sobject." + key, methods[key]))
if not completion_list and not settings["disable_relationship_completion"]:
# Because relationship name is not unique, so we need to display sobject name prefix
matched_sobjects = parentRelationships.get(variable_name, [])
if len(matched_sobjects) == 1:
sobject_name = matched_sobjects[0].lower()
if sobject_name in sobjects_describe:
completion_list = util.get_sobject_completion_list(
sobjects_describe[sobject_name],
display_child_relationships=False
)
else:
for sobject in matched_sobjects:
if sobject.lower() not in sobjects_describe:
continue
completion_list.extend(util.get_sobject_completion_list(
sobjects_describe[sobject.lower()],
prefix=sobject+".",
display_child_relationships=False)
)
# Add standard class in specified namespace to completions
if variable_name in apex.apex_namespaces:
for standard_class in apex.apex_namespaces[variable_name]:
completion_list.append(("%s\t%s" % (standard_class, variable_name), standard_class))
# Check whether variable is standard class
if variable_type.lower() in apex.apex_completions:
class_name = variable_type.lower()
elif variable_name.lower() in apex.apex_completions:
class_name = variable_name.lower()
else:
class_name = None
# If variable is standard class
if class_name:
class_attrs = apex.apex_completions[class_name]
if isinstance(class_attrs, dict):
class_attr = class_attrs
# Get the methods by class_name
methods = class_attr["methods"]
for key in sorted(methods.keys()):
completion_list.append((key, methods[key]))
# Get the properties by class_name
properties = class_attr["properties"]
if isinstance(properties, dict):
for key in sorted(properties.keys()):
completion_list.append((key if "\t" in key else (key + "\tProperty"), properties[key]))
elif isinstance(class_attrs, list):
for class_attr in class_attrs:
# Get the methods by class_name
methods = class_attr["methods"]
for key in sorted(methods.keys()):
left = "%s.%s.%s" % (class_attr["namespace"], class_attr["name"], key)
right = methods[key]
completion_list.append((left, right))
# Get the properties by class_name
properties = class_attr["properties"]
if isinstance(properties, dict):
for key in sorted(properties.keys()):
left = "%s.%s.%s\tProperty" % (class_attr["namespace"], class_attr["name"], key)
right = properties[key]
completion_list.append((left, right))
else:
try:
# Check whether inner class property completion
matched_region = view.find_all("[a-zA-Z_1-9]+\\.[a-zA-Z_1-9]+\\s+%s[,;\\s:=){]" % variable_name)
if matched_region:
matched_str = view.substr(matched_region[0])
namespace, innerclass = matched_str[:matched_str.find(" ")].split(".")
if namespace.lower() in symbol_tables:
inners = symbol_tables[namespace.lower()]["inners"]
# Sometimes, the inner class name is same with standard class or sObject
# if this inner class is matched, ignore the standard completion
if innerclass.lower() in inners:
completion_list = []
for key in inners[innerclass.lower()]:
completion_list.append((key, inners[innerclass.lower()][key]))
# Not inner class completion
else:
if variable_name.lower() in symbol_tables:
outer = symbol_tables[variable_name.lower()]["outer"]
elif variable_type.lower() in symbol_tables:
outer = symbol_tables[variable_type.lower()]["outer"]
else:
outer = None
# Call Custom Class from different class
if outer:
for key in sorted(outer):
completion_list.append((key, outer[key]))
# Call Inner Class in the same class
elif view.file_name():
attributes = util.get_file_attributes(view.file_name())
namespace = attributes["name"]
if namespace and namespace.lower() in symbol_tables:
inners = symbol_tables[namespace.lower()]["inners"]
if variable_type.lower() in inners:
inner = inners[variable_type.lower()]
for key in sorted(inner):
completion_list.append((key, inner[key]))
except KeyError as ke:
pass
elif ch == "=":
if not settings["disable_picklist_value_completion"]:
# Get the row and col of current point
cursor_row, cursor_col = view.rowcol(pt)
# Get all matched regions
matched_regions = view.find_all("([a-zA-Z_1-9]+\\.[a-zA-Z_1-9]+)")
# Get the nearest matched region from start to end
# for example, matched regions by above pattern are :
# [(4, 24), (28, 57), (76, 96), (100, 129)]
# If the second one has the same row with cursor point, so it
# will be chosen as the right matched region
matched_region = None
for mr in matched_regions:
row, col = view.rowcol(mr.begin())
if cursor_row == row:
matched_region = mr
if not matched_region:
return []
variable_name, field_name = view.substr(matched_region).split(".")
# Get Sobject Name
pattern = "([a-zA-Z_1-9]+[\\[\\]]*|(map+|list|set)[^\\n^(][<,.\\s>a-zA-Z_1-9]+)\\s+%s[,;\\s:=){]" % variable_name
variable_type = util.get_variable_type(view, pt, pattern)
variable_type = variable_type.lower()
# Get sobject describe
if variable_type.lower() in sobjects_describe:
sobject_name = variable_type.lower()
elif variable_name.lower() in sobjects_describe:
sobject_name = variable_name.lower()
else:
sobject_name = ""
sobject_describe = sobjects_describe.get(sobject_name)
# Get sobject picklist field describe
if not sobject_describe:
return []
if field_name not in sobject_describe["picklist_fields"]:
return []
picklist_values = sobject_describe["picklist_fields"][field_name]
completion_list = []
for pv in picklist_values:
completion_list.append(("%s(%s)\t%s" % (
pv["value"], pv["label"], field_name
), " '%s'" % pv["value"]
))
return completion_list
class PageCompletions(sublime_plugin.EventListener):
""" There are two kinds of completion, Visualforce and Html
Visualforce Lib is based on Mavensmate
Html Lib is based on EMMET
1. input <, list all Tags of Visualforce and Html
2. input :, list suffix of all Visualforce Components
3. input space, list all attributes of tags, if tag attribute has predefined values,
output attr, otherwise, output attr="$1"
4. input =, list all values of this corresponding attribute
"""
def on_query_completions(self, view, prefix, locations):
# Only trigger within HTML
if not view.match_selector(locations[0], "text.html - source"):
return []
# Get plugin settings
settings = context.get_settings()
username = settings["username"]
pt = locations[0] - len(prefix) - 1
ch = view.substr(sublime.Region(pt, pt + 1))
next_char = view.substr(sublime.Region(pt + 2, pt + 3))
variable_name = view.substr(view.word(pt-1))
begin = view.full_line(pt).begin()
# In order to speed up code completion,
# store the "metadata" into globals()
metadata = load_sobject_cache(username=username)
sobjects_describe = metadata.get("sobjects", {})
completion_list = []
if ch in ["<", ":"]:
# Check whether tag has ending, for example,
# `<apex:page />` has ending, `<apex:page` doesn't have
tag_has_ending = False
for mr in view.find_all("<\w[\s\S]+?>"):
if mr.contains(pt):
tag_has_ending = True
if ch == "<":
# Visualforce Standard Components
for tag in sorted(vf.tag_defs):
attr = vf.tag_defs[tag]
completion_list.append((tag + "\t%s" % attr["type"],
tag if tag_has_ending else (tag + "$1>")))
# Custom Component
completion_list.extend(util.get_component_completion(username, "ApexComponent"))
# Html Elements
for tag in sorted(html.HTML_ELEMENTS_ATTRIBUTES):
completion_list.append((tag + "\thtml",
tag if tag_has_ending else (tag + "$1>")))
completion_list.sort(key=lambda tup:tup[1])
elif ch == ":":
# Just Visualforce Component contains :
matched_tag_prefix = view.substr(view.word(pt))
# If tag prefix 'c', list all custom components
if matched_tag_prefix == "c":
return util.get_component_completion(username, "ApexComponent")
# Combine components
tag_names = {}
for tag_name in vf.tag_defs:
tag_prefix, tag_suffix = tuple(tag_name.split(':'))
if tag_prefix in tag_names:
tag_names[tag_prefix].append(tag_suffix)
else:
tag_names[tag_prefix] = [tag_suffix]
# If it's not valid tag prefix, just return
if not matched_tag_prefix in tag_names:
return []
# Populate completion list
for tag_name in tag_names[matched_tag_prefix]:
completion_list.append((tag_name + "\t" + matched_tag_prefix,
tag_name if tag_has_ending else (tag_name + "$1>")))
elif ch == " ":
# Get the begin point of current line
cursor_row, cursor_col = view.rowcol(pt)
##########################################
# Visualforce Attribute Completions
##########################################
if not settings["disable_component_attribute_completion"]:
# Get the two chars after course point
# If these two chars is '="', it means attribute value is already exist
# we will not add ="{!}" or ="" for this attribute
forward_two_chars = view.substr(sublime.Region(pt + 2, pt + 4))
# Get all matched regions
matched_regions = view.find_all("<\w+:\w+[\s\S]*?>")
# Choose the matched one that contains cursor point
matched_region = None
for mr in matched_regions:
if mr.contains(pt):
matched_region = mr
break
if matched_region:
matched_tag = view.substr(matched_region).split(" ")[0][1:].strip()
# Combine the attr of matched visualforce tag
if matched_tag in vf.tag_defs:
def_entry = vf.tag_defs[matched_tag]
for key, value in def_entry['attribs'].items():
display = "%s\t%s" % (key, value['type'])
# Has value completion
if "values" in value or value["type"] == "Boolean" or forward_two_chars == '="':
completion_list.append((display, key))
continue
if value["type"] in ["Object", "ApexPages.Action"]:
completion_list.append((display, key+'="{!$1}"$0'))
else:
completion_list.append((display, key+'="$1"$0'))
##########################################
# Custom Component Attribute Completions
##########################################
# Get all matched regions
if not settings["disable_custom_component_completion"]:
matched_regions = view.find_all("<c:\\w+")
# Get the nearest matched region from start to end
# for example, matched regions by above pattern are :
# [(4, 24), (28, 57), (76, 96), (100, 129)]
# the cursor point is int the next or same row
# with the second one, so that one is the exact one
matched_region = None
for mr in matched_regions:
row, col = view.rowcol(mr.begin())
if cursor_row == row or cursor_row == row + 1:
matched_region = mr
if matched_region:
matched_tag = view.substr(matched_region)[1:]
tag_name = matched_tag.split(":")[1].strip()
completion_list.extend(util.get_component_attributes(settings, tag_name))
##########################################
# HTML Element Attribute Completions
##########################################
if not settings["disable_html_completion"]:
# Get all matched regions
matched_regions = view.find_all("<\w+\s+[\s\S]*?>")
# Get the nearest matched region from start to end
# for example, matched regions by above pattern are :
# [(4, 24), (28, 57), (76, 96), (100, 129)]
# the cursor point is int the next or same row
# with the second one, so that one is the exact one
matched_region = None
for mr in matched_regions:
if mr.contains(pt):
matched_region = mr
# If matched region is found and matched block contains cursor point
if matched_region:
matched_tag = view.substr(matched_region)[1:].split(" ")[0].strip()
if matched_tag in html.HTML_ELEMENTS_ATTRIBUTES:
def_entry = html.HTML_ELEMENTS_ATTRIBUTES[matched_tag]
for attr_name in sorted(def_entry):
if attr_name in html.HTML_ATTRIBUTES_VALUES and html.HTML_ATTRIBUTES_VALUES[attr_name]:
completion_list.append((attr_name + "\tattr", attr_name))
else:
completion_list.append((attr_name + "\tattr", attr_name+'="$1"$0'))
# ##########################################
# Bootstrap3 class name completions
##########################################
if not settings["disable_bootstrap_completion"]:
matched_attribute_regions = view.find_all('\w+="[\w\s\-]*"')
for mr in matched_attribute_regions:
if not mr.contains(pt): continue
className = view.substr(mr).split("=")[0]
if className.lower() in ["styleclass", "class"]:
for className in bootstrap.classes:
completion_list.append(("%s\tBootstrap3" % className, className))
break
# Sort the completion_list by first element
completion_list.sort(key=lambda tup:tup[1])
elif ch == "=":
##########################################
# Visualforce Attribute Values Completions
##########################################
if not settings["disable_component_attribute_value_completion"]:
matched_regions = view.find_all("<\w+:\w+[\s\S]*?>")
matched_region = None
for mr in matched_regions:
if mr.contains(pt):
matched_region = mr
if matched_region:
# Get the Tag Name and Tag Attribute Name
matched_tag = view.substr(matched_region)[1:]
matched_tag = matched_tag.split(" ")[0].strip()
matched_attr_name = view.substr(view.word(pt-1))
# Get the Attribute Values
if matched_tag in vf.tag_defs and matched_attr_name in vf.tag_defs[matched_tag]["attribs"]:
tag_attribute = vf.tag_defs[matched_tag]["attribs"][matched_attr_name]
# If attr type boolean, add {!} to it
if tag_attribute["type"] == "Boolean":
completion_list.append(("{!}" + "\t" + matched_attr_name, '"{!$1}"$0'))
completion_list.append(("true" + "\t" + matched_attr_name, '"true"$0'))
completion_list.append(("false" + "\t" + matched_attr_name, '"false"$0'))
if "values" in tag_attribute:
for value in tag_attribute["values"]:
completion_list.append((value + "\t" + matched_attr_name, '"%s"' % value))
return completion_list
##########################################
# HTML Element Attribute Values Completions
##########################################
if not settings["disable_html_completion"]:
matched_attr_name = view.substr(view.word(pt-1))
if matched_attr_name in html.HTML_ATTRIBUTES_VALUES:
for attr_value in html.HTML_ATTRIBUTES_VALUES[matched_attr_name]:
completion_list.append((attr_value + "\t" +
matched_attr_name, '"%s"' % attr_value))
# Sort the completion_list by first element
completion_list.sort(key=lambda tup:tup[1])
if ch in ['"']:
# 1. sObject completion for standardController
pattern = "<\\w+:\\w+\\s+standardController=\"\\w+\""
matched_region = view.find(pattern, begin, sublime.IGNORECASE)
if matched_region and matched_region.contains(pt):
for key in sorted(sobjects_describe.keys()):
sobject_name = sobjects_describe[key]["name"]
completion_list.append((sobject_name + "\tSobject", sobject_name))
# 2. Custom class completion for extension or controller
matched_region = view.find('(controller="\\w+"|extensions="\\w+")', begin)
if matched_region and matched_region.contains(pt):
apex_class_completion = util.get_component_completion(username, "ApexClass")
completion_list.extend(apex_class_completion)
# 3. Add page completion
attr_name = variable_name
if attr_name in vf.page_reference_attrs:
apex_class_completion = util.get_component_completion(username, "ApexPage")
completion_list.extend(apex_class_completion)
# 4. Bootstrap3 class name completions
if not settings["disable_bootstrap_completion"]:
matched_attribute_regions = view.find_all('\w+="[\w\s\-]*"')
for mr in matched_attribute_regions:
if not mr.contains(pt): continue
className = view.substr(mr).split("=")[0]
if className.lower() == "class":
for className in bootstrap.classes:
completion_list.append(("%s\tBootstrap3" % className, className))
break
# Completions for component interface, for example,
# e.g. force:appHostable, force:lightningQuickAction
if ch in ['"', ',', ' ']:
matched_region = view.find('(implements="[\\w\\s:\\,]+")', begin)
if matched_region and matched_region.contains(pt):
completion_list = []
for _interface in vf.component_interfaces:
completion_list.append((_interface, _interface))
if ch == ".":
################################################################
# Custom label completion, which is fetched form <project cache>
################################################################
if variable_name.lower() == "label":
package_cache = util.get_package_info(settings)
if "CustomLabel" in package_cache:
for member in package_cache["CustomLabel"]:
completion_list.append(("%s\t%s" % (member, "CustomLabel"), member))
return completion_list
################################################################
# Extension or Controller creation after # with specified pattern
################################################################
if not view.file_name():
return completion_list
# Get the name of controller or extension
pattern = '\\s+(controller="\\w+"|extensions="\\w+")'
matched_regions = view.find_all(pattern)
if not matched_regions:
return completion_list
controller_name = view.substr(matched_regions[0]).split('"')[1]
# Get the classes path
base, filename = os.path.split(view.file_name())
src, path = os.path.split(base)
controller_path = os.path.join(src, "classes", controller_name+".cls")
if not os.path.isfile(controller_path): return completion_list
# Get the variable type in the respective controller
# and then show the field list of variable type
with open(controller_path, "rb") as fp:
content = fp.read()
# Page Variable Completion
pattern = "[a-zA-Z_1-9]+\\s+%s[,;\\s:=){]" % variable_name
match = re.compile(pattern.encode("utf-8"), re.IGNORECASE).search(content)
if match and match.group():
variable_type = match.group().decode("utf-8").split(" ")[0]
if variable_type.lower() in sobjects_describe:
sobject_describe = sobjects_describe.get(variable_type.lower())
completion_list = util.get_sobject_completion_list(sobject_describe)
return completion_list