Skip to content

Commit

Permalink
Merge pull request #216 from lushang/master
Browse files Browse the repository at this point in the history
Build 3.6.2
  • Loading branch information
lushang authored Mar 30, 2022
2 parents 717dd70 + 8f66ddb commit 586a0bd
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 38 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Release History
-----------------


Build 3.6.2 (2022-03-30)
++++++++++++++++++++++++++++++++++++
* Added diff functionality for aura and lwc component
* Allow developer check conflict before save lightning components
* Miscellaneous bug fix and refinements

Build 3.6.1 (2021-01-13)
++++++++++++++++++++++++++++++++++++
* Removed component metadata cache after destructing
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ well welcome to any contribution, open an issue for discussion before draft you
* Press ``alt`` + Click ``left mouse button``: Retrieve debug log detail by id
* Press ``alt`` + DblClick ``left mouse button``: View code coverage by name
* Press ``alt`` + Triple Click ``left mouse button``: Cancel deployment by Id

# Development Reference

- [Sublime Test Documentation](https://www.sublimetext.com/docs/index.html)
- [API Reference](https://www.sublimetext.com/docs/api_reference.html)
- [Sublime Text Community Documentation](https://docs.sublimetext.io/guide/extensibility/plugins/)
6 changes: 6 additions & 0 deletions config/messages/3.6.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Build 3.6.2
-----------
Release Date: 30 March 2022

* Added diff functionality for aura and lwc component, allow developer check conflict before save lightning components
* Miscellaneous bug fixings and refinements
4 changes: 2 additions & 2 deletions config/settings/package.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "haoide",
"version": "3.6.1",
"version": "3.6.2",
"description": "HaoIDE is a Sublime Text 3 plugin for Salesforce and used for swift development on Force.com",
"author": "Hao Liu @ 2013-2019, Lushang @ 2020-2021",
"author": "Hao Liu @ 2013-2019, Lushang @ 2020-2022",
"email": "[email protected]",
"homepage": "https://github.com/xjsender/haoide",
"issue_url": "https://github.com/xjsender/haoide/issues",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Object: $2
* Purpose: $3
* Author: $4 ($5)
* Create Date: 2020-${6:03-27}
* Create Date: 2022-${6:03-30}
* Modify History:
* 2021-${6:01-13} $4 ${7:Create this class}
* 2022-${6:03-30} $4 ${7:Create this class}
**************************************************************************************************/
]]></content>
<tabTrigger>ch</tabTrigger>
Expand Down
3 changes: 2 additions & 1 deletion events.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def on_hover(self, view, pt, hover_zone):

def on_new(self, view):
"""
1. Eveytime when you open a new view, default syntax is Apex
1. Everytime when you open a new view, default syntax is Apex
2. Set Status with current default project
"""

view.set_syntax_file("Packages/Java/Java.tmLanguage")
util.display_active_project(view)

Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ def is_enabled(self):

self.settings = context.get_settings()
self.attributes = util.get_file_attributes(self.file_name)
if self.attributes["metadata_folder"] not in ["classes", "triggers", "pages", "components"]:
diffable_attrbs = ["classes", "triggers", "pages", "components", "aura", "lwc"]
if self.attributes["metadata_folder"] not in diffable_attrbs:
return False

return True
Expand Down
2 changes: 1 addition & 1 deletion messages.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"3.6.0": "config/messages/3.6.0.md",
"3.6.1": "config/messages/3.6.1.md",
"3.6.2": "config/messages/3.6.2.md",
"install": "config/messages/install.txt"
}
17 changes: 12 additions & 5 deletions processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ def handle_thread(thread, timeout):
handle_set_component_attribute(component_attribute)

# If not succeed, just go to the error line
# Because error line in page is always at the line 1, so just work in class or trigger
# Only works in class or trigger since error line in page is always at the line 1
elif "success" in result and not result["success"]:
print('error result', result)
# Maybe network issue
Expand All @@ -1759,8 +1759,8 @@ def handle_thread(thread, timeout):

# Check current view the saving code file
if not view or not view.file_name(): return
if not file_base_name in view.file_name(): return
if not extension in [".trigger", ".cls", ".page", ".cmp", '.js', '.css']: return
if file_base_name not in view.file_name(): return
if extension not in [".trigger", ".cls", ".page", ".cmp", '.js', '.css']: return

if "line" in result:
line = result["line"]
Expand Down Expand Up @@ -1941,6 +1941,7 @@ def handle_thread(thread, timeout):
return

result = api.result

if result["success"] and result["records"]:
lastModifiedDate = result["records"][0]["LastModifiedDate"]
util.set_component_attribute(attributes, lastModifiedDate)
Expand All @@ -1952,8 +1953,13 @@ def handle_thread(thread, timeout):

settings = context.get_settings()
api = ToolingApi(settings)
cmp_type = attributes["type"]
if cmp_type == "AuraDefinitionBundle":
cmp_type = 'AuraDefinition'
elif cmp_type == 'LightningComponentBundle':
cmp_type = "LightningComponentResource"
soql = "SELECT LastModifiedDate FROM %s WHERE Id = '%s'" % (
attributes["type"], attributes["id"]
cmp_type, attributes["id"]
)
thread = threading.Thread(target=api.query, args=(soql, True,))
thread.start()
Expand Down Expand Up @@ -2007,7 +2013,8 @@ def handle_thread(thread, timeout):
result = api.result

# If error, just skip, error is processed in ThreadProgress
if not result["success"]: return
if not result["success"]:
return

# Diff Change Compare
diff.diff_changes(file_name, result)
Expand Down
15 changes: 10 additions & 5 deletions salesforce/api/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,14 +1161,15 @@ def save_to_server(self, component_attribute, body, is_check_only, check_save_co
# Result used in thread invoke
self.result = return_result

def save_lightning_to_server(self, component_attribute, body, check_save_conflict=True):
def save_lightning_to_server(self, component_attribute, body, is_check_only, check_save_conflict=True):
"""
Save Lightning AuraDefinition or LightningComponentResource such as component makeup, controller and helper or
Lightning Web component resource to Salesforce
Arguments:
@param component_attribute: attribute of component, e.g., component id, url
@param body: Code content
@param is_check_only: is check only
@param check_save_conflict: indicate whether to check saving conflict
@return: saving result
"""
Expand Down Expand Up @@ -1219,12 +1220,16 @@ def handle_error_message(result):

# Component Attribute
bundle_type = component_attribute["type"]
component_type = 'AuraDefinition' if bundle_type == "AuraDefinitionBundle" else 'LightningComponentResource'
component_type = 'AuraDefinition' \
if bundle_type == "AuraDefinitionBundle" \
else 'LightningComponentResource'
component_id = component_attribute["id"]
component_url = self.base_url + '/tooling/sobjects/' + component_type + '/' + component_id
component_url = self.base_url + \
'/tooling/sobjects/%s/%s' % (component_type, component_id)

# 2. Check conflict
if self.settings["check_save_conflict"] and check_save_conflict:
if self.settings["check_save_conflict"] and not is_check_only \
and check_save_conflict and "url" in component_attribute:
Printer.get('log').write("Start to check saving conflict")
query = "SELECT Id, LastModifiedById, LastModifiedBy.Id, " + \
"LastModifiedBy.Name, LastModifiedDate, SystemModstamp " + \
Expand Down Expand Up @@ -1274,7 +1279,7 @@ def handle_error_message(result):
data = {
"Source": body
}
result = self.patch(component_url, data)
result = self.patch(component_url, data) # {"str": "", "success": true}
return_result = {
"success": False,
"problem": '',
Expand Down
36 changes: 21 additions & 15 deletions salesforce/lib/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
import codecs
import os


def diff_changes(file_name, result):
try:
if "Body" in result:
server = result["Body"].splitlines()
elif "Markup" in result:
server = result["Markup"].splitlines()
elif "Source" in result:
server = result["Source"].splitlines()
else:
show_diff_panel("No server text found to diff")
return

local = codecs.open(file_name, "r", "utf-8").read().splitlines()
except UnicodeDecodeError:
show_diff_panel("Diff only works with UTF-8 files")
return

time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
bdate_literal = result["LastModifiedDate"].split(".")[0]
server_date = datetime.datetime.strptime(bdate_literal, "%Y-%m-%dT%H:%M:%S")
local_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
bdate_literal = result["LastModifiedDate"].split(".")[0]
server_date = datetime.datetime.strptime(bdate_literal, "%Y-%m-%dT%H:%M:%S")
local_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))

diff = difflib.unified_diff(server, local, "Server", "Local ", server_date, local_date, lineterm='')
difftxt = u"\n".join(line for line in diff)
diff = difflib.unified_diff(server, local, "Server", "Local ", server_date, local_date, lineterm='')
difftxt = u"\n".join(line for line in diff)

if difftxt == "":
show_diff_panel("There is no difference between %s and server" % os.path.basename(file_name))
return
if difftxt == "":
show_diff_panel("There is no difference between %s and server" % os.path.basename(file_name))
else:
show_diff_panel(difftxt)
except UnicodeDecodeError:
show_diff_panel("Diff only works with UTF-8 files")

show_diff_panel(difftxt)

def diff_files(file_name, other_file_name):
try:
Expand All @@ -51,10 +56,11 @@ def diff_files(file_name, other_file_name):

show_diff_panel(difftxt)

def show_diff_panel(difftxt):

def show_diff_panel(diff_txt):
win = sublime.active_window()
v = win.create_output_panel('diff_with_server')
v.assign_syntax('Packages/Diff/Diff.tmLanguage')

v.run_command('append', {'characters': difftxt})
v.run_command('append', {'characters': diff_txt})
win.run_command("show_panel", {"panel": "output.diff_with_server"})
4 changes: 2 additions & 2 deletions salesforce/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def format_request_envelope(self, request_body):
formatted_body = formatter.format_string(request_body)
except Exception as ex:
if self.settings["debug_mode"]:
print ("[Format Request Body] " + str(ex))
print("[Format Request Body] " + str(ex))
formatted_body = request_body

return formatted_body
Expand All @@ -55,7 +55,7 @@ def format_request_envelope(self, request_body):
def create_request(self, request_type, options={}):
soap_body = getattr(self, "create_%s_request" % request_type)(options)
if self.settings["debug_mode"]:
print ("[Debug for {request_type}]: \n{seprate}\n{content}\n{seprate}".format(
print("[Debug for {request_type}]: \n{seprate}\n{content}\n{seprate}".format(
seprate="~" * 100,
request_type=request_type,
content=soap_body.decode("UTF-8")
Expand Down
30 changes: 26 additions & 4 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,12 @@ def reload_file_attributes(file_properties, settings=None, append=False):
"ApexComponent": "Markup"
}

# print(file_properties)
lightning_body = {
"AuraDefinitionBundle": "AuraDefinition",
"LightningComponentBundle": "LightningComponentResource"
}

# print(json.dumps(file_properties))

# If the package only contains `package.xml`
if isinstance(file_properties, dict):
Expand Down Expand Up @@ -1863,6 +1868,13 @@ def reload_file_attributes(file_properties, settings=None, append=False):
attrs["url"] = "/services/data/v%s.0/sobjects/%s/%s" % (
settings["api_version"], metdata_object, filep["id"]
)
elif metdata_object in lightning_body:
attrs["body"] = 'Source'
attrs["url"] = "/services/data/v%s.0/tooling/sobjects/%s/%s" % (
settings["api_version"],
lightning_body.get(metdata_object),
filep["id"]
)

# Check whether component is Test Class or not
if metdata_object == "ApexClass":
Expand Down Expand Up @@ -3199,13 +3211,23 @@ def get_component_attribute(file_name, switch=True, reload_cache=False):
xml_name = settings[metadata_folder]["xmlName"]
username = settings["username"]
components = load_metadata_cache(reload_cache=reload_cache, username=username)
lightning_cmps = {
"AuraDefinitionBundle": "AuraDefinition",
"LightningComponentBundle": "LightningComponentResource"
}
try:
component_attribute = components[xml_name][fullName.lower()]
cmp_attr = components[xml_name][fullName.lower()]
if 'url' not in cmp_attr and cmp_attr['type'] in lightning_cmps:
cmp_attr['url'] = "/services/data/v%s.0/tooling/sobjects/%s/%s" % (
settings["api_version"],
lightning_cmps.get(cmp_attr['type']),
cmp_attr["id"]
)
except:
component_attribute, name = None, None
cmp_attr, name = None, None

# Return tuple
return (component_attribute, name)
return cmp_attr, name


def delete_component_attribute(dirs_or_files, switch=True):
Expand Down

0 comments on commit 586a0bd

Please sign in to comment.