|
1 | 1 | import os
|
2 |
| -import shutil |
3 |
| -import sublime |
4 | 2 | import webbrowser
|
5 | 3 |
|
6 |
| -from LSP.plugin.core.handlers import LanguageHandler |
7 |
| -from LSP.plugin.core.protocol import Response |
8 |
| -from LSP.plugin.core.settings import ClientConfig |
9 |
| -from LSP.plugin.core.settings import read_client_config |
10 |
| -from lsp_utils import ServerNpmResource |
11 |
| - |
12 |
| -PACKAGE_NAME = 'LSP-eslint' |
13 |
| -SETTINGS_FILENAME = 'LSP-eslint.sublime-settings' |
14 |
| -SERVER_DIRECTORY = 'vscode-eslint' |
15 |
| -SERVER_BINARY_PATH = os.path.join(SERVER_DIRECTORY, 'out', 'eslintServer.js') |
16 |
| - |
17 |
| -server = ServerNpmResource(PACKAGE_NAME, SERVER_DIRECTORY, SERVER_BINARY_PATH) |
| 4 | +from lsp_utils import NpmClientHandler |
18 | 5 |
|
19 | 6 |
|
20 | 7 | def plugin_loaded():
|
21 |
| - server.setup() |
| 8 | + LspEslintPlugin.setup() |
22 | 9 |
|
23 | 10 |
|
24 | 11 | def plugin_unloaded():
|
25 |
| - server.cleanup() |
26 |
| - |
27 |
| - |
28 |
| -def is_node_installed(): |
29 |
| - return shutil.which('node') is not None |
30 |
| - |
31 |
| - |
32 |
| -class LspEslintPlugin(LanguageHandler): |
33 |
| - @property |
34 |
| - def name(self) -> str: |
35 |
| - return PACKAGE_NAME.lower() |
36 |
| - |
37 |
| - @property |
38 |
| - def config(self) -> ClientConfig: |
39 |
| - settings = sublime.load_settings(SETTINGS_FILENAME) |
40 |
| - client_configuration = settings.get('client') |
41 |
| - if client_configuration is None: |
42 |
| - client_configuration = {} |
43 |
| - |
44 |
| - # Calling setup() also here as this might run before `plugin_loaded`. |
45 |
| - # Will be a no-op if already ran. |
46 |
| - # See https://github.com/sublimelsp/LSP/issues/899 |
47 |
| - server.setup() |
48 |
| - |
49 |
| - default_configuration = { |
50 |
| - 'enabled': True, |
51 |
| - 'command': ['node', server.binary_path, '--stdio'], |
52 |
| - "languages": [ |
53 |
| - { |
54 |
| - "languageId": "eslint", |
55 |
| - "scopes": ["source.js", "text.html.vue"], |
56 |
| - "syntaxes": [ |
57 |
| - "Packages/Vue Syntax Highlight/Vue Component.sublime-syntax", |
58 |
| - "Packages/JavaScript/JavaScript.sublime-syntax", |
59 |
| - "Packages/User/JS Custom/Syntaxes/React.sublime-syntax", |
60 |
| - "Packages/JavaScript/JavaScript.sublime-syntax", |
61 |
| - "Packages/Babel/JavaScript (Babel).sublime-syntax" |
62 |
| - ] |
63 |
| - } |
64 |
| - ], |
65 |
| - "settings": { |
66 |
| - "validate": True, |
67 |
| - "packageManager": "npm", |
68 |
| - "autoFix": True, |
69 |
| - "autoFixOnSave": True, |
70 |
| - "options": {}, |
71 |
| - "run": "onType", |
72 |
| - "nodePath": None, |
73 |
| - "quiet": False, |
74 |
| - "workspaceFolder": None, |
75 |
| - "codeAction": { |
76 |
| - "disableRuleComment": { |
77 |
| - "enable": True, |
78 |
| - "location": "separateLine" |
79 |
| - }, |
80 |
| - "showDocumentation": { |
81 |
| - "enable": True |
82 |
| - } |
83 |
| - } |
84 |
| - } |
85 |
| - } |
| 12 | + LspEslintPlugin.cleanup() |
86 | 13 |
|
87 |
| - default_configuration.update(client_configuration) |
88 |
| - return read_client_config(self.name, default_configuration) |
89 | 14 |
|
90 |
| - def on_start(self, window) -> bool: |
91 |
| - if not is_node_installed(): |
92 |
| - sublime.status_message("{}: Please install Node.js for the server to work.".format(PACKAGE_NAME)) |
93 |
| - return False |
94 |
| - return server.ready |
| 15 | +class LspEslintPlugin(NpmClientHandler): |
| 16 | + package_name = __package__ |
| 17 | + server_directory = 'vscode-eslint' |
| 18 | + server_binary_path = os.path.join(server_directory, 'out', 'eslintServer.js') |
95 | 19 |
|
96 |
| - def on_initialized(self, client) -> None: |
97 |
| - client.on_notification('eslint/status', self.handle_status) |
98 |
| - client.on_request( |
99 |
| - 'eslint/openDoc', |
100 |
| - lambda params, request_id: self.handle_open_doc(client, params, request_id)) |
| 20 | + def on_ready(self, api) -> None: |
| 21 | + api.on_notification('eslint/status', self.handle_status) |
| 22 | + api.on_request('eslint/openDoc', self.handle_open_doc) |
101 | 23 |
|
102 | 24 | def handle_status(self, params) -> None:
|
103 | 25 | pass
|
104 | 26 |
|
105 |
| - def handle_open_doc(self, client, params, request_id) -> None: |
| 27 | + def handle_open_doc(self, params, respond) -> None: |
106 | 28 | webbrowser.open(params['url'])
|
107 |
| - client.send_response(Response(request_id, {})) |
| 29 | + respond({}) |
0 commit comments