@rsvelte/language-server 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -1
- package/dist/server.mjs +81 -9
- package/dist/vendor/rsvelte_lint.cjs +33 -4
- package/dist/vendor/rsvelte_lint_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,8 @@ toolchain.
|
|
|
18
18
|
- **Diagnostics** — push diagnostics from the bundled
|
|
19
19
|
[`rsvelte_lint`](https://github.com/baseballyama/rsvelte/tree/main/crates/rsvelte_lint)
|
|
20
20
|
engine (compiled to wasm, vendored in the package — no extra install). Runs on
|
|
21
|
-
open, on change (300 ms debounced), and on save.
|
|
21
|
+
open, on change (300 ms debounced), and on save. The rule set comes from the
|
|
22
|
+
project's own [`rsvelte-lint.json`](#lint-configuration).
|
|
22
23
|
|
|
23
24
|
That's the full v1 surface — hover, completion, go-to-definition, rename,
|
|
24
25
|
find-references, and TypeScript diagnostics are **not** implemented. Those
|
|
@@ -37,6 +38,38 @@ The server reads these from the client's `rsvelte.*` configuration:
|
|
|
37
38
|
| `rsvelte.lint.enable` | `true` | Enable linting via the bundled engine. |
|
|
38
39
|
| `rsvelte.rsvelteFmtPath` | `""` | Explicit path to a `rsvelte-fmt` binary (overrides resolution). |
|
|
39
40
|
|
|
41
|
+
## Lint configuration
|
|
42
|
+
|
|
43
|
+
Severities and rule options come from a `rsvelte-lint.json` (or
|
|
44
|
+
`.rsvelte-lintrc.json`), discovered by walking up from the document's directory
|
|
45
|
+
— the same file, in the same order, that the
|
|
46
|
+
[`rsvelte-lint`](https://www.npmjs.com/package/@rsvelte/lint) CLI resolves, so
|
|
47
|
+
the editor reports what CI does. With no config file, every rule runs at its
|
|
48
|
+
default severity (the `recommended` preset); to start from nothing and opt in,
|
|
49
|
+
use `"extends": ["none"]`:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"extends": ["recommended"],
|
|
54
|
+
"rules": {
|
|
55
|
+
"svelte/no-at-html-tags": "error",
|
|
56
|
+
"svelte/no-unused-class-name": "off",
|
|
57
|
+
"svelte/button-has-type": ["warn", { "submit": true, "reset": false }]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
See the
|
|
63
|
+
[CLI's configuration reference](https://www.npmjs.com/package/@rsvelte/lint#configuration)
|
|
64
|
+
for the full shape. An ESLint config is deliberately **not** read: importing it
|
|
65
|
+
is opt-in on the CLI (`--config-from-eslint`), and a server that read it on its
|
|
66
|
+
own would report a different rule set than the same project's CI. A config that
|
|
67
|
+
can't be read or parsed is reported to the client's log and the recommended
|
|
68
|
+
preset is used, so a typo never leaves the editor without diagnostics.
|
|
69
|
+
|
|
70
|
+
Resolved configs are cached for the life of the server; they are dropped when a
|
|
71
|
+
config file is saved through the client, and on `workspace/didChangeConfiguration`.
|
|
72
|
+
|
|
40
73
|
## Usage
|
|
41
74
|
|
|
42
75
|
```sh
|
package/dist/server.mjs
CHANGED
|
@@ -10114,7 +10114,7 @@ function getWellformedEdit(textEdit) {
|
|
|
10114
10114
|
|
|
10115
10115
|
// src/server.ts
|
|
10116
10116
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
10117
|
-
import { dirname as
|
|
10117
|
+
import { dirname as dirname4 } from "node:path";
|
|
10118
10118
|
|
|
10119
10119
|
// src/diagnostics.ts
|
|
10120
10120
|
var import_node = __toESM(require_main3(), 1);
|
|
@@ -10233,11 +10233,11 @@ function load() {
|
|
|
10233
10233
|
return null;
|
|
10234
10234
|
}
|
|
10235
10235
|
}
|
|
10236
|
-
function runLint(source, filename) {
|
|
10236
|
+
function runLint(source, filename, config) {
|
|
10237
10237
|
const m = load();
|
|
10238
10238
|
if (!m) return null;
|
|
10239
10239
|
try {
|
|
10240
|
-
return m.
|
|
10240
|
+
return m.lint_with_config(source, filename, config);
|
|
10241
10241
|
} catch {
|
|
10242
10242
|
return null;
|
|
10243
10243
|
}
|
|
@@ -10252,6 +10252,62 @@ function lintVersion() {
|
|
|
10252
10252
|
}
|
|
10253
10253
|
}
|
|
10254
10254
|
|
|
10255
|
+
// src/lintConfig.ts
|
|
10256
|
+
import { basename, dirname as dirname3, join as join3 } from "node:path";
|
|
10257
|
+
import { readFileSync } from "node:fs";
|
|
10258
|
+
var CONFIG_NAMES = ["rsvelte-lint.json", ".rsvelte-lintrc.json"];
|
|
10259
|
+
var NO_CONFIG = { text: "", path: null };
|
|
10260
|
+
var cache = /* @__PURE__ */ new Map();
|
|
10261
|
+
function isLintConfigPath(path) {
|
|
10262
|
+
return CONFIG_NAMES.includes(basename(path));
|
|
10263
|
+
}
|
|
10264
|
+
function clearLintConfigCache() {
|
|
10265
|
+
cache.clear();
|
|
10266
|
+
}
|
|
10267
|
+
function resolveLintConfig(dir, onError) {
|
|
10268
|
+
const cached = cache.get(dir);
|
|
10269
|
+
if (cached) return cached;
|
|
10270
|
+
const found = discover(dir);
|
|
10271
|
+
cache.set(dir, found.config);
|
|
10272
|
+
if (found.error) onError?.(`${found.config.path}: ${found.error}`);
|
|
10273
|
+
return found.config;
|
|
10274
|
+
}
|
|
10275
|
+
function discover(start) {
|
|
10276
|
+
let dir = start;
|
|
10277
|
+
for (; ; ) {
|
|
10278
|
+
for (const name of CONFIG_NAMES) {
|
|
10279
|
+
const found = read(join3(dir, name));
|
|
10280
|
+
if (found) return found;
|
|
10281
|
+
}
|
|
10282
|
+
const parent = dirname3(dir);
|
|
10283
|
+
if (parent === dir) return { config: NO_CONFIG, error: null };
|
|
10284
|
+
dir = parent;
|
|
10285
|
+
}
|
|
10286
|
+
}
|
|
10287
|
+
function read(path) {
|
|
10288
|
+
let text;
|
|
10289
|
+
try {
|
|
10290
|
+
text = readFileSync(path, "utf8");
|
|
10291
|
+
} catch (err) {
|
|
10292
|
+
const code = err.code;
|
|
10293
|
+
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
10294
|
+
return { config: { text: "", path }, error: String(err) };
|
|
10295
|
+
}
|
|
10296
|
+
let parsed;
|
|
10297
|
+
try {
|
|
10298
|
+
parsed = JSON.parse(text);
|
|
10299
|
+
} catch (err) {
|
|
10300
|
+
return { config: { text: "", path }, error: String(err) };
|
|
10301
|
+
}
|
|
10302
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
10303
|
+
return {
|
|
10304
|
+
config: { text: "", path },
|
|
10305
|
+
error: "lint config must be a JSON object"
|
|
10306
|
+
};
|
|
10307
|
+
}
|
|
10308
|
+
return { config: { text, path }, error: null };
|
|
10309
|
+
}
|
|
10310
|
+
|
|
10255
10311
|
// src/server.ts
|
|
10256
10312
|
var DEFAULT_SETTINGS = {
|
|
10257
10313
|
format: { enable: true },
|
|
@@ -10313,9 +10369,8 @@ async function refreshSettings() {
|
|
|
10313
10369
|
}
|
|
10314
10370
|
connection.onDidChangeConfiguration(async () => {
|
|
10315
10371
|
await refreshSettings();
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
}
|
|
10372
|
+
clearLintConfigCache();
|
|
10373
|
+
relintOpenDocuments();
|
|
10319
10374
|
});
|
|
10320
10375
|
connection.onDocumentFormatting(async (params) => {
|
|
10321
10376
|
if (!settings.format.enable) return [];
|
|
@@ -10323,7 +10378,7 @@ connection.onDocumentFormatting(async (params) => {
|
|
|
10323
10378
|
if (!doc) return [];
|
|
10324
10379
|
const fsPath = docFsPath(doc.uri);
|
|
10325
10380
|
const binPath = resolveRsvelteFmt(
|
|
10326
|
-
|
|
10381
|
+
dirname4(fsPath),
|
|
10327
10382
|
settings.rsvelteFmtPath
|
|
10328
10383
|
);
|
|
10329
10384
|
if (!binPath) return [];
|
|
@@ -10350,13 +10405,30 @@ async function lintDocument(doc) {
|
|
|
10350
10405
|
connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
|
|
10351
10406
|
return;
|
|
10352
10407
|
}
|
|
10353
|
-
const
|
|
10408
|
+
const fsPath = docFsPath(doc.uri);
|
|
10409
|
+
const config = resolveLintConfig(
|
|
10410
|
+
dirname4(fsPath),
|
|
10411
|
+
(message) => connection.console.warn(message)
|
|
10412
|
+
);
|
|
10413
|
+
const json = runLint(doc.getText(), fsPath, config.text);
|
|
10354
10414
|
const diagnostics = json ? lintJsonToDiagnostics(json) : [];
|
|
10355
10415
|
connection.sendDiagnostics({ uri: doc.uri, diagnostics });
|
|
10356
10416
|
}
|
|
10417
|
+
function relintOpenDocuments() {
|
|
10418
|
+
for (const doc of documents.all()) {
|
|
10419
|
+
scheduleLint(doc, 0);
|
|
10420
|
+
}
|
|
10421
|
+
}
|
|
10357
10422
|
documents.onDidOpen((e) => scheduleLint(e.document, 0));
|
|
10358
10423
|
documents.onDidChangeContent((e) => scheduleLint(e.document));
|
|
10359
|
-
documents.onDidSave((e) =>
|
|
10424
|
+
documents.onDidSave((e) => {
|
|
10425
|
+
if (isLintConfigPath(docFsPath(e.document.uri))) {
|
|
10426
|
+
clearLintConfigCache();
|
|
10427
|
+
relintOpenDocuments();
|
|
10428
|
+
return;
|
|
10429
|
+
}
|
|
10430
|
+
scheduleLint(e.document, 0);
|
|
10431
|
+
});
|
|
10360
10432
|
documents.onDidClose((e) => {
|
|
10361
10433
|
const timer = debounceTimers.get(e.document.uri);
|
|
10362
10434
|
if (timer) {
|
|
@@ -269,6 +269,35 @@ function lint_version() {
|
|
|
269
269
|
}
|
|
270
270
|
exports.lint_version = lint_version;
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* [`lint`] under the text of a `rsvelte-lint.json`. Wasm has no filesystem, so
|
|
274
|
+
* the host (the language server) discovers the config file and passes its
|
|
275
|
+
* contents in; `""` selects the recommended preset.
|
|
276
|
+
* @param {string} source
|
|
277
|
+
* @param {string} filename
|
|
278
|
+
* @param {string} config
|
|
279
|
+
* @returns {string}
|
|
280
|
+
*/
|
|
281
|
+
function lint_with_config(source, filename, config) {
|
|
282
|
+
let deferred4_0;
|
|
283
|
+
let deferred4_1;
|
|
284
|
+
try {
|
|
285
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
286
|
+
const len0 = WASM_VECTOR_LEN;
|
|
287
|
+
const ptr1 = passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
288
|
+
const len1 = WASM_VECTOR_LEN;
|
|
289
|
+
const ptr2 = passStringToWasm0(config, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
290
|
+
const len2 = WASM_VECTOR_LEN;
|
|
291
|
+
const ret = wasm.lint_with_config(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
292
|
+
deferred4_0 = ret[0];
|
|
293
|
+
deferred4_1 = ret[1];
|
|
294
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
295
|
+
} finally {
|
|
296
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
exports.lint_with_config = lint_with_config;
|
|
300
|
+
|
|
272
301
|
/**
|
|
273
302
|
* Parse a Svelte component and return the AST as JSON.
|
|
274
303
|
* @param {string} source
|
|
@@ -403,8 +432,8 @@ function __wbg_get_imports() {
|
|
|
403
432
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
404
433
|
},
|
|
405
434
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
406
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [String], shim_idx:
|
|
407
|
-
const ret = makeClosure(arg0, arg1,
|
|
435
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [String], shim_idx: 5, ret: String, inner_ret: Some(String) }, mutable: false }) -> Externref`.
|
|
436
|
+
const ret = makeClosure(arg0, arg1, wasm_bindgen_de7100a3341595c3___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_);
|
|
408
437
|
return ret;
|
|
409
438
|
},
|
|
410
439
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
@@ -428,13 +457,13 @@ function __wbg_get_imports() {
|
|
|
428
457
|
};
|
|
429
458
|
}
|
|
430
459
|
|
|
431
|
-
function
|
|
460
|
+
function wasm_bindgen_de7100a3341595c3___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_(arg0, arg1, arg2) {
|
|
432
461
|
let deferred2_0;
|
|
433
462
|
let deferred2_1;
|
|
434
463
|
try {
|
|
435
464
|
const ptr0 = passStringToWasm0(arg2, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
436
465
|
const len0 = WASM_VECTOR_LEN;
|
|
437
|
-
const ret = wasm.
|
|
466
|
+
const ret = wasm.wasm_bindgen_de7100a3341595c3___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_(arg0, arg1, ptr0, len0);
|
|
438
467
|
deferred2_0 = ret[0];
|
|
439
468
|
deferred2_1 = ret[1];
|
|
440
469
|
return getStringFromWasm0(ret[0], ret[1]);
|
|
Binary file
|
package/package.json
CHANGED