Skip to content

Commit

Permalink
Revert "Eslint server already comes bundled in the vscode-eslint fold…
Browse files Browse the repository at this point in the history
…er, so there is no need to run npm install in the plugin_loaded hook" because Predrag obviously didn't know what he was doing

This reverts commit 6f47bed.
  • Loading branch information
predragnikolic committed Dec 15, 2019
1 parent 6f47bed commit c504697
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import shutil
import sublime
import subprocess
import threading
import webbrowser

from LSP.plugin.core.handlers import LanguageHandler
Expand All @@ -11,16 +13,62 @@

package_path = os.path.dirname(__file__)
server_path = os.path.join(package_path, 'vscode-eslint', 'out', 'eslintServer.js')
vscode_eslint_path = os.path.join(package_path, 'vscode-eslint')
node_modules_path = os.path.join(vscode_eslint_path, 'node_modules')


def plugin_loaded():
print('LSP-eslint: Server is installed.')
dependencies_insalled = os.path.isdir(node_modules_path)
print('LSP-eslint: Server {} installed.'.format('is' if dependencies_insalled else 'is not'))

if not dependencies_insalled:
# this will be called only when the plugin gets:
# - installed for the first time,
# - or when updated on package control
logAndShowMessage('LSP-eslint: Installing server.')

runCommand(
onCommandDone,
["npm", "install", "--verbose", "--prefix", vscode_eslint_path, vscode_eslint_path]
)


def onCommandDone():
logAndShowMessage('LSP-eslint: Server installed.')


def runCommand(onExit, popenArgs):
"""
Runs the given args in a subprocess.Popen, and then calls the function
onExit when the subprocess completes.
onExit is a callable object, and popenArgs is a list/tuple of args that
would give to subprocess.Popen.
"""
def runInThread(onExit, popenArgs):
try:
if sublime.platform() == 'windows':
subprocess.check_call(popenArgs, shell=True)
else:
subprocess.check_call(popenArgs)
onExit()
except subprocess.CalledProcessError as error:
logAndShowMessage('LSP-eslint: Error while installing the server.', error)
return
thread = threading.Thread(target=runInThread, args=(onExit, popenArgs))
thread.start()
# returns immediately after the thread starts
return thread


def is_node_installed():
return shutil.which('node') is not None


def logAndShowMessage(msg, additional_logs=None):
print(msg, '\n', additional_logs) if additional_logs else print(msg)
sublime.active_window().status_message(msg)


class LspEslintPlugin(LanguageHandler):
@property
def name(self) -> str:
Expand Down

0 comments on commit c504697

Please sign in to comment.