Skip to content

Commit

Permalink
Use sublime.packages_path()
Browse files Browse the repository at this point in the history
  • Loading branch information
predragnikolic committed Jul 28, 2019
1 parent 2da99dc commit 69e0b8f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 28 deletions.
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 44 additions & 17 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,73 @@
import shutil
import os
import sublime
import threading
import subprocess

from LSP.plugin.core.handlers import LanguageHandler
from LSP.plugin.core.settings import ClientConfig, LanguageConfig


package_path = os.path.dirname(__file__)
server_path = os.path.join(package_path, 'node_modules', 'vue-language-server', 'bin', 'vls')


def plugin_loaded():
package_path = os.path.join(sublime.packages_path(), 'LSP-vue')
server_path = os.path.join(package_path, 'node_modules', 'vue-language-server', 'bin', 'vls')
print('LSP-vue: Server {} installed.'.format('is' if os.path.isfile(server_path) else 'is not' ))

# install the node_modules if not installed
if not os.path.isdir(os.path.join(package_path, 'node_modules')):
# install server if no node_modules
print('LSP-vue: Installing server.')
sublime.active_window().run_command(
"exec", {
"cmd": [
"npm",
"install",
"--verbose",
"--prefix",
package_path
]
}
# this will be called only when the plugin gets:
# - installed for the first time,
# - or when updated on package control
logAndShowMessage('LSP-vue: Installing server.')

runCommand(
onCommandDone,
["npm", "install", "--verbose", "--prefix", package_path]
)
sublime.message_dialog('LSP-vue\n\nRestart sublime after the server has been installed successfully.')


def onCommandDone():
logAndShowMessage('LSP-vue: 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:
subprocess.check_call(popenArgs)
onExit()
except subprocess.CalledProcessError as error:
logAndShowMessage('LSP-vue: 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 LspVuePlugin(LanguageHandler):
@property
def name(self) -> str:
return 'lsp-vue'

@property
def config(self) -> ClientConfig:
package_path = os.path.join(sublime.packages_path(), 'LSP-vue')
server_path = os.path.join(package_path, 'node_modules', 'vue-language-server', 'bin', 'vls')
settings = sublime.load_settings("LSP-vue.sublime-settings")
return ClientConfig(
name='lsp-vue',
Expand Down

0 comments on commit 69e0b8f

Please sign in to comment.