Skip to content

Commit

Permalink
fix #20, added a message in the status bar in case of a subprocess.Ca…
Browse files Browse the repository at this point in the history
…lledProcessError error
  • Loading branch information
pichillilorenzo committed Jan 22, 2018
1 parent 31cfb40 commit 2d9608f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from shutil import copyfile
from threading import Timer

PLUGIN_VERSION = "0.13.12"
PLUGIN_VERSION = "0.13.13"

PACKAGE_PATH = os.path.abspath(os.path.dirname(__file__))
PACKAGE_NAME = os.path.basename(PACKAGE_PATH)
Expand Down Expand Up @@ -231,7 +231,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_

# update the PATH environment variable
os.environ.update(new_env)

try:
output = None
result = None
Expand Down Expand Up @@ -272,7 +272,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
# out[0] = out[0].replace("Started a new flow server: -", "")
# out = "\n".join(out)
# result = json.loads(out) if is_output_json else out
out = out[ len(out) - 1 ]
out = out[-1]
if '{"flowVersion":"' in out :
index = out.index('{"flowVersion":"')
out = out[index:]
Expand All @@ -289,10 +289,19 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_

if use_fp_temp :
fp.close()

return [True, result]
except subprocess.CalledProcessError as e:
print(traceback.format_exc())

if e.output:
output_error_message = e.output.decode("utf-8", "ignore").strip()
output_error_message = output_error_message.split("\n")
output_error_message = "\n".join(output_error_message[:-2]) if '{"flowVersion":"' in output_error_message[-1] else "\n".join(output_error_message)

print(e.output)
sublime.active_window().status_message(output_error_message)

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

Expand Down Expand Up @@ -5538,6 +5547,7 @@ def on_modified_async_with_thread(self, recheck=True):
repetitions = dict()

if result[0]:

if "body" in result[1]:
body = result[1]["body"]
items = Util.nested_lookup("type", ["VariableDeclarator", "FunctionDeclaration", "ClassDeclaration", "ImportDefaultSpecifier", "ImportNamespaceSpecifier", "ImportSpecifier", "ArrayPattern", "ObjectPattern"], body)
Expand Down Expand Up @@ -5584,10 +5594,13 @@ def on_modified_async_with_thread(self, recheck=True):

repetitions[variableName] = [variableRegion]

items = Util.nested_lookup("type", ["VariableDeclarator", "MemberExpression", "CallExpression", "BinaryExpression", "ExpressionStatement", "Property", "ArrayExpression", "ObjectPattern", "AssignmentExpression", "IfStatement", "ForStatement", "WhileStatement", "ForInStatement", "ForOfStatement", "LogicalExpression", "UpdateExpression", "ArrowFunctionExpression", "ConditionalExpression"], body)
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"], body)
for item in items:

if "object" in item :
if "exportKind" in item and "declaration" in item and isinstance(item["declaration"],dict) and "name" in item["declaration"] and item["declaration"]["type"] == "Identifier":
item = item["declaration"]

elif "object" in item :
if "property" in item and isinstance(item["property"],dict) and "name" in item["property"] and item["property"]["type"] == "Identifier":
items += [item["property"]]
if "object" in item and isinstance(item["object"],dict) and "name" in item["object"] and item["object"]["type"] == "Identifier":
Expand Down
94 changes: 94 additions & 0 deletions changelog/0.13.13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
v0.13.13

## Fixes

- Fixed "Unused variable shows up in React project" #20

## Improvements

- Added a message in the status bar in case of a subprocess.CalledProcessError error. For example, it could be caused by a malformed .flowconfig in a project.



=================================================================
** THIS PLUGIN IS IN BETA! Thanks for your support in advance! **
=================================================================

If you like it, remember to star it ⭐ on GitHub: https://github.com/pichillilorenzo/JavaScriptEnhancements

** USAGE **
===========

See how it works on the Wiki: 👉👉 https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki 👈👈


** WHAT IS THIS? **
===================

This plugin uses Flow (javascript static type checker from Facebook) under the hood.

It offers better javascript autocomplete and a lot of features about creating,
developing and managing javascript projects, such as:

- Cordova projects (run cordova emulate, build, compile, serve, etc. directly from Sublime Text!)
- Ionic v1 and v2 projects (same as Cordova projects!)
- Angular v1 and v2 projects
- React projects (only about the creation at this moment)
- React Native projects (only about the creation at this moment. I will add also NativeScript support)
- Express projects (only about the creation at this moment)
- Yeoman generators
- Local bookmarks project
- JavaScript real-time errors
- etc.

You could use it also in existing projects (see the Wiki - https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Using-it-with-an-existing-project)!

It turns Sublime Text into a JavaScript IDE like!

This project is based on my other Sublime Text plugin JavaScript Completions (https://github.com/pichillilorenzo/JavaScript-Completions)

** NOTE **
If you want use this plugin, you may want uninstall/disable the JavaScript Completions plugin, if installed.

** OS SUPPORTED NOW **
======================

👉 Linux (64-bit)
👉 Mac OS X
👉 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!

❗❗ Dependencies ❗❗
=======================

In order to work properly, this plugin has some dependencies:

👉 Sublime Text 3 (build 3124 or newer)
👉 Node.js and npm (https://nodejs.org or nvm (https://github.com/creationix/nvm))
👉 TerminalView (only for Linux and Mac OS X) sublime text plugin (https://github.com/Wramberg/TerminalView)

Not required, but useful for typescript files (Flow wont work on this type of files):

👉 TypeScript sublime text plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin)

** Flow Requirements **
=======================

It use [Flow](https://github.com/facebook/flow) for type checking and auto-completions.

👉 Mac OS X
👉 Linux (64-bit)
👉 Windows (64-bit)

Email me for any questions or doubts about this new project on: [email protected]

** Donation **
==============

If this project help you reduce time to develop and also you like it, please support it with a donation 😄👍. Thanks!

Open Collective: https://opencollective.com/javascriptenhancements/donate
PayPal: https://www.paypal.me/LorenzoPichilli

Thanks anyway for your support! 😄😄

MIT License
10 changes: 9 additions & 1 deletion changelog/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ It use [Flow](https://github.com/facebook/flow) for type checking and auto-compl

Email me for any questions or doubts about this new project on: [email protected]

Thanks for your support! 😄😄
** Donation **
==============

If this project help you reduce time to develop and also you like it, please support it with a donation 😄👍. Thanks!

Open Collective: https://opencollective.com/javascriptenhancements/donate
PayPal: https://www.paypal.me/LorenzoPichilli

Thanks anyway for your support! 😄😄

MIT License
13 changes: 11 additions & 2 deletions helper/node/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_

# update the PATH environment variable
os.environ.update(new_env)

try:
output = None
result = None
Expand Down Expand Up @@ -141,7 +141,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
# out[0] = out[0].replace("Started a new flow server: -", "")
# out = "\n".join(out)
# result = json.loads(out) if is_output_json else out
out = out[ len(out) - 1 ]
out = out[-1]
if '{"flowVersion":"' in out :
index = out.index('{"flowVersion":"')
out = out[index:]
Expand All @@ -158,10 +158,19 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_

if use_fp_temp :
fp.close()

return [True, result]
except subprocess.CalledProcessError as e:
print(traceback.format_exc())

if e.output:
output_error_message = e.output.decode("utf-8", "ignore").strip()
output_error_message = output_error_message.split("\n")
output_error_message = "\n".join(output_error_message[:-2]) if '{"flowVersion":"' in output_error_message[-1] else "\n".join(output_error_message)

print(e.output)
sublime.active_window().status_message(output_error_message)

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

Expand Down
8 changes: 6 additions & 2 deletions helper/unused_variables_view_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def on_modified_async_with_thread(self, recheck=True):
repetitions = dict()

if result[0]:

if "body" in result[1]:
body = result[1]["body"]
items = Util.nested_lookup("type", ["VariableDeclarator", "FunctionDeclaration", "ClassDeclaration", "ImportDefaultSpecifier", "ImportNamespaceSpecifier", "ImportSpecifier", "ArrayPattern", "ObjectPattern"], body)
Expand Down Expand Up @@ -141,10 +142,13 @@ def on_modified_async_with_thread(self, recheck=True):

repetitions[variableName] = [variableRegion]

items = Util.nested_lookup("type", ["VariableDeclarator", "MemberExpression", "CallExpression", "BinaryExpression", "ExpressionStatement", "Property", "ArrayExpression", "ObjectPattern", "AssignmentExpression", "IfStatement", "ForStatement", "WhileStatement", "ForInStatement", "ForOfStatement", "LogicalExpression", "UpdateExpression", "ArrowFunctionExpression", "ConditionalExpression"], body)
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"], body)
for item in items:

if "object" in item :
if "exportKind" in item and "declaration" in item and isinstance(item["declaration"],dict) and "name" in item["declaration"] and item["declaration"]["type"] == "Identifier":
item = item["declaration"]

elif "object" in item :
if "property" in item and isinstance(item["property"],dict) and "name" in item["property"] and item["property"]["type"] == "Identifier":
items += [item["property"]]
if "object" in item and isinstance(item["object"],dict) and "name" in item["object"] and item["object"]["type"] == "Identifier":
Expand Down
2 changes: 1 addition & 1 deletion make/_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from shutil import copyfile
from threading import Timer

PLUGIN_VERSION = "0.13.12"
PLUGIN_VERSION = "0.13.13"

PACKAGE_PATH = os.path.abspath(os.path.dirname(__file__))
PACKAGE_NAME = os.path.basename(PACKAGE_PATH)
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"0.13.0": "changelog/0.13.0.txt",
"0.13.1": "changelog/0.13.1.txt",
"0.13.11": "changelog/0.13.11.txt",
"0.13.12": "changelog/0.13.12.txt"
"0.13.12": "changelog/0.13.12.txt",
"0.13.13": "changelog/0.13.13.txt"
}

0 comments on commit 2d9608f

Please sign in to comment.