Skip to content

Commit f4b2021

Browse files
support of refactor commands on windows, refactor commands improved, surround_with and delete_surrounded improved
1 parent e6855ec commit f4b2021

15 files changed

+739
-265
lines changed

Context.sublime-menu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@
209209
"command": "surround_with",
210210
"args": {"case": "iife_function"}
211211
},
212+
{
213+
"caption": "generator function",
214+
"command": "surround_with",
215+
"args": {"case": "generator_function"}
216+
},
212217
{
213218
"caption": "block {}",
214219
"command": "surround_with",

_generated_2018_02_05_at_03_39_47.py renamed to _generated_2018_02_06_at_02_44_41.py

Lines changed: 361 additions & 130 deletions
Large diffs are not rendered by default.

changelog/0.14.0.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ v0.14.0
2020
* Extract Variable
2121
* Extract Field
2222
* Convert a function to an arrow function
23+
24+
See the Wiki to see how it works https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki
2325
- Added "Open TerminalView Here…" command to Context Menu and Side Bar Menu
2426
- Forced "auto_complete_delay" option to 0 when showing JavaScript auto-completions
2527
- Updated default_autocomplete and surround_with_command with more options
28+
- Show .flowconfig errors in status bar
2629

2730
## Misc
2831

default_autocomplete.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
"function_with_name",
4141
"function ${1:function_name} (${2:argument}) {\n\t${3:// body... }\n}"
4242
],
43+
[
44+
"generator_function",
45+
"function* ${1:function_name} (${2:argument}) {\n\t${3:// body... }\n}"
46+
],
4347
[
4448
"anonymous_function",
4549
"function (${1:argument}) {\n\t${2:// body... }\n}"
@@ -66,7 +70,7 @@
6670
],
6771
[
6872
"do_while",
69-
"do{\n\t// statement\n} while (${1:condition});"
73+
"do{\n\t// statement\n} while (${1:condition})"
7074
],
7175
[
7276
"while",

helper/WindowView.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def __init__(self, title="WindowView", window=None, view=None, use_compare_layou
4747
self.view.settings().set("draw_indent_guides", False)
4848
self.view.settings().set("wide_caret", True)
4949
self.view.settings().set("rulers", "blink")
50+
self.view.settings().set("word_wrap", True)
5051
self.view.settings().add_on_change('color_scheme', lambda: self.setColorScheme())
52+
self.setColorScheme()
5153
self.events = dict()
5254
self.region_ids = []
5355
self.region_input_ids = []

helper/can_i_use/can_i_use_data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

helper/delete_surrounded_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def run(self, edit, **args):
77
scope = view.scope_name(selection.begin()).strip()
88
scope_splitted = scope.split(" ")
99
if case == "strip_quoted_string" :
10-
result = Util.firstIndexOfMultiple(scope_splitted, ("string.quoted.double.js", "string.quoted.single.js", "string.template.js"))
10+
result = Util.firstIndexOfMultiple(scope_splitted, ("string.quoted.double.js", "string.quoted.single.js", "string.template.js", "string.quoted.js", "string.interpolated.js"))
1111
selector = result.get("string")
1212
item = Util.get_region_scope_first_match(view, scope, selection, selector)
1313
if item :

helper/javascript_completions/on_query_completions_event_listener.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,13 @@ def on_selection_modified_async(self, view) :
261261
selections = view.sel()
262262
if len(selections) == 0:
263263
return
264+
265+
sel = None
266+
try:
267+
sel = selections[0]
268+
except IndexError as e:
269+
return
264270

265-
sel = selections[0]
266271
if not view.match_selector(
267272
sel.begin(),
268273
'source.js - string - comment'

helper/node/main.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def execute(self, command, command_args, is_from_bin=False, chdir="", wait_termi
6060

6161
return Util.execute(args[0], args[1:], chdir=chdir, wait_terminate=wait_terminate, func_stdout=func_stdout, args_func_stdout=args_func_stdout)
6262

63-
def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_temp=False, use_only_filename_view_flow=False, fp_temp_contents="", is_output_json=False, chdir="", clean_output_flow=False, bin_path="", use_node=True) :
63+
def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_temp=False, use_only_filename_view_flow=False, fp_temp_contents="", is_output_json=False, chdir="", clean_output_flow=False, bin_path="", use_node=True, command_arg_escape=True) :
6464

6565
fp = None
6666
args = ""
@@ -80,7 +80,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
8080
for command_arg in command_args :
8181
if command_arg == ":temp_file":
8282
command_arg = fp.name
83-
command_args_list.append(shlex.quote(command_arg) if sublime.platform() != 'windows' else json.dumps(command_arg))
83+
command_args_list.append( (shlex.quote(command_arg) if sublime.platform() != 'windows' else json.dumps(command_arg)) if command_arg_escape else command_arg )
8484
command_args = " ".join(command_args_list)
8585

8686
if sublime.platform() == 'windows':
@@ -168,12 +168,22 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
168168
print(traceback.format_exc())
169169

170170
if e.output:
171+
print(e.output)
171172
output_error_message = e.output.decode("utf-8", "ignore").strip()
172173
output_error_message = output_error_message.split("\n")
173-
output_error_message = "\n".join(output_error_message[:-2]) if '{"flowVersion":"' in output_error_message[-1] else "\n".join(output_error_message)
174+
final_message = ""
175+
flag = False
174176

175-
print(e.output)
176-
sublime.active_window().status_message(output_error_message)
177+
for msg in output_error_message:
178+
msg = msg.strip()
179+
if msg.startswith("{\"flowVersion\":"):
180+
flag = True
181+
break
182+
else:
183+
final_message += msg + " "
184+
185+
if flag:
186+
sublime.active_window().status_message(final_message)
177187

178188
# reset the PATH environment variable
179189
os.environ.update(old_env)
@@ -206,7 +216,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
206216
fp.close()
207217
return [False, None]
208218

209-
except:
219+
except Exception as e:
210220

211221
# reset the PATH environment variable
212222
os.environ.update(old_env)

helper/refactor/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def run(self, edit, **args):
1616
windowView.add(text=" ")
1717
windowView.addButton(text="MOVE", scope="javascriptenhancements.button_ok", callback=lambda view: self.view.run_command("refactor_safe_move", args={"inputs": windowView.getInputs(), "preview": False, "view_id_caller": self.view.id()}))
1818
windowView.add(text=" ")
19-
windowView.addCloseButton(text="CANCEL", scope="javascriptenhancements.button_cancel")
19+
windowView.addCloseButton(text="CANCEL", scope="javascriptenhancements.button_cancel", callback=lambda view: self.closePreview("Refactor - Safe Move Preview"))
2020
windowView.add(text=" \n")
2121

2222
elif case == "safe_copy" :
@@ -29,7 +29,7 @@ def run(self, edit, **args):
2929
windowView.add(text=" ")
3030
windowView.addButton(text="COPY", scope="javascriptenhancements.button_ok", callback=lambda view: self.view.run_command("refactor_safe_copy", args={"inputs": windowView.getInputs(), "preview": False, "view_id_caller": self.view.id()}))
3131
windowView.add(text=" ")
32-
windowView.addCloseButton(text="CANCEL", scope="javascriptenhancements.button_cancel")
32+
windowView.addCloseButton(text="CANCEL", scope="javascriptenhancements.button_cancel", callback=lambda view: self.closePreview("Refactor - Safe Copy Preview"))
3333
windowView.add(text=" \n")
3434

3535
if case == "safe_delete" :
@@ -42,7 +42,7 @@ def run(self, edit, **args):
4242
windowView.add(text=" ")
4343
windowView.addButton(text="DELETE", scope="javascriptenhancements.button_ok", callback=lambda view: self.view.run_command("refactor_safe_delete", args={"preview": False, "view_id_caller": self.view.id()}))
4444
windowView.add(text=" ")
45-
windowView.addCloseButton(text="CANCEL", scope="javascriptenhancements.button_cancel")
45+
windowView.addCloseButton(text="CANCEL", scope="javascriptenhancements.button_cancel", callback=lambda view: self.closePreview("Refactor - Safe Delete Preview"))
4646
windowView.add(text=" \n")
4747

4848
elif case == "extract_method" :
@@ -103,8 +103,14 @@ def run(self, edit, **args):
103103
elif case == "convert_to_arrow_function" :
104104
self.view.run_command("refactor_convert_to_arrow_function")
105105

106-
def is_enabled(self, **args) :
106+
def closePreview(self, preview_name):
107+
window = self.view.window()
108+
for v in window.views():
109+
if v.name() == preview_name:
110+
v.close()
111+
break
107112

113+
def is_enabled(self, **args) :
108114
view = self.view
109115
return Util.selection_in_js_scope(view)
110116

0 commit comments

Comments
 (0)