Skip to content

Commit

Permalink
Merge pull request #15 from Galooshi/find-named-exports
Browse files Browse the repository at this point in the history
Find named exports
  • Loading branch information
trotzig authored Jan 31, 2017
2 parents 2a0e50b + af7997b commit 792a3c3
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions import-js.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess

import_js_environment = {}
daemons = {}
daemon = None


def extract_path():
Expand Down Expand Up @@ -54,10 +54,10 @@ def plugin_loaded():
print(import_js_environment)

def plugin_unloaded():
global daemons
for cwd, daemon in daemons.items():
print('Stopping ImportJS daemon process for cwd ' + cwd)
daemon.terminate()
global daemon
print('Stopping ImportJS daemon process')
daemon.terminate()
daemon = None

def no_executable_error(executable):
return dedent('''
Expand Down Expand Up @@ -94,18 +94,18 @@ class ImportJsCommand(sublime_plugin.TextCommand):
def project_root(self):
return self.view.window().extract_variables()['folder']

def start_or_get_daemon(self, cwd):
global daemons
if (cwd in daemons):
return daemons[cwd]
def start_or_get_daemon(self):
global daemon
if (daemon != None):
return daemon

is_windows = os.name == 'nt'
executable = 'importjsd'

try:
daemon = subprocess.Popen(
[executable, 'start', '--parent-pid', str(os.getppid())],
cwd=cwd,
cwd=self.project_root(),
env=import_js_environment,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
Expand All @@ -118,8 +118,6 @@ def start_or_get_daemon(self, cwd):
# commands.
daemon.stdout.readline()

daemons[cwd] = daemon

return daemon
except FileNotFoundError as e:
if(e.strerror.find(executable) > -1):
Expand Down Expand Up @@ -153,7 +151,7 @@ def run(self, edit, **args):


print(payload)
process = self.start_or_get_daemon(self.project_root())
process = self.start_or_get_daemon()
process.stdin.write((json.dumps(payload) + '\n').encode('utf-8'))
process.stdin.flush()
resultJson = process.stdout.readline().decode('utf-8')
Expand All @@ -180,8 +178,7 @@ def handle_resolved_imports(resolved_imports):
return

if(cmd == 'goto'):
self.view.window().open_file(
self.project_root() + '/' + result.get('goto'))
self.view.window().open_file(result.get('goto'))
else:
self.view.run_command("import_js_replace",
{"characters": result.get('fileContent')})
Expand Down

0 comments on commit 792a3c3

Please sign in to comment.