Skip to content

Commit

Permalink
add setting to choose priority and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Feb 17, 2021
1 parent b03dfb9 commit f914508
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion st3/lsp_utils/api_wrapper_interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABCMeta, abstractmethod
from LSP.plugin.core.typing import Any, Callable, Optional
from LSP.plugin.core.typing import Any, Callable

__all__ = ['ApiWrapperInterface']

Expand Down
2 changes: 1 addition & 1 deletion st3/lsp_utils/node_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def npm_install(self, package_dir: str, use_ci: bool = True) -> None:
'--prefix', package_dir,
package_dir
]
output, error = run_command_sync(args)
_, error = run_command_sync(args)
if error is not None:
raise Exception('Failed to run npm command "{}":\n{}'.format(' '.join(args), error))

Expand Down
57 changes: 28 additions & 29 deletions st3/lsp_utils/server_npm_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .helpers import log_and_show_message
from .helpers import parse_version
from .helpers import run_command_sync
from .helpers import SemanticVersion
from .helpers import version_to_string
from .node_distribution import NodeDistribution
Expand Down Expand Up @@ -53,33 +51,34 @@ def create(cls, options: Dict) -> Optional['ServerNpmResource']:
def resolve_node_distribution(
cls, package_name: str, minimum_node_version: SemanticVersion, storage_path: str
) -> Optional[NodeDistribution]:
# Try with node on the PATH first.
node_distribution = NodeDistributionPATH()
node_version = None
if node_distribution.node_exists():
try:
cls.check_node_version(node_distribution, minimum_node_version)
return node_distribution
except Exception as ex:
message = 'Ignoring Node on PATH due to an error. {}'.format(ex)
log_and_show_message('{}: Warning: {}'.format(package_name, message))
# Failed resolving Node on the PATH. Falling back to local Node.
node_distribution = NodeDistributionLocal(path.join(storage_path, 'lsp_utils', 'node-dist'))
if not node_distribution.node_exists():
if not sublime.ok_cancel_dialog(NO_NODE_FOUND_MESSAGE.format(package_name=package_name), 'Install Node'):
return
try:
node_distribution.install_node()
except Exception as ex:
log_and_show_message('{}: Error: Failed installing a local Node:\n{}'.format(package_name, ex))
return
if node_distribution.node_exists():
try:
cls.check_node_version(node_distribution, minimum_node_version)
return node_distribution
except Exception as ex:
error = 'Ignoring local Node due to an error. {}'.format(ex)
log_and_show_message('{}: Error: {}'.format(package_name, error))
selected_distributions = sublime.load_settings('lsp_utils.sublime-settings').get('node_distributions')
for distribution in selected_distributions:
if distribution == 'system':
node_distribution = NodeDistributionPATH()
if node_distribution.node_exists():
try:
cls.check_node_version(node_distribution, minimum_node_version)
return node_distribution
except Exception as ex:
message = 'Ignoring system Node due to an error. {}'.format(ex)
log_and_show_message('{}: Error: {}'.format(package_name, message))
elif distribution == 'local':
node_distribution = NodeDistributionLocal(path.join(storage_path, 'lsp_utils', 'node-dist'))
if not node_distribution.node_exists():
if not sublime.ok_cancel_dialog(NO_NODE_FOUND_MESSAGE.format(package_name=package_name), 'Install Node'):
return
try:
node_distribution.install_node()
except Exception as ex:
log_and_show_message('{}: Error: Failed installing a local Node:\n{}'.format(package_name, ex))
return
if node_distribution.node_exists():
try:
cls.check_node_version(node_distribution, minimum_node_version)
return node_distribution
except Exception as ex:
error = 'Ignoring local Node due to an error. {}'.format(ex)
log_and_show_message('{}: Error: {}'.format(package_name, error))

@classmethod
def check_node_version(cls, node_distribution: NodeDistribution, minimum_node_version: SemanticVersion) -> None:
Expand Down

0 comments on commit f914508

Please sign in to comment.