Skip to content

Commit bf6b3fc

Browse files
fix #25, fix #24, Added "enable_keymap" option to the plugin settings in order to allow quick enabling/disabling of the default plugin keymaps
1 parent f0fa07b commit bf6b3fc

15 files changed

+206
-48
lines changed

JavaScript Enhancements.sublime-settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
"angularv1_custom_path": "yo",
1111
"angularv2_custom_path": "ng",
1212
"react_custom_path": "create-react-app",
13+
"react_native_custom_path": "create-react-native-app",
1314
"express_custom_path": "express",
1415
"yeoman_custom_path": "yo",
1516

17+
"enable_keymap": true,
18+
1619
"enable_can_i_use_menu_option": true,
1720
"enable_unused_variables_feature": true
1821
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ If all is going in the right way, you will see `JavaScript Enhancements - instal
7676

7777
### Fixing node.js and npm custom path
7878

79-
If the plugin gives to you message errors like `Error during installation: "node.js" seems not installed on your system...` but instead you have installed node.js and npm (for example using [nvm](https://github.com/creationix/nvm)), then you could try to set your custom path in the [Global settings](https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Global-settings) of the plugin and then restart Sublime Text.
79+
If the plugin gives to you message errors like `Error during installation: "node.js" seems not installed on your system...` but instead you have installed node.js and npm (for example using [nvm](https://github.com/creationix/nvm)), then you could try to set your custom path in the [Global settings](https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Global-settings) of the plugin and then restart Sublime Text.
80+
81+
If you don't know the path of them, use `which node`/`which npm` (for Linux-based OS) or `where node.exe`/`where npm` (for Windows OS) to get it.
8082

8183
If this doesn't work too, then you could try to add the custom path that contains binaries of node.js and npm in the **`PATH`** key-value on the same JavaScript Enhancements settings file. This variable will be **appended** to the **$PATH** environment variable, so you could use the same syntax in it. After this you need to restart Sublime Text. Example of a global setting for `Linux` that uses `nvm`:
8284

_generated_2018_01_23_at_15_18_32.py renamed to _generated_2018_01_25_at_02_31_42.py

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from shutil import copyfile
44
from threading import Timer
55

6-
PLUGIN_VERSION = "0.13.14"
6+
PLUGIN_VERSION = "0.13.15"
77

88
PACKAGE_PATH = os.path.abspath(os.path.dirname(__file__))
99
PACKAGE_NAME = os.path.basename(PACKAGE_PATH)
@@ -887,7 +887,7 @@ def execute(command, command_args, chdir="", wait_terminate=True, func_stdout=No
887887

888888
env = os.environ.copy()
889889
env["PATH"] = env["PATH"] + javascriptCompletions.get("PATH")
890-
shell = os.getenv('SHELL')
890+
shell = None if sublime.platform() == 'windows' else '/bin/bash'
891891

892892
with subprocess.Popen(args, shell=True, executable=shell, env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=(None if not chdir else chdir)) as p:
893893

@@ -917,7 +917,7 @@ def _wrapper_func_stdout(args, func_stdout, args_func_stdout=[], chdir=""):
917917

918918
env = os.environ.copy()
919919
env["PATH"] = env["PATH"] + javascriptCompletions.get("PATH")
920-
shell = os.getenv('SHELL')
920+
shell = None if sublime.platform() == 'windows' else '/bin/bash'
921921

922922
with subprocess.Popen(args, shell=True, executable=shell, env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, preexec_fn=os.setsid, cwd=(None if not chdir else chdir)) as p:
923923

@@ -1277,6 +1277,12 @@ def close(self) :
12771277
self.socket = None
12781278

12791279

1280+
KEYMAP_COMMANDS = []
1281+
keymaps = Util.open_json(os.path.join(PACKAGE_PATH, 'Default.sublime-keymap'))
1282+
for keymap in keymaps:
1283+
if keymap["command"] != "window_view_keypress":
1284+
KEYMAP_COMMANDS += [keymap["command"]]
1285+
12801286
def sublime_executable_path():
12811287
executable_path = sublime.executable_path()
12821288

@@ -1329,11 +1335,17 @@ def init(self):
13291335
node_modules_path = os.path.join(PACKAGE_PATH, "node_modules")
13301336
npm = NPM()
13311337
if not os.path.exists(node_modules_path):
1332-
sublime.active_window().status_message("JavaScript Enhancements - installing npm dependencies...")
1338+
animation_npm_installer = AnimationLoader(["[= ]", "[ = ]", "[ = ]", "[ = ]", "[ =]", "[ = ]", "[ = ]", "[ = ]"], 0.067, "JavaScript Enhancements - installing npm dependencies ")
1339+
interval_animation = RepeatedTimer(animation_npm_installer.sec, animation_npm_installer.animate)
1340+
# sublime.active_window().status_message("JavaScript Enhancements - installing npm dependencies...")
13331341
result = npm.install_all()
13341342
if result[0]:
1343+
animation_npm_installer.on_complete()
1344+
interval_animation.stop()
13351345
sublime.active_window().status_message("JavaScript Enhancements - npm dependencies installed correctly.")
13361346
else:
1347+
animation_npm_installer.on_complete()
1348+
interval_animation.stop()
13371349
print(result)
13381350
if os.path.exists(node_modules_path):
13391351
shutil.rmtree(node_modules_path)
@@ -1666,10 +1678,11 @@ def run(self, **kwargs):
16661678
self.command = ["$(which "+shlex.quote(self.path_cli)+")"]
16671679
self.path_cli = self.settings["project_settings"]["node_js_custom_path"] or javascriptCompletions.get("node_js_custom_path")
16681680

1669-
if not self.command:
1670-
self.command = kwargs.get("command")
1671-
else:
1672-
self.command += [kwargs.get("command")]
1681+
if kwargs.get("command"):
1682+
if not self.command:
1683+
self.command = kwargs.get("command")
1684+
else:
1685+
self.command += kwargs.get("command")
16731686

16741687
self.prepare_command(**kwargs)
16751688

@@ -1694,11 +1707,11 @@ def run(self, **kwargs):
16941707
self.command = ["$(which "+shlex.quote(self.path_cli)+")"]
16951708
self.path_cli = javascriptCompletions.get("node_js_custom_path")
16961709

1697-
1698-
if not self.command:
1699-
self.command = kwargs.get("command")
1700-
else:
1701-
self.command += [kwargs.get("command")]
1710+
if kwargs.get("command"):
1711+
if not self.command:
1712+
self.command = kwargs.get("command")
1713+
else:
1714+
self.command += kwargs.get("command")
17021715

17031716
self.prepare_command(**kwargs)
17041717

@@ -3362,6 +3375,8 @@ def find_prev(self, regions):
33623375
return previous_regions[len(previous_regions)-1] if len(previous_regions) > 0 else None
33633376

33643377

3378+
import sublime, sublime_plugin
3379+
33653380
class wait_modified_asyncViewEventListener():
33663381
last_change = time.time()
33673382
waiting = False
@@ -3381,9 +3396,7 @@ def wait(self):
33813396
self.waiting = True
33823397
else :
33833398
return
3384-
self.last_change = time.time()
3385-
while time.time() - self.last_change <= self.wait_time:
3386-
time.sleep(.1)
3399+
sublime.set_timeout(self.wait_time)
33873400
self.waiting = False
33883401

33893402
def on_modified_async_with_thread(self, *args, **kwargs):
@@ -3392,6 +3405,15 @@ def on_modified_async_with_thread(self, *args, **kwargs):
33923405

33933406
import sublime, sublime_plugin
33943407

3408+
class enableKeymap(sublime_plugin.EventListener):
3409+
3410+
def on_text_command(self, view, command_name, args):
3411+
3412+
if command_name in KEYMAP_COMMANDS and not javascriptCompletions.get("enable_keymap"):
3413+
return ("noop", {})
3414+
3415+
import sublime, sublime_plugin
3416+
33953417
class surround_withCommand(sublime_plugin.TextCommand):
33963418
def run(self, edit, **args):
33973419
view = self.view
@@ -4030,7 +4052,7 @@ def load_default_autocomplete(view, comps_to_campare, prefix, location, isHover
40304052

40314053
scope = view.scope_name(location-(len(prefix)+1)).strip()
40324054

4033-
if scope.endswith(" punctuation.accessor.js") :
4055+
if scope.endswith(" punctuation.accessor.js") or scope.endswith(" keyword.operator.accessor.js") :
40344056
return []
40354057

40364058
prefix = prefix.lower()
@@ -5603,7 +5625,7 @@ def on_modified_async_with_thread(self, recheck=True):
56035625

56045626
repetitions[variableName] = [variableRegion]
56055627

5606-
items = Util.nested_lookup("type", ["VariableDeclarator", "MemberExpression", "CallExpression", "BinaryExpression", "ExpressionStatement", "Property", "ArrayExpression", "ObjectPattern", "AssignmentExpression", "IfStatement", "ForStatement", "WhileStatement", "ForInStatement", "ForOfStatement", "LogicalExpression", "UpdateExpression", "ArrowFunctionExpression", "ConditionalExpression", "JSXIdentifier", "ExportDefaultDeclaration", "JSXExpressionContainer", "NewExpression", "ReturnStatement"], body)
5628+
items = Util.nested_lookup("type", ["VariableDeclarator", "MemberExpression", "CallExpression", "BinaryExpression", "ExpressionStatement", "Property", "ArrayExpression", "ObjectPattern", "AssignmentExpression", "IfStatement", "ForStatement", "WhileStatement", "ForInStatement", "ForOfStatement", "LogicalExpression", "UpdateExpression", "ArrowFunctionExpression", "ConditionalExpression", "JSXIdentifier", "ExportDefaultDeclaration", "JSXExpressionContainer", "NewExpression", "ReturnStatement", "SpreadProperty", "TemplateLiteral"], body)
56075629
for item in items:
56085630

56095631
if "exportKind" in item and "declaration" in item and isinstance(item["declaration"],dict) and "name" in item["declaration"] and item["declaration"]["type"] == "Identifier":
@@ -5629,6 +5651,12 @@ def on_modified_async_with_thread(self, recheck=True):
56295651

56305652
item = item["callee"]
56315653

5654+
elif "expressions" in item and item["expressions"]:
5655+
for expression in item["expressions"]:
5656+
if isinstance(expression,dict) and "name" in expression and expression["type"] == "Identifier":
5657+
items += [expression]
5658+
continue
5659+
56325660
elif "left" in item or "right" in item:
56335661

56345662
if "left" in item and isinstance(item["left"],dict) and "name" in item["left"] and item["left"]["type"] == "Identifier":
@@ -5935,7 +5963,7 @@ def start():
59355963
print("node.js version: " + str(node.getCurrentNodeJSVersion()))
59365964
except Exception as err:
59375965
print(err)
5938-
response = sublime.yes_no_cancel_dialog("Error during installation: \"node.js\" seems not installed on your system. Node.js and npm are required to be able to use JavaScript Enhancements plugin.\n\nIf you are using \"nvm\" or you have a different path for node.js and npm, please then change the path on:\n\nPreferences > Package Settings > JavaScript Enhancements > Settings\n\nand restart Sublime Text.\n\nIf this doesn't work then try also to add the path of their binaries in the PATH key-value on the same JavaScript Enhancements settings file. This variable will be used to add them in the $PATH environment variable, so put the symbol \":\" (instead \";\" for Windows) in front of your path.\n\nDo you want open the website of node.js?", "Yes, open it", "Or use nvm")
5966+
response = sublime.yes_no_cancel_dialog("Error during installation: \"node.js\" seems not installed on your system. Node.js and npm are required to be able to use JavaScript Enhancements plugin.\n\nIf you are using \"nvm\" or you have a different path for node.js and npm, please then change the path on:\n\nPreferences > Package Settings > JavaScript Enhancements > Settings\n\nand restart Sublime Text. If you don't know the path of it, use \"which node\" (for Linux-based OS) or \"where node.exe\" (for Windows OS) to get it.\n\nIf this doesn't work then try also to add the path of their binaries in the PATH key-value on the same JavaScript Enhancements settings file. This variable will be used to add them in the $PATH environment variable, so put the symbol \":\" (instead \";\" for Windows) in front of your path.\n\nDo you want open the website of node.js?", "Yes, open it", "Or use nvm")
59395967
if response == sublime.DIALOG_YES:
59405968
sublime.active_window().run_command("open_url", args={"url": "https://nodejs.org"})
59415969
elif response == sublime.DIALOG_NO:
@@ -5947,7 +5975,7 @@ def start():
59475975
print("npm version: " + str(npm.getCurrentNPMVersion()))
59485976
except Exception as err:
59495977
print(err)
5950-
response = sublime.yes_no_cancel_dialog("Error during installation: \"npm\" seems not installed on your system. Node.js and npm are required to be able to use JavaScript Enhancements plugin.\n\nIf you are using \"nvm\" or you have a different path for node.js and npm, please change their custom path on:\n\nPreferences > Package Settings > JavaScript Enhancements > Settings\n\nand restart Sublime Text.\n\nIf this doesn't work then try also to add the path of their binaries in the PATH key-value on the same JavaScript Enhancements settings file. This variable will be used to add them in the $PATH environment variable, so put the symbol \":\" (instead \";\" for Windows) in front of your path.\n\nDo you want open the website of node.js?", "Yes, open it", "Or use nvm")
5978+
response = sublime.yes_no_cancel_dialog("Error during installation: \"npm\" seems not installed on your system. Node.js and npm are required to be able to use JavaScript Enhancements plugin.\n\nIf you are using \"nvm\" or you have a different path for node.js and npm, please change their custom path on:\n\nPreferences > Package Settings > JavaScript Enhancements > Settings\n\nand restart Sublime Text. If you don't know the path of it, use \"which npm\" (for Linux-based OS) or \"where npm\" (for Windows OS) to get it.\n\nIf this doesn't work then try also to add the path of their binaries in the PATH key-value on the same JavaScript Enhancements settings file. This variable will be used to add them in the $PATH environment variable, so put the symbol \":\" (instead \";\" for Windows) in front of your path.\n\nDo you want open the website of node.js?", "Yes, open it", "Or use nvm")
59515979
if response == sublime.DIALOG_YES:
59525980
sublime.active_window().run_command("open_url", args={"url": "https://nodejs.org"})
59535981
elif response == sublime.DIALOG_NO:

changelog/0.13.15.txt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
v0.13.15
2+
3+
## Fixes
4+
5+
- Fixed "zsh shell doesn't recognize node.js" #25, using "/bin/bash" shell instead
6+
- Fixed other issues with Unused variable feature #24
7+
8+
## Improvements
9+
10+
- Added "enable_keymap" option to the plugin settings in order to allow quick enabling/disabling of the default plugin keymaps.
11+
12+
13+
14+
=================================================================
15+
** THIS PLUGIN IS IN BETA! Thanks for your support in advance! **
16+
=================================================================
17+
18+
If you like it, remember to star it ⭐ on GitHub: https://github.com/pichillilorenzo/JavaScriptEnhancements
19+
20+
** USAGE **
21+
===========
22+
23+
See how it works on the Wiki: 👉👉 https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki 👈👈
24+
25+
26+
** WHAT IS THIS? **
27+
===================
28+
29+
This plugin uses Flow (javascript static type checker from Facebook) under the hood.
30+
31+
It offers better javascript autocomplete and a lot of features about creating,
32+
developing and managing javascript projects, such as:
33+
34+
- Cordova projects (run cordova emulate, build, compile, serve, etc. directly from Sublime Text!)
35+
- Ionic v1 and v2 projects (same as Cordova projects!)
36+
- Angular v1 and v2 projects
37+
- React projects (only about the creation at this moment)
38+
- React Native projects (only about the creation at this moment. I will add also NativeScript support)
39+
- Express projects (only about the creation at this moment)
40+
- Yeoman generators
41+
- Local bookmarks project
42+
- JavaScript real-time errors
43+
- etc.
44+
45+
You could use it also in existing projects (see the Wiki - https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Using-it-with-an-existing-project)!
46+
47+
It turns Sublime Text into a JavaScript IDE like!
48+
49+
This project is based on my other Sublime Text plugin JavaScript Completions (https://github.com/pichillilorenzo/JavaScript-Completions)
50+
51+
** NOTE **
52+
If you want use this plugin, you may want uninstall/disable the JavaScript Completions plugin, if installed.
53+
54+
** OS SUPPORTED NOW **
55+
======================
56+
57+
👉 Linux (64-bit)
58+
👉 Mac OS X
59+
👉 Windows (64-bit): released without the use of TerminalView plugin. For each feature (like also creating a project) will be used the cmd.exe shell (so during the creation of a project don't close it until it finishes!). Unfortunately the TerminalView plugin supports only Linux-based OS 😞. Has someone any advice or idea about that? Is there something similar to the TerminalView plugin for Windows?? Thanks!
60+
61+
❗❗ Dependencies ❗❗
62+
=======================
63+
64+
In order to work properly, this plugin has some dependencies:
65+
66+
👉 Sublime Text 3 (build 3124 or newer)
67+
👉 Node.js and npm (https://nodejs.org or nvm (https://github.com/creationix/nvm))
68+
👉 TerminalView (only for Linux and Mac OS X) sublime text plugin (https://github.com/Wramberg/TerminalView)
69+
70+
Not required, but useful for typescript files (Flow wont work on this type of files):
71+
72+
👉 TypeScript sublime text plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin)
73+
74+
** Flow Requirements **
75+
=======================
76+
77+
It use [Flow](https://github.com/facebook/flow) for type checking and auto-completions.
78+
79+
👉 Mac OS X
80+
👉 Linux (64-bit)
81+
👉 Windows (64-bit)
82+
83+
Email me for any questions or doubts about this new project on: pichillilorenzo@gmail.com
84+
85+
** Donation **
86+
==============
87+
88+
If this project help you reduce time to develop and also you like it, please support it with a donation 😄👍. Thanks!
89+
90+
Open Collective: https://opencollective.com/javascriptenhancements/donate
91+
PayPal: https://www.paypal.me/LorenzoPichilli
92+
93+
Thanks anyway for your support! 😄😄
94+
95+
MIT License
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sublime, sublime_plugin
2+
3+
class enableKeymap(sublime_plugin.EventListener):
4+
5+
def on_text_command(self, view, command_name, args):
6+
7+
if command_name in KEYMAP_COMMANDS and not javascriptCompletions.get("enable_keymap"):
8+
return ("noop", {})

helper/javascript_completions/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def load_default_autocomplete(view, comps_to_campare, prefix, location, isHover
2525

2626
scope = view.scope_name(location-(len(prefix)+1)).strip()
2727

28-
if scope.endswith(" punctuation.accessor.js") :
28+
if scope.endswith(" punctuation.accessor.js") or scope.endswith(" keyword.operator.accessor.js") :
2929
return []
3030

3131
prefix = prefix.lower()

helper/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
${include wait_modified_async_view_event_listener.py}
1212

13+
${include enable_keymap_event_listener.py}
14+
1315
${include surround_with_command.py}
1416

1517
${include delete_surrounded_command.py}

helper/unused_variables_view_event_listener.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def on_modified_async_with_thread(self, recheck=True):
151151

152152
repetitions[variableName] = [variableRegion]
153153

154-
items = Util.nested_lookup("type", ["VariableDeclarator", "MemberExpression", "CallExpression", "BinaryExpression", "ExpressionStatement", "Property", "ArrayExpression", "ObjectPattern", "AssignmentExpression", "IfStatement", "ForStatement", "WhileStatement", "ForInStatement", "ForOfStatement", "LogicalExpression", "UpdateExpression", "ArrowFunctionExpression", "ConditionalExpression", "JSXIdentifier", "ExportDefaultDeclaration", "JSXExpressionContainer", "NewExpression", "ReturnStatement"], body)
154+
items = Util.nested_lookup("type", ["VariableDeclarator", "MemberExpression", "CallExpression", "BinaryExpression", "ExpressionStatement", "Property", "ArrayExpression", "ObjectPattern", "AssignmentExpression", "IfStatement", "ForStatement", "WhileStatement", "ForInStatement", "ForOfStatement", "LogicalExpression", "UpdateExpression", "ArrowFunctionExpression", "ConditionalExpression", "JSXIdentifier", "ExportDefaultDeclaration", "JSXExpressionContainer", "NewExpression", "ReturnStatement", "SpreadProperty", "TemplateLiteral"], body)
155155
for item in items:
156156

157157
if "exportKind" in item and "declaration" in item and isinstance(item["declaration"],dict) and "name" in item["declaration"] and item["declaration"]["type"] == "Identifier":
@@ -177,6 +177,12 @@ def on_modified_async_with_thread(self, recheck=True):
177177

178178
item = item["callee"]
179179

180+
elif "expressions" in item and item["expressions"]:
181+
for expression in item["expressions"]:
182+
if isinstance(expression,dict) and "name" in expression and expression["type"] == "Identifier":
183+
items += [expression]
184+
continue
185+
180186
elif "left" in item or "right" in item:
181187

182188
if "left" in item and isinstance(item["left"],dict) and "name" in item["left"] and item["left"]["type"] == "Identifier":

0 commit comments

Comments
 (0)