Skip to content

Commit 1c4d1c3

Browse files
rchlrwols
authored andcommitted
Switch to NpmClientHandler
Also re-adds some things that were reverted in previous commits.
1 parent c5f93bf commit 1c4d1c3

File tree

8 files changed

+107
-137
lines changed

8 files changed

+107
-137
lines changed

LSP-eslint.sublime-commands

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"caption": "Preferences: LSP-eslint Settings",
44
"command": "edit_settings",
55
"args": {
6-
"base_file": "${packages}/LSP-eslint/LSP-eslint.sublime-settings",
7-
"default": "// Settings in here override those in \"LSP-eslint/LSP-eslint.sublime-settings\",\n\n{\n\t$0\n}\n"
6+
"base_file": "${packages}/LSP-eslint/LSP-eslint.sublime-settings",
7+
"default": "// Settings in here override those in \"LSP-eslint/LSP-eslint.sublime-settings\"\n\n{\n\t$0\n}\n"
88
}
99
},
1010
]

LSP-eslint.sublime-settings

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
{
2-
"client" : {
3-
"enabled": true,
4-
"languages": [
5-
{
6-
"languageId": "eslint",
7-
"scopes": ["source.js", "text.html.vue"],
8-
"syntaxes": [
9-
"Packages/Vue Syntax Highlight/Vue Component.sublime-syntax",
10-
"Packages/JavaScript/JavaScript.sublime-syntax",
11-
"Packages/User/JS Custom/Syntaxes/React.sublime-syntax",
12-
"Packages/JavaScript/JavaScript.sublime-syntax",
13-
"Packages/Babel/JavaScript (Babel).sublime-syntax"
14-
]
15-
}
16-
],
17-
"initializationOptions": {},
18-
"settings": {
19-
"validate": true,
20-
"packageManager": "npm",
21-
"autoFix": true,
22-
"autoFixOnSave": true,
23-
"options": {},
24-
"run": "onType",
25-
"nodePath": null,
26-
"quiet": false,
27-
"workspaceFolder": null,
28-
"codeAction": {
29-
"disableRuleComment": {
30-
"enable": true,
31-
"location": "separateLine"
32-
},
33-
"showDocumentation": {
34-
"enable": true
35-
}
36-
}
37-
}
38-
}
2+
"languages": [
3+
{
4+
"languageId": "eslint",
5+
"scopes": ["source.js", "text.html.vue"],
6+
"syntaxes": [
7+
"Packages/Babel/JavaScript (Babel).sublime-syntax",
8+
"Packages/JavaScript/JavaScript.sublime-syntax",
9+
"Packages/JavaScript/JavaScript.sublime-syntax",
10+
"Packages/User/JS Custom/Syntaxes/React.sublime-syntax",
11+
"Packages/Vue Syntax Highlight/Vue Component.sublime-syntax",
12+
],
13+
},
14+
],
15+
"initializationOptions": {},
16+
"settings": {
17+
"validate": true,
18+
"packageManager": "npm",
19+
"autoFix": true,
20+
"autoFixOnSave": true,
21+
"options": {},
22+
"run": "onType",
23+
"nodePath": null,
24+
"quiet": false,
25+
"workspaceFolder": null,
26+
"codeAction": {
27+
"disableRuleComment": {
28+
"enable": true,
29+
"location": "separateLine"
30+
},
31+
"showDocumentation": {
32+
"enable": true
33+
},
34+
},
35+
},
3936
}

Main.sublime-menu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"command": "edit_settings",
2121
"args": {
2222
"base_file": "${packages}/LSP-eslint/LSP-eslint.sublime-settings",
23-
"default": "{\n\t$0\n}\n"
23+
"default": "// Settings in here override those in \"LSP-eslint/LSP-eslint.sublime-settings\"\n\n{\n\t$0\n}\n",
2424
}
2525
}
2626
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ ESLint configuration options. Those are currently not documented but [documentat
3131

3232
Q: How to enable linting of Typescript code?
3333

34-
A: Add `"source.ts"` entry to `scopes` option and `"Packages/TypeScript Syntax/TypeScript.tmLanguage"` entry to `syntaxes` option. It's also necessary to have appropriate ESLint configuration in your project. See https://github.com/typescript-eslint/typescript-eslint for more information.
34+
A: Add `"source.ts"` entry to `scopes` option and `"Packages/TypeScript Syntax/TypeScript.tmLanguage"` entry to `syntaxes` option. It's also necessary to have appropriate ESLint configuration in your project. See https://github.com/typescript-eslint/typescript-eslint for more information.

plugin.py

Lines changed: 12 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,29 @@
11
import os
2-
import shutil
3-
import sublime
42
import webbrowser
53

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
185

196

207
def plugin_loaded():
21-
server.setup()
8+
LspEslintPlugin.setup()
229

2310

2411
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()
8613

87-
default_configuration.update(client_configuration)
88-
return read_client_config(self.name, default_configuration)
8914

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')
9519

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)
10123

10224
def handle_status(self, params) -> None:
10325
pass
10426

105-
def handle_open_doc(self, client, params, request_id) -> None:
27+
def handle_open_doc(self, params, respond) -> None:
10628
webbrowser.open(params['url'])
107-
client.send_response(Response(request_id, {}))
29+
respond({})

vscode-eslint/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
out

vscode-eslint/.eslintrc.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
# @see https://github.com/microsoft/vscode-eslint
3+
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
REPO_DIR="${SCRIPT_DIR}"
6+
SRC_DIR="${REPO_DIR}/src"
7+
SRC_SERVER_DIR="${SRC_DIR}/server"
8+
DIST_DIR="${REPO_DIR}/out"
9+
10+
11+
# ------------------------- #
12+
# download the source codes #
13+
# ------------------------- #
14+
15+
pushd "${REPO_DIR}" || exit
16+
17+
rm -rf \
18+
"${SRC_DIR}" "${DIST_DIR}" \
19+
"package.json" "package-lock.json"
20+
21+
echo 'Enter commit SHA or tag (for example 2.1.0) to build'
22+
read -rp 'SHA or tag: ' ref
23+
24+
curl -L "https://github.com/microsoft/vscode-eslint/archive/${ref}.tar.gz" | tar -xzv
25+
mv vscode-eslint-* "${SRC_DIR}"
26+
27+
popd || exit
28+
29+
# ------------ #
30+
# prepare deps #
31+
# ------------ #
32+
33+
pushd "${SRC_SERVER_DIR}" || exit
34+
35+
npm install
36+
npm install -D typescript @types/node
37+
38+
# ------- #
39+
# compile #
40+
# ------- #
41+
42+
npx tsc --newLine LF -p .
43+
44+
popd || exit
45+
46+
# -------------------- #
47+
# collect output files #
48+
# -------------------- #
49+
50+
pushd "${REPO_DIR}" || exit
51+
52+
mv "${SRC_SERVER_DIR}/out" "${DIST_DIR}"
53+
cp "${SRC_SERVER_DIR}/package.json" .
54+
cp "${SRC_SERVER_DIR}/package-lock.json" .
55+
56+
popd || exit

0 commit comments

Comments
 (0)