Skip to content

Commit e318aaa

Browse files
authored
Fix: Use ${node_bin} for the node binary (sublimelsp#41)
With the latest version of lsp_utils a change was introduced [1] that allows using a locally managed node runtime instead of the system one. For that to work, the "node" command needs to use a variable. [1] sublimelsp/lsp_utils@403345a
1 parent 7669198 commit e318aaa

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

LSP-eslint.sublime-settings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"command": ["${node_bin}", "${server_path}", "--stdio"],
23
"languages": [
34
{
45
"languageId": "javascriptreact",

plugin.py

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
from LSP.plugin.core.typing import Any, Dict, Literal, Set, Union
2-
from LSP.plugin.core.url import uri_to_filename
1+
from LSP.plugin.core.typing import Any, Callable, Dict, Literal, Optional, Set
2+
from LSP.plugin import uri_to_filename
3+
from LSP.plugin import WorkspaceFolder
4+
from lsp_utils import notification_handler
35
from lsp_utils import NpmClientHandler
6+
from lsp_utils import request_handler
47
import os
5-
import posixpath
68
import re
79
import sublime
810
import webbrowser
911

1012

11-
def plugin_loaded():
13+
def plugin_loaded() -> None:
1214
LspEslintPlugin.setup()
1315

1416

15-
def plugin_unloaded():
17+
def plugin_unloaded() -> None:
1618
LspEslintPlugin.cleanup()
1719

1820

@@ -21,61 +23,55 @@ class LspEslintPlugin(NpmClientHandler):
2123
server_directory = 'language-server'
2224
server_binary_path = os.path.join(server_directory, 'out', 'eslintServer.js')
2325

24-
@classmethod
25-
def install_in_cache(cls) -> bool:
26-
return False
27-
2826
def __init__(self, *args: Any, **kwargs: Any) -> None:
2927
super().__init__(*args, **kwargs)
3028
self._probe_failed = set() # type: Set[str]
3129

32-
def on_ready(self, api) -> None:
33-
api.on_notification('eslint/status', self.handle_status)
34-
api.on_notification('eslint/exitCalled', self.handle_exit_called)
35-
api.on_notification('eslint/showOutputChannel', self.handle_show_output_channel)
36-
api.on_request('eslint/openDoc', self.handle_open_doc)
37-
api.on_request('eslint/probeFailed', self.handle_probe_failed)
38-
api.on_request('eslint/noConfig', self.handle_no_config)
39-
api.on_request('eslint/noLibrary', self.handle_no_library)
40-
api.on_request('eslint/confirmESLintExecution', self.handle_confirm_execution)
41-
42-
def handle_status(self, params) -> None:
30+
@notification_handler('eslint/status')
31+
def handle_status(self, params: Any) -> None:
4332
pass
4433

45-
def handle_exit_called(self, params) -> None:
34+
@notification_handler('eslint/exitCalled')
35+
def handle_exit_called(self, params: Any) -> None:
4636
pass
4737

48-
def handle_show_output_channel(self, params) -> None:
38+
@notification_handler('eslint/showOutputChannel')
39+
def handle_show_output_channel(self, params: Any) -> None:
4940
sublime.active_window().run_command('lsp_toggle_server_panel')
5041

51-
def handle_open_doc(self, params, respond) -> None:
42+
@request_handler('eslint/openDoc')
43+
def handle_open_doc(self, params: Any, respond: Callable[[Any], None]) -> None:
5244
webbrowser.open(params['url'])
5345
respond({})
5446

55-
def handle_probe_failed(self, params, respond) -> None:
47+
@request_handler('eslint/probeFailed')
48+
def handle_probe_failed(self, params: Any, respond: Callable[[Any], None]) -> None:
5649
self._probe_failed.add(params['textDocument']['uri'])
5750
respond(None)
5851

59-
def handle_no_config(self, params, respond) -> None:
52+
@request_handler('eslint/noConfig')
53+
def handle_no_config(self, params: Any, respond: Callable[[Any], None]) -> None:
6054
# TODO: Show better notification that no eslint configuration was found.
6155
print('LSP-eslint: Could not find eslint configuration ({}) for {}'.format(
6256
params['message'], params['document']['uri']))
6357
respond(None)
6458

65-
def handle_no_library(self, params, respond) -> None:
59+
@request_handler('eslint/noLibrary')
60+
def handle_no_library(self, params: Any, respond: Callable[[Any], None]) -> None:
6661
# TODO: Show better notification that no eslint library was found.
6762
print('LSP-eslint: Failed resolving eslint library for {}'.format(params['source']['uri']))
6863
respond(None)
6964

70-
def handle_confirm_execution(self, params, respond) -> None:
65+
@request_handler('eslint/confirmESLintExecution')
66+
def handle_confirm_execution(self, params: Any, respond: Callable[[Any], None]) -> None:
7167
respond(4) # ConfirmExecutionResult.approved
7268

73-
def on_workspace_configuration(self, params, configuration) -> None:
69+
def on_workspace_configuration(self, params: Any, configuration: Dict) -> None:
7470
session = self.weaksession()
7571
if session:
7672
scope_uri = params.get('scopeUri')
7773
if scope_uri:
78-
workspace_folder = None
74+
workspace_folder = None # type: Optional[WorkspaceFolder]
7975
for folder in session.get_workspace_folders():
8076
if folder.includes_uri(scope_uri):
8177
workspace_folder = folder
@@ -90,7 +86,8 @@ def on_workspace_configuration(self, params, configuration) -> None:
9086
configuration['validate'] = 'on'
9187
del configuration['probe']
9288

93-
def resolve_working_directory(self, configuration, scope_uri, workspace_folder) -> None:
89+
def resolve_working_directory(self, configuration: Dict, scope_uri: str,
90+
workspace_folder: Optional[WorkspaceFolder]) -> None:
9491
working_directories = configuration.get('workingDirectories', None)
9592
if isinstance(working_directories, list):
9693
working_directory = None
@@ -132,25 +129,27 @@ def resolve_working_directory(self, configuration, scope_uri, workspace_folder)
132129
configuration['workingDirectory'] = working_directory
133130
configuration.pop('workingDirectories', None)
134131

135-
def is_working_directory_item(self, item, configuration_key) -> bool:
132+
def is_working_directory_item(self, item: Any, configuration_key: str) -> bool:
136133
if isinstance(item, dict):
137134
value = item.get(configuration_key, None)
138135
not_cwd = item.get('!cwd', None)
139136
return isinstance(value, str) and (isinstance(not_cwd, bool) or not_cwd is None)
140137
return False
141138

142-
def is_mode_item(self, item) -> bool:
139+
def is_mode_item(self, item: Any) -> bool:
143140
if isinstance(item, dict):
144141
mode = item.get('mode', None)
145142
return isinstance(mode, str) and mode in ('auto', 'location')
146143
return False
147144

148-
def to_os_path(self, path) -> str:
145+
def to_os_path(self, path: str) -> str:
149146
if sublime.platform == 'windows':
150147
path = re.sub(r'^\/(\w)\/', r'\1:\\', path)
151148
return os.path.normpath(path)
152149

153-
def compute_validate(self, language_id: str, scope_uri: str, config: Dict[str, Any]) -> Literal['off', 'on', 'probe']:
150+
def compute_validate(
151+
self, language_id: str, scope_uri: str, config: Dict[str, Any]
152+
) -> Literal['off', 'on', 'probe']:
154153
validate = config.get('validate')
155154
if isinstance(validate, list):
156155
for validate_langugage_id in validate:
@@ -162,5 +161,5 @@ def compute_validate(self, language_id: str, scope_uri: str, config: Dict[str, A
162161
if isinstance(probe, list):
163162
for probe_language_id in probe:
164163
if probe_language_id == language_id:
165-
return 'probe';
166-
return 'off';
164+
return 'probe'
165+
return 'off'

0 commit comments

Comments
 (0)