Skip to content

Commit

Permalink
release 2.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
xjsender committed Apr 10, 2015
1 parent cfe0bd1 commit 58a89bb
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 39 deletions.
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Release History
---------------


Release 2.8.5 (2015-04-10)
++++++++++++++++++
* Biggest optimization for variable completion:
- Exclude comment statement
- Choose the nearest matched one
* Add a new ``remove_comments`` command in the ``Utilities``
* Allow ``extract_to_here`` command to support all zip resources


Release 2.8.4 (2015-04-09)
++++++++++++++++++
* Add error popup display for latest version of sublime
Expand Down
4 changes: 4 additions & 0 deletions config/menus/Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@
"router": "rest"
}
},
{
"caption": "Remove Comments",
"command": "remove_comments"
},
{
"id": "convert15idto18id",
"caption": "Convert 15 Id to 18 Id",
Expand Down
14 changes: 14 additions & 0 deletions config/messages/2.8.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Build 2.8.5
-----------
Release Date: 10 Apr 2015

* Biggest optimization for variable completion:
- Exclude comment statement
- Choose the nearest matched one
* Add a new ``remove_comments`` command in the ``Utilities``
* Allow ``extract_to_here`` command to support all zip resources

Notes:

* You should restart your sublime after ``HaoIDE`` is upgraded
-----------
2 changes: 1 addition & 1 deletion config/settings/package.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haoide",
"version": "2.8.4",
"version": "2.8.5",
"description": "haoide is a Sublime Text 3 plugin for Salesforce and used for swift development on Force.com",
"author": "Hao Liu",
"email": "[email protected]",
Expand Down
15 changes: 7 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
from .salesforce import message


class RemoveComments(sublime_plugin.TextCommand):
def run(self, edit):
comments = self.view.find_by_selector('comment')
for region in reversed(comments):
region = self.view.full_line(region)
self.view.erase(edit, region)

class Haoku(sublime_plugin.WindowCommand):
def __init__(self, *args, **kwargs):
super(Haoku, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -2045,14 +2052,6 @@ def is_visible(self, files):
return False

self._file = files[0]
try:
base, name = os.path.split(self._file)
name, extension = name.split(".")
if extension not in ["zip", "resource"]:
return False
except:
return False

return True

class UpdateStaticResource(sublime_plugin.WindowCommand):
Expand Down
1 change: 1 addition & 0 deletions messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"2.8.2": "config/messages/2.8.2.md",
"2.8.3": "config/messages/2.8.3.md",
"2.8.4": "config/messages/2.8.4.md",
"2.8.5": "config/messages/2.8.5.md",
"install": "config/messages/install.txt"
}
83 changes: 53 additions & 30 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,25 @@ def open_with_browser(show_url, use_default_chrome=True):
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(browser_path))
webbrowser.get('chrome').open_new_tab(show_url)

def remove_comments(view, regions):
# Get all comment regions
comment_regions = view.find_by_selector('comment')

matched_regions = []
for region in regions:
# check whether region is comment statement
is_comment_region = False
for comment_region in comment_regions:
if comment_region.contains(region):
is_comment_region = True
break

# If region is comment statement, just skip
if not is_comment_region:
matched_regions.append(region)

return matched_regions

def get_variable_type(view, pt, pattern):
"""Return the matched soql region
Expand All @@ -373,43 +392,47 @@ def get_variable_type(view, pt, pattern):
"""
# Get the matched variable type
matched_regions = view.find_all(pattern, sublime.IGNORECASE)

# It must have lots of matched
row_region = {}
for mr in matched_regions:
row, col = view.rowcol(mr.begin())
row_region[row] = mr

# Get the row, col of cursor
cursor_row, cursor_col = view.rowcol(pt)

# Choose the nearest matched region
# For example, rows of matched regions are 1, 3, 14, 17
# cursor row is 15, so we choose the region of 14
rows = list(row_region.keys())
rows.append(cursor_row)
rows = sorted(rows)
cursor_index = rows.index(cursor_row)

# If no matched region, just set it as none
if cursor_index == 0:
matched_region = None
# If lots of matched regions, choose the previous one
uncomment_regions = remove_comments(view, matched_regions)

# Three scenarios:
# 1. If no matched regions
# 2. Only one matched region
# 3. More than one matched region
if not uncomment_regions:
return ""
elif len(uncomment_regions) == 1:
matched_region = uncomment_regions[0]
else:
matched_region = matched_regions[cursor_index - 1]

if not matched_region: return ""
matched_block = view.substr(matched_region).strip()
row_region = {} # Row => Region
for mr in uncomment_regions:
row, col = view.rowcol(mr.begin())
row_region[row] = mr

# Get the cursor row
cursor_row = view.rowcol(pt)[0]

# Three steps:
# 1. Add the cursor row and matched rows together
# 2. Sort all rows by ASC
# 3. Get the previous row of cursor row
rows = list(row_region.keys())
rows.append(cursor_row)
rows = sorted(rows)
cursor_index = rows.index(cursor_row)
matched_region = row_region[rows[cursor_index - 1]]

# Get the content of matched region
matched_str = view.substr(matched_region).strip()

# If list, map, set
if "<" in matched_block and ">" in matched_block:
variable_type = matched_block.split("<")[0].strip()
if "<" in matched_str and ">" in matched_str:
variable_type = matched_str.split("<")[0].strip()
# String[] strs;
elif "[]" in matched_block:
elif "[]" in matched_str:
variable_type = 'list'
# String str;
else:
variable_type = matched_block.split(" ")[0]
variable_type = matched_str.split(" ")[0]

return variable_type

Expand Down

0 comments on commit 58a89bb

Please sign in to comment.