Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xjsender/haoide
Browse files Browse the repository at this point in the history
  • Loading branch information
lushang committed Jul 14, 2019
2 parents f6cb37d + 5ae5371 commit c2a8205
Show file tree
Hide file tree
Showing 20 changed files with 4,889 additions and 84 deletions.
39 changes: 23 additions & 16 deletions aura.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from .salesforce.lib.panel import Printer


class OpenAuraDocumentReference(sublime_plugin.WindowCommand):
class OpenLightningDocReferences(sublime_plugin.WindowCommand):
def __init__(self, *args, **kwargs):
super(OpenAuraDocumentReference, self).__init__(*args, **kwargs)
super(OpenLightningDocReferences, self).__init__(*args, **kwargs)

def run(self):
instance = util.get_instance(self.settings)
if instance == "emea": instance = "eu0"
start_url = "https://%s.lightning.force.com/auradocs/reference.app" % instance
start_url = "https://%s.lightning.force.com/docs/component-library" % instance
self.window.run_command("login_to_sfdc", {"startURL": start_url})

def is_enabled(self):
Expand Down Expand Up @@ -47,17 +47,24 @@ def run(self, dirs, switch_project=True, source_org=None, element=None, update_m
}
})

base64_package = util.build_package(dirs)
processor.handle_deploy_thread(base64_package, source_org=source_org, element=element, update_meta=update_meta)
base64_package = util.build_aura_package(dirs, meta_type=element)
processor.handle_deploy_thread(
base64_package,
source_org=source_org,
element=element,
update_meta=update_meta
)

def is_visible(self, dirs, switch_project=True):
if not dirs or len(dirs) == 0: return False
if not dirs or len(dirs) == 0:
return False

self.settings = context.get_settings()
for _dir in dirs:
attributes = util.get_file_attributes(_dir)
metadata_folder = attributes["metadata_folder"]
if metadata_folder != "aura": return False
if metadata_folder not in ["aura", "lwc"]:
return False
if self.settings["default_project_name"] not in _dir:
return False

Expand Down Expand Up @@ -280,9 +287,9 @@ def run(self, _type=""):
self.window.show_input_panel("Please Input %s Name: " % _type,
"", self.on_input, None, None)

def on_input(self, lighting_name):
def on_input(self, lightning_name):
# Create component to local according to user input
if not re.match('^[a-zA-Z]+\\w+$', lighting_name):
if not re.match('^[a-zA-Z]+\\w+$', lightning_name):
message = 'Invalid format, do you want to try again?'
if not sublime.ok_cancel_dialog(message): return
self.window.show_input_panel("Please Input %s Name: " % self._type,
Expand All @@ -295,30 +302,30 @@ def on_input(self, lighting_name):

# Get template attribute
templates = util.load_templates()
template = templates.get("Aura").get(self._type)
template = templates.get("Aura").get(self._type)
with open(os.path.join(workspace, ".templates", template["directory"])) as fp:
body = fp.read()

# Build dir for new lighting component
component_dir = os.path.join(workspace, "src", "aura", lighting_name)
component_dir = os.path.join(workspace, "src", "aura", lightning_name)
if not os.path.exists(component_dir):
os.makedirs(component_dir)
else:
message = "%s is already exist, do you want to try again?" % lighting_name
message = "%s is already exist, do you want to try again?" % lightning_name
if not sublime.ok_cancel_dialog(message, "Try Again?"): return
self.window.show_input_panel("Please Input Lighting Name: ",
"", self.on_input, None, None)
return

lihghting_file = os.path.join(component_dir, lighting_name+template["extension"])
lightning_file = os.path.join(component_dir, lightning_name+template["extension"])

# Create Aura lighting file
with open(lihghting_file, "w") as fp:
with open(lightning_file, "w") as fp:
fp.write(body)

# If created succeed, just open it and refresh project
window = sublime.active_window()
window.open_file(lihghting_file)
window.open_file(lightning_file)
window.run_command("refresh_folder_list")

# Deploy Aura to server
Expand All @@ -330,4 +337,4 @@ def on_input(self, lighting_name):
})

def is_enabled(self):
return util.check_action_enabled()
return util.check_action_enabled()
46 changes: 30 additions & 16 deletions completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def on_query_completions(self, view, prefix, locations):
return []

# Check whether current file is package file
pattern = "<types>[\s.*<>\-\w/\%1-9]+</types>"
pattern = "<types>[\\s.*<>\\-\\w/\\%1-9]+</types>"
if not view.find_all(pattern): return

location = locations[0]
Expand Down Expand Up @@ -181,7 +181,7 @@ def on_query_completions(self, view, prefix, locations):
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)
matches = view.find_all("\\(\\s*SELECT([\\s\\S]+?)\\)", sublime.IGNORECASE)

child_relationship_name = None
is_cursor_in_child_query = False
Expand Down Expand Up @@ -598,7 +598,7 @@ def on_query_completions(self, view, prefix, locations):
if not file_name :
is_lightning = False
else:
is_lightning = True if file_name.split(".")[-1] in ["app", "cmp", "evt"] else False
is_lightning = True if file_name.split(".")[-1] in ["app", "cmp", "evt", "html", "js"] else False

# Get tag definition of Visualforce page or Lightning component
tag_defs = lightning.tag_defs if is_lightning else vf.tag_defs
Expand All @@ -614,15 +614,18 @@ def on_query_completions(self, view, prefix, locations):
# `<apex:page />` has ending, `<apex:page` doesn't have
tag_has_ending = False

for mr in view.find_all("<\w[\s\S]+?>"):
for mr in view.find_all("<\\w[\\s\\S]+?>"):
if mr.contains(pt):
tag_has_ending = True

if ch == "<":
# Standard Lightning/Visualforce Components
for tag in sorted(tag_defs):
attr = tag_defs[tag]
completion_list.append((tag + "\t%s" % attr["type"], tag if tag_has_ending else (tag + "$1>")))
completion_list.append((
tag + "\t%s" % attr["type"],
tag if tag_has_ending else (tag + "$1>")
))

if is_lightning:
# Custom Lightning Component
Expand All @@ -633,12 +636,14 @@ def on_query_completions(self, view, prefix, locations):

# 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.append((
tag + "\thtml",
tag if tag_has_ending else (tag + "$1>")
))

completion_list.sort(key=lambda tup: tup[1])

elif ch == ":":
elif ch in [":", "-"]:
# Just Visualforce and Lightning Component contain prefix/namespace :
matched_tag_prefix = view.substr(view.word(pt))

Expand Down Expand Up @@ -682,7 +687,7 @@ def on_query_completions(self, view, prefix, locations):
forward_two_chars = view.substr(sublime.Region(pt + 2, pt + 4))

# Get all matched regions
matched_regions = view.find_all("<\w+:\w+[\s\S]*?>")
matched_regions = view.find_all("<\\w+[:-]*\\w+[\\s\\S]*?>")

# Choose the matched one that contains cursor point
matched_region = None
Expand All @@ -707,9 +712,18 @@ def on_query_completions(self, view, prefix, locations):

if value["type"] in ["Object", "ApexPages.Action"]:
completion_list.append((display, key+'="{!$1}"$0'))
elif value["type"] in ["TrackObject", "List", "Method"]:
completion_list.append((display, key+'={$1}$0'))
else:
completion_list.append((display, key+'="$1"$0'))

# Add html global functions for LWC
if def_entry["type"] == "lwc":
for method_name in lightning.html_global_methods:
display = "%s\tMethod" % method_name
completion_list.append((display, method_name+'={$1}$0'))


######################################################
# Custom Apex/Lightning Component Attribute Completions
######################################################
Expand Down Expand Up @@ -738,7 +752,7 @@ def on_query_completions(self, view, prefix, locations):
##########################################
if not settings["disable_html_completion"]:
# Get all matched regions
matched_regions = view.find_all("<\w+\s+[\s\S]*?>")
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 :
Expand All @@ -765,7 +779,7 @@ def on_query_completions(self, view, prefix, locations):
# Bootstrap3 class name completions
############################################
if not settings["disable_bootstrap_completion"]:
matched_attribute_regions = view.find_all('\w+="[\w\s\-]*"')
matched_attribute_regions = view.find_all('\\w+="[\\w\\s\\-]*"')
for mr in matched_attribute_regions:
if not mr.contains(pt):
continue
Expand All @@ -777,7 +791,7 @@ def on_query_completions(self, view, prefix, locations):

# SLDS class name completions
if not settings["disable_slds_completion"]:
matched_attribute_regions = view.find_all('\w+="[\w\s\-]*"')
matched_attribute_regions = view.find_all('\\w+="[\\w\\s\\-]*"')
for mr in matched_attribute_regions:
if not mr.contains(pt):
continue
Expand All @@ -795,7 +809,7 @@ def on_query_completions(self, view, prefix, locations):
# Visualforce/Lightning Attribute Values Completions
############################################################
if not settings["disable_component_attribute_value_completion"]:
matched_regions = view.find_all("<\w+:\w+[\s\S]*?>")
matched_regions = view.find_all("<\\w+[:-]+\\w+[\\s\\S]*?>")

matched_region = None
for mr in matched_regions:
Expand All @@ -804,9 +818,9 @@ def on_query_completions(self, view, prefix, locations):

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))
matched_str = view.substr(matched_region)[1:-1]
matched_tag = matched_str.split(" ")[0].strip()
matched_attr_name = view.substr(view.extract_scope(pt-1))[:-1]

# Get the Attribute Values
if matched_tag in tag_defs and matched_attr_name in tag_defs[matched_tag]["attribs"]:
Expand Down
14 changes: 12 additions & 2 deletions config/commands/main.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
{"caption": "-"},

{
"caption": "HaoIDE: Open Aura Document Reference",
"command": "open_aura_document_reference"
"caption": "HaoIDE: Open Lightning Doc Reference",
"command": "open_lightning_doc_references"
},

{
Expand Down Expand Up @@ -103,6 +103,11 @@
}
},

{
"caption": "HaoIDE: New Lighting Web Component",
"command": "create_lightning_web_component"
},

{
"caption": "HaoIDE: Toggle Metdata Objects",
"command": "toggle_metadata_objects",
Expand Down Expand Up @@ -263,6 +268,11 @@
"command": "json_to_xml"
},

{
"caption": "HaoIDE: Utitlities > JSON to CSV",
"command": "json_to_csv"
},

{
"caption": "HaoIDE: Utitlities > XML to JSON",
"command": "xml_to_json"
Expand Down
6 changes: 6 additions & 0 deletions config/menus/Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{"caption": "-"},

{"caption": "Diff With Server", "command": "diff_with_server"},
{"caption": "Diff With Other File", "command": "diff_with_other_file"},

{"caption": "Retrieve From Server", "command": "retrieve_file_from_server"},
{"caption": "Deploy To Server", "command": "deploy_file_to_server"},
Expand Down Expand Up @@ -73,6 +74,11 @@
"command": "json_to_xml"
},

{
"caption": "JSON To CSV",
"command": "json_to_csv"
},

{
"caption": "XML To JSON",
"command": "xml_to_json"
Expand Down
5 changes: 5 additions & 0 deletions config/menus/Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@
"command": "json_to_xml"
},

{
"caption": "JSON to CSV",
"command": "json_to_csv"
},

{ "caption": "-" },

{
Expand Down
7 changes: 5 additions & 2 deletions config/settings/toolingapi.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
// There should be only one active project in projects settings
"default" : true,

// Hide the project in the `Switch Project` Fetaure if this option is true
"hidden_in_project_list": false,

// Login URL,
// sandbox: https://test.salesforce.com
// production: https://login.salesforce.com
Expand Down Expand Up @@ -82,7 +85,7 @@
"file_exclude_patterns": [
// "*.md",
// "*-history.*",
"*.*-meta.xml",
// "*.*-meta.xml",
"*.sublime-project",
"package.zip"
],
Expand All @@ -91,7 +94,7 @@
// Just work after new project is invoked or click ``HaoIDE > Update > Update Project Patterns``
"folder_exclude_patterns": [
// ".history",
".templates"
// ".templates"
],

// Solution for issue #49 in https://github.com/xjsender/SublimeApex
Expand Down
12 changes: 12 additions & 0 deletions config/snippets/LWC/targets.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<snippet>
<content><![CDATA[
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
]]></content>
<tabTrigger>targets</tabTrigger>
<scope>text.xml</scope>
<description>LWC Targets</description>
</snippet>
2 changes: 2 additions & 0 deletions config/templates/lwc/lwc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<template>
</template>
5 changes: 5 additions & 0 deletions config/templates/lwc/lwc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement, track, wire } from 'lwc';

export default class {class_name__c} extends LightningElement {

}
5 changes: 5 additions & 0 deletions config/templates/lwc/lwc.js-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="{class_name__c}">
<apiVersion>{api_version}.0</apiVersion>
<isExposed>false</isExposed>
</LightningComponentBundle>
15 changes: 15 additions & 0 deletions config/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@
}
},

"lwc": {
"html": {
"directory": "lwc/lwc.html",
"extension": ".html"
},
"js": {
"directory": "lwc/lwc.js",
"extension": ".js"
},
"js-meta": {
"directory": "lwc/lwc.js-meta.xml",
"extension": ".js-meta.xml"
}
},

"ApexClass": {
"Aura": {
"directory": "ApexClass/Aura.cls",
Expand Down
Loading

0 comments on commit c2a8205

Please sign in to comment.