Skip to content

Commit

Permalink
Show nicer progress indicator when installing server (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Apr 1, 2020
1 parent f625de4 commit cd41e42
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions st3/lsp_utils/server_npm_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
import threading

from sublime_lib import ResourcePath
from sublime_lib import ActivityIndicator, ResourcePath


def run_command(on_exit, on_error, popen_args):
Expand All @@ -28,9 +28,10 @@ def run_in_thread(on_exit, on_error, popen_args):
return thread


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


class ServerNpmResource(object):
Expand All @@ -47,6 +48,7 @@ def __init__(self, package_name, server_directory, server_binary_path):
self._server_directory = server_directory
self._binary_path = server_binary_path
self._package_cache_path = None
self._activity_indicator = None

@property
def ready(self):
Expand Down Expand Up @@ -101,7 +103,13 @@ def _install_dependencies(self, cache_server_path):
# this will be called only when the plugin gets:
# - installed for the first time,
# - or when updated on package control
log_and_show_message('{}: Installing server.'.format(self._package_name))
install_message = '{}: Installing server'.format(self._package_name)
log_and_show_message(install_message, show_in_status=False)

active_window = sublime.active_window()
if active_window:
self._activity_indicator = ActivityIndicator(active_window.active_view(), install_message)
self._activity_indicator.start()

run_command(
self._on_install_success, self._on_install_error,
Expand All @@ -110,8 +118,15 @@ def _install_dependencies(self, cache_server_path):

def _on_install_success(self):
self._is_ready = True
self._stop_indicator()
log_and_show_message(
'{}: Server installed. It\'s recommended to restart Sublime Text.'.format(self._package_name))
'{}: Server installed. Supported files might need to be re-opened.'.format(self._package_name))

def _on_install_error(self, error):
self._stop_indicator()
log_and_show_message('{}: Error while installing the server.'.format(self._package_name), error)

def _stop_indicator(self):
if self._activity_indicator:
self._activity_indicator.stop()
self._activity_indicator = None

0 comments on commit cd41e42

Please sign in to comment.