Skip to content

Commit

Permalink
refactor: remove legacy ST3 code (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Oct 16, 2023
1 parent 7483345 commit fb75101
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 190 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LSP utilities for Package Control

Module with LSP-related utilities for Sublime Text
Module with LSP-related utilities for Sublime Text.

📘 [Documentation](https://sublimelsp.github.io/lsp_utils/)

Expand Down
8 changes: 1 addition & 7 deletions st3/lsp_utils/_client_handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from .abstract_plugin import ClientHandler
from .api_decorator import notification_handler
from .api_decorator import request_handler
from LSP.plugin import __version__ as lsp_version


if lsp_version < (1, 0, 0):
from .language_handler import ClientHandler # type: ignore
else:
from .abstract_plugin import ClientHandler

__all__ = [
'ClientHandler',
Expand Down
173 changes: 0 additions & 173 deletions st3/lsp_utils/_client_handler/language_handler.py

This file was deleted.

2 changes: 1 addition & 1 deletion st3/lsp_utils/_util/weak_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# [1] https://github.com/SublimeText/sublime_lib/blob/master/st3/sublime_lib/_util/weak_method.py

def weak_method(method: Callable[..., Any]) -> Callable:
def weak_method(method: Callable[..., Any]) -> Callable[..., Any]:
assert isinstance(method, MethodType)
self_ref = weakref.ref(method.__self__)
function_ref = weakref.ref(method.__func__)
Expand Down
10 changes: 5 additions & 5 deletions st3/lsp_utils/node_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get(
) -> Optional['NodeRuntime']:
if isinstance(required_node_version, tuple):
required_semantic_version = NpmSpec('>={}'.format(version_to_string(required_node_version)))
elif isinstance(required_node_version, str):
else:
required_semantic_version = NpmSpec(required_node_version)
if cls._node_runtime_resolved:
if cls._node_runtime:
Expand Down Expand Up @@ -181,17 +181,17 @@ def run_node(
stdout: int = subprocess.PIPE,
stderr: int = subprocess.PIPE,
env: Dict[str, Any] = {}
) -> Optional[subprocess.Popen]:
) -> Optional['subprocess.Popen[bytes]']:
node_bin = self.node_bin()
if node_bin is None:
return None
os_env = os.environ.copy()
os_env.update(self.node_env())
os_env.update(env)
startupinfo = None
if sublime.platform() == 'windows':
startupinfo = subprocess.STARTUPINFO() # type: ignore
startupinfo.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW # type: ignore
if sys.platform == 'win32':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW
return subprocess.Popen(
[node_bin] + args, stdin=stdin, stdout=stdout, stderr=stderr, env=os_env, startupinfo=startupinfo)

Expand Down
18 changes: 15 additions & 3 deletions st3/lsp_utils/server_npm_resource.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .helpers import SemanticVersion
from .node_runtime import NodeRuntime
from .server_resource_interface import ServerResourceInterface
from .server_resource_interface import ServerStatus
from hashlib import md5
from LSP.plugin.core.typing import Dict, Optional
from LSP.plugin.core.typing import Dict, Optional, TypedDict, Union
from os import makedirs
from os import path
from os import remove
Expand All @@ -12,6 +13,17 @@

__all__ = ['ServerNpmResource']

ServerNpmResourceCreateOptions = TypedDict('ServerNpmResourceCreateOptions', {
'package_name': str,
'server_directory': str,
'server_binary_path': str,
'package_storage': str,
'storage_path': str,
'minimum_node_version': SemanticVersion,
'required_node_version': str,
'skip_npm_install': bool,
})


class ServerNpmResource(ServerResourceInterface):
"""
Expand All @@ -20,14 +32,14 @@ class ServerNpmResource(ServerResourceInterface):
"""

@classmethod
def create(cls, options: Dict) -> 'ServerNpmResource':
def create(cls, options: ServerNpmResourceCreateOptions) -> 'ServerNpmResource':
package_name = options['package_name']
server_directory = options['server_directory']
server_binary_path = options['server_binary_path']
package_storage = options['package_storage']
storage_path = options['storage_path']
minimum_node_version = options['minimum_node_version']
required_node_version = options['required_node_version']
required_node_version = options['required_node_version'] # type: Union[str, SemanticVersion]
skip_npm_install = options['skip_npm_install']
# Fallback to "minimum_node_version" if "required_node_version" is 0.0.0 (not overridden).
if '0.0.0' == required_node_version:
Expand Down

0 comments on commit fb75101

Please sign in to comment.