Skip to content

Commit

Permalink
code refactoring, fixed an issue about go-to-definition, added flow w…
Browse files Browse the repository at this point in the history
…arnings
  • Loading branch information
pichillilorenzo committed Mar 7, 2018
1 parent 012dcd9 commit f42af12
Show file tree
Hide file tree
Showing 43 changed files with 1,010 additions and 1,353 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Expand Up @@ -21,7 +21,7 @@ before_install:
install:
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then
brew update;
brew upgrade python;
brew install python || brew upgrade python;
fi
- sh travis.sh bootstrap
- sh travis.sh install_color_scheme_unit
Expand All @@ -35,6 +35,4 @@ after_success:
- codecov

notifications:
email:
on_success: change
on_failure: change
email: false
2 changes: 1 addition & 1 deletion Default.sublime-keymap
Expand Up @@ -19,7 +19,7 @@
},
{
"keys": ["super+alt+g"],
"command": "javascript_enhancements_go_to_def"
"command": "javascript_enhancements_go_to_definition"
},
{
"keys": ["super+alt+s"],
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Lorenzo Pichilli
Copyright (c) 2017-2018 Lorenzo Pichilli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -47,7 +47,7 @@ If you want use this plugin, you may want **uninstall/disable** the **JavaScript
In order to work properly, this plugin has some dependencies:

- **Sublime Text 3** (build **3124** or newer)
- **Node.js** and **npm** ([nodejs.org](https://nodejs.org) or [nvm](https://github.com/creationix/nvm))
- **Node.js** (6 or upper) and **npm** ([nodejs.org](https://nodejs.org) or [nvm](https://github.com/creationix/nvm))
- **TerminalView** (only for _Linux_ and _Mac OS X_) sublime text plugin ([TerminalView](https://github.com/Wramberg/TerminalView))

**Not required**, but **useful** for typescript files (Flow wont work on this type of files):
Expand Down
3 changes: 2 additions & 1 deletion changelog/0.16.0.txt
Expand Up @@ -11,12 +11,13 @@ v0.16.0
## Improvements

- Complete code plugin refactoring
- Improved completions performance
- Improved completions performance using 'flow ide' command
- Added "code screenshot" feature using [carbon](https://carbon.now.sh/)
- updated flow-bin to 0.66.0
- Added initial support for Vue.js
- Improved extract method feature
- Improved completions detection from default_autocomplete.json
- Added flow warnings


=================================================================
Expand Down
4 changes: 3 additions & 1 deletion main.py
Expand Up @@ -2,11 +2,11 @@
import os, platform, shutil, tempfile, json, re, sys
from subprocess import Popen, PIPE
from .src.libs.global_vars import *
from .src.libs.flow import *
from .src.libs import util
from .src.libs import *
from .src.commands import *
from .src.listeners import *
from .tests import *

keymaps = util.open_json(os.path.join(PACKAGE_PATH, 'Default.sublime-keymap'))
for keymap in keymaps:
Expand Down Expand Up @@ -87,6 +87,8 @@ def start():
shutil.rmtree(node_modules_path)
sublime.error_message("Error during installation: can't install npm dependencies for JavaScript Enhancements plugin.\n\nThe error COULD be caused by the npm permission access (EACCES error), so in this case you need to repair/install node.js and npm in a way that doesn't require \"sudo\" command.\n\nFor example you could use a Node Version Manager, such as \"nvm\" or \"nodenv\".\n\nTry to run \"npm install\" inside the package of this plugin to see what you get.")
return

Hook.apply('plugin_ready')

sublime.set_timeout_async(lambda: util.overwrite_default_javascript_snippet())

Expand Down
2 changes: 1 addition & 1 deletion src/commands/bookmarks.py
Expand Up @@ -238,4 +238,4 @@ def is_visible(self):
return util.is_javascript_project()

class JavascriptEnhancementsNavigateProjectBookmarksCommand(JavascriptEnhancementsNavigateRegionsCommand, sublime_plugin.TextCommand):
region_key = "javascript_enhancements_region_bookmarks"
region_keys = ["javascript_enhancements_region_bookmarks"]
2 changes: 1 addition & 1 deletion src/commands/can_i_use/can_i_use_data.json

Large diffs are not rendered by default.

48 changes: 7 additions & 41 deletions src/commands/go_to_definition.py
Expand Up @@ -2,7 +2,7 @@
import os
from ..libs import NodeJS
from ..libs import util
from ..libs import flow
from ..libs import FlowCLI

class JavascriptEnhancementsGoToDefinitionCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
Expand All @@ -26,50 +26,16 @@ def go_to_def(self, view, point):
def find_def(self, view, point) :
view.sel().add(point)

flow_cli = "flow"
is_from_bin = True
chdir = ""
use_node = True
bin_path = ""

settings = util.get_project_settings()
if settings and settings["project_settings"]["flow_cli_custom_path"]:
flow_cli = os.path.basename(settings["project_settings"]["flow_cli_custom_path"])
bin_path = os.path.dirname(settings["project_settings"]["flow_cli_custom_path"])
is_from_bin = False
chdir = settings["project_dir_name"]
use_node = False

deps = flow.parse_cli_dependencies(view)

node = NodeJS(check_local=True)

result = node.execute_check_output(
flow_cli,
[
'get-def',
'--from', 'sublime_text',
'--root', deps.project_root,
'--json',
':temp_file',
str(deps.row + 1), str(deps.col + 1)
],
is_from_bin=is_from_bin,
use_fp_temp=True,
fp_temp_contents=deps.contents,
is_output_json=True,
use_only_filename_view_flow=True,
chdir=chdir,
bin_path=bin_path,
use_node=use_node
)
flow_cli = FlowCLI(view)
result = flow_cli.get_def()

if result[0] :
row = result[1]["line"] - 1
col = result[1]["start"] - 1
if result[1]["path"] != "-" and os.path.isfile(result[1]["path"]) :
view = sublime.active_window().open_file(result[1]["path"])
util.go_to_centered(view, row, col)
if row >= 0:
if result[1]["path"] != "-" and os.path.isfile(result[1]["path"]) :
view = sublime.active_window().open_file(result[1]["path"])
util.go_to_centered(view, row, col)

def is_enabled(self, **args):
view = self.view
Expand Down
2 changes: 1 addition & 1 deletion src/commands/navigate_flow_errors.py
Expand Up @@ -2,4 +2,4 @@
from .navigate_regions import JavascriptEnhancementsNavigateRegionsCommand

class JavascriptEnhancementsNavigateFlowErrorsCommand(JavascriptEnhancementsNavigateRegionsCommand, sublime_plugin.TextCommand):
region_key = "javascript_enhancements_flow_error"
region_keys = ["javascript_enhancements_flow_error", "javascript_enhancements_flow_warning"]
9 changes: 7 additions & 2 deletions src/commands/navigate_regions.py
Expand Up @@ -2,13 +2,18 @@

class JavascriptEnhancementsNavigateRegionsCommand():

region_key = ""
region_keys = []

def run(self, edit, **args) :

view = self.view
regions = []

regions = view.get_regions(self.region_key)
for region_key in self.region_keys:
regions += view.get_regions(region_key)

regions = sorted(regions, key=lambda region: region.begin())

if not regions:
return

Expand Down
2 changes: 1 addition & 1 deletion src/commands/navigate_unused_variables.py
Expand Up @@ -2,4 +2,4 @@
from .navigate_regions import JavascriptEnhancementsNavigateRegionsCommand

class JavascriptEnhancementsNavigateUnusedVariablesCommand(JavascriptEnhancementsNavigateRegionsCommand, sublime_plugin.TextCommand):
region_key = "javascript_enhancements_unused_variable"
region_keys = ["javascript_enhancements_unused_variable"]
34 changes: 3 additions & 31 deletions src/commands/refactor/convert_to_arrow_function.py
@@ -1,43 +1,15 @@
import sublime, sublime_plugin
import os, traceback
from ...libs import util
from ...libs import NodeJS
from ...libs import FlowCLI

class JavascriptEnhancementsRefactorConvertToArrowFunctionCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
view = self.view
selection = view.sel()[0]

flow_cli = "flow"
is_from_bin = True
chdir = ""
use_node = True
bin_path = ""

settings = util.get_project_settings()
if settings and settings["project_settings"]["flow_cli_custom_path"]:
flow_cli = os.path.basename(settings["project_settings"]["flow_cli_custom_path"])
bin_path = os.path.dirname(settings["project_settings"]["flow_cli_custom_path"])
is_from_bin = False
chdir = settings["project_dir_name"]
use_node = False

node = NodeJS(check_local=True)

result = node.execute_check_output(
flow_cli,
[
'ast',
'--from', 'sublime_text'
],
is_from_bin=is_from_bin,
use_fp_temp=True,
fp_temp_contents=view.substr(sublime.Region(0, view.size())),
is_output_json=True,
chdir=chdir,
bin_path=bin_path,
use_node=use_node
)
flow_cli = FlowCLI(view)
result = flow_cli.ast()

if result[0]:

Expand Down
49 changes: 4 additions & 45 deletions src/commands/refactor/export.py
@@ -1,7 +1,7 @@
import sublime, sublime_plugin
import os, traceback
from ...libs import util
from ...libs import NodeJS
from ...libs import FlowCLI
from ...libs import window_view_manager
from .refactor_preview import RefactorPreview

Expand Down Expand Up @@ -59,36 +59,8 @@ def run(self, edit, **args):
preview_view = RefactorPreview("Refactor - Export " + tp.title() + " Preview")
preview_view.append_text("Refactor - Export " + tp.title() + " Preview\n\n")

flow_cli = "flow"
is_from_bin = True
chdir = ""
use_node = True
bin_path = ""

settings = util.get_project_settings()
if settings and settings["project_settings"]["flow_cli_custom_path"]:
flow_cli = os.path.basename(settings["project_settings"]["flow_cli_custom_path"])
bin_path = os.path.dirname(settings["project_settings"]["flow_cli_custom_path"])
is_from_bin = False
chdir = settings["project_dir_name"]
use_node = False

node = NodeJS(check_local=True)

result = node.execute_check_output(
flow_cli,
[
'ast',
'--from', 'sublime_text'
],
is_from_bin=is_from_bin,
use_fp_temp=True,
fp_temp_contents=view.substr(sublime.Region(0, view.size())),
is_output_json=True,
chdir=chdir,
bin_path=bin_path,
use_node=use_node
)
flow_cli = FlowCLI(view)
result = flow_cli.ast()

if result[0]:

Expand Down Expand Up @@ -127,20 +99,7 @@ def run(self, edit, **args):

if file_already_exists:
with open(new_path, "r+", encoding="utf-8") as file:
result_exists = node.execute_check_output(
flow_cli,
[
'ast',
'--from', 'sublime_text'
],
is_from_bin=is_from_bin,
use_fp_temp=True,
fp_temp_contents=file.read(),
is_output_json=True,
chdir=chdir,
bin_path=bin_path,
use_node=use_node
)
result_exists = flow_cli.ast(contents=file.read())
if result_exists[0]:
body2 = result_exists[1]["body"]
items2 = util.nested_lookup("type", ["ExportDefaultDeclaration"], body2)
Expand Down

0 comments on commit f42af12

Please sign in to comment.