@rsvelte/language-server 0.1.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.
@@ -0,0 +1,409 @@
1
+ /* @ts-self-types="./rsvelte_lint.d.ts" */
2
+
3
+ /**
4
+ * Result of compiling a Svelte component.
5
+ */
6
+ class CompileResultWasm {
7
+ static __wrap(ptr) {
8
+ const obj = Object.create(CompileResultWasm.prototype);
9
+ obj.__wbg_ptr = ptr;
10
+ CompileResultWasmFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ return obj;
12
+ }
13
+ __destroy_into_raw() {
14
+ const ptr = this.__wbg_ptr;
15
+ this.__wbg_ptr = 0;
16
+ CompileResultWasmFinalization.unregister(this);
17
+ return ptr;
18
+ }
19
+ free() {
20
+ const ptr = this.__destroy_into_raw();
21
+ wasm.__wbg_compileresultwasm_free(ptr, 0);
22
+ }
23
+ /**
24
+ * @returns {string}
25
+ */
26
+ get css() {
27
+ let deferred1_0;
28
+ let deferred1_1;
29
+ try {
30
+ const ret = wasm.compileresultwasm_css(this.__wbg_ptr);
31
+ deferred1_0 = ret[0];
32
+ deferred1_1 = ret[1];
33
+ return getStringFromWasm0(ret[0], ret[1]);
34
+ } finally {
35
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
36
+ }
37
+ }
38
+ /**
39
+ * @returns {string | undefined}
40
+ */
41
+ get error() {
42
+ const ret = wasm.compileresultwasm_error(this.__wbg_ptr);
43
+ let v1;
44
+ if (ret[0] !== 0) {
45
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
46
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
47
+ }
48
+ return v1;
49
+ }
50
+ /**
51
+ * @returns {string}
52
+ */
53
+ get js() {
54
+ let deferred1_0;
55
+ let deferred1_1;
56
+ try {
57
+ const ret = wasm.compileresultwasm_js(this.__wbg_ptr);
58
+ deferred1_0 = ret[0];
59
+ deferred1_1 = ret[1];
60
+ return getStringFromWasm0(ret[0], ret[1]);
61
+ } finally {
62
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
63
+ }
64
+ }
65
+ /**
66
+ * @returns {boolean}
67
+ */
68
+ get success() {
69
+ const ret = wasm.compileresultwasm_success(this.__wbg_ptr);
70
+ return ret !== 0;
71
+ }
72
+ }
73
+ if (Symbol.dispose) CompileResultWasm.prototype[Symbol.dispose] = CompileResultWasm.prototype.free;
74
+ exports.CompileResultWasm = CompileResultWasm;
75
+
76
+ /**
77
+ * Result of parsing a Svelte component.
78
+ */
79
+ class ParseResultWasm {
80
+ static __wrap(ptr) {
81
+ const obj = Object.create(ParseResultWasm.prototype);
82
+ obj.__wbg_ptr = ptr;
83
+ ParseResultWasmFinalization.register(obj, obj.__wbg_ptr, obj);
84
+ return obj;
85
+ }
86
+ __destroy_into_raw() {
87
+ const ptr = this.__wbg_ptr;
88
+ this.__wbg_ptr = 0;
89
+ ParseResultWasmFinalization.unregister(this);
90
+ return ptr;
91
+ }
92
+ free() {
93
+ const ptr = this.__destroy_into_raw();
94
+ wasm.__wbg_parseresultwasm_free(ptr, 0);
95
+ }
96
+ /**
97
+ * @returns {string}
98
+ */
99
+ get ast() {
100
+ let deferred1_0;
101
+ let deferred1_1;
102
+ try {
103
+ const ret = wasm.parseresultwasm_ast(this.__wbg_ptr);
104
+ deferred1_0 = ret[0];
105
+ deferred1_1 = ret[1];
106
+ return getStringFromWasm0(ret[0], ret[1]);
107
+ } finally {
108
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
109
+ }
110
+ }
111
+ /**
112
+ * @returns {string | undefined}
113
+ */
114
+ get error() {
115
+ const ret = wasm.parseresultwasm_error(this.__wbg_ptr);
116
+ let v1;
117
+ if (ret[0] !== 0) {
118
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
119
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
120
+ }
121
+ return v1;
122
+ }
123
+ /**
124
+ * @returns {boolean}
125
+ */
126
+ get success() {
127
+ const ret = wasm.parseresultwasm_success(this.__wbg_ptr);
128
+ return ret !== 0;
129
+ }
130
+ }
131
+ if (Symbol.dispose) ParseResultWasm.prototype[Symbol.dispose] = ParseResultWasm.prototype.free;
132
+ exports.ParseResultWasm = ParseResultWasm;
133
+
134
+ /**
135
+ * Compile a Svelte component to client-side JavaScript.
136
+ * @param {string} source
137
+ * @param {string} name
138
+ * @returns {CompileResultWasm}
139
+ */
140
+ function compile_client(source, name) {
141
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
142
+ const len0 = WASM_VECTOR_LEN;
143
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
144
+ const len1 = WASM_VECTOR_LEN;
145
+ const ret = wasm.compile_client(ptr0, len0, ptr1, len1);
146
+ return CompileResultWasm.__wrap(ret);
147
+ }
148
+ exports.compile_client = compile_client;
149
+
150
+ /**
151
+ * Compile a Svelte component to server-side JavaScript.
152
+ * @param {string} source
153
+ * @param {string} name
154
+ * @returns {CompileResultWasm}
155
+ */
156
+ function compile_server(source, name) {
157
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
158
+ const len0 = WASM_VECTOR_LEN;
159
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
160
+ const len1 = WASM_VECTOR_LEN;
161
+ const ret = wasm.compile_server(ptr0, len0, ptr1, len1);
162
+ return CompileResultWasm.__wrap(ret);
163
+ }
164
+ exports.compile_server = compile_server;
165
+
166
+ /**
167
+ * Initialize panic hook for better error messages in the browser console.
168
+ */
169
+ function init() {
170
+ wasm.init();
171
+ }
172
+ exports.init = init;
173
+
174
+ /**
175
+ * Lint `source`, returning a JSON array of diagnostics:
176
+ * `[{ "severity", "line", "column", "endLine", "endColumn", "code", "message" }]`.
177
+ * Lines are 1-indexed, columns 0-indexed (UTF-16), matching `rsvelte check`.
178
+ * @param {string} source
179
+ * @param {string} filename
180
+ * @returns {string}
181
+ */
182
+ function lint(source, filename) {
183
+ let deferred3_0;
184
+ let deferred3_1;
185
+ try {
186
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
187
+ const len0 = WASM_VECTOR_LEN;
188
+ const ptr1 = passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
189
+ const len1 = WASM_VECTOR_LEN;
190
+ const ret = wasm.lint(ptr0, len0, ptr1, len1);
191
+ deferred3_0 = ret[0];
192
+ deferred3_1 = ret[1];
193
+ return getStringFromWasm0(ret[0], ret[1]);
194
+ } finally {
195
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
196
+ }
197
+ }
198
+ exports.lint = lint;
199
+
200
+ /**
201
+ * The rsvelte-lint crate version (for the playground UI).
202
+ * @returns {string}
203
+ */
204
+ function lint_version() {
205
+ let deferred1_0;
206
+ let deferred1_1;
207
+ try {
208
+ const ret = wasm.lint_version();
209
+ deferred1_0 = ret[0];
210
+ deferred1_1 = ret[1];
211
+ return getStringFromWasm0(ret[0], ret[1]);
212
+ } finally {
213
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
214
+ }
215
+ }
216
+ exports.lint_version = lint_version;
217
+
218
+ /**
219
+ * Parse a Svelte component and return the AST as JSON.
220
+ * @param {string} source
221
+ * @returns {ParseResultWasm}
222
+ */
223
+ function parse_svelte(source) {
224
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
225
+ const len0 = WASM_VECTOR_LEN;
226
+ const ret = wasm.parse_svelte(ptr0, len0);
227
+ return ParseResultWasm.__wrap(ret);
228
+ }
229
+ exports.parse_svelte = parse_svelte;
230
+
231
+ /**
232
+ * Convert a Svelte component to TypeScript/TSX. Mirrors the napi `svelte2tsx`
233
+ * shape — `options_json` and the return value are JSON strings so the wasm
234
+ * boundary stays at primitive types and no bespoke `wasm_bindgen` struct is
235
+ * needed for every field of `Svelte2TsxResult`.
236
+ * @param {string} source
237
+ * @param {string} options_json
238
+ * @returns {string}
239
+ */
240
+ function svelte2tsx(source, options_json) {
241
+ let deferred3_0;
242
+ let deferred3_1;
243
+ try {
244
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
245
+ const len0 = WASM_VECTOR_LEN;
246
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
247
+ const len1 = WASM_VECTOR_LEN;
248
+ const ret = wasm.svelte2tsx(ptr0, len0, ptr1, len1);
249
+ deferred3_0 = ret[0];
250
+ deferred3_1 = ret[1];
251
+ return getStringFromWasm0(ret[0], ret[1]);
252
+ } finally {
253
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
254
+ }
255
+ }
256
+ exports.svelte2tsx = svelte2tsx;
257
+
258
+ /**
259
+ * Get the version of the compiler.
260
+ * @returns {string}
261
+ */
262
+ function version() {
263
+ let deferred1_0;
264
+ let deferred1_1;
265
+ try {
266
+ const ret = wasm.version();
267
+ deferred1_0 = ret[0];
268
+ deferred1_1 = ret[1];
269
+ return getStringFromWasm0(ret[0], ret[1]);
270
+ } finally {
271
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
272
+ }
273
+ }
274
+ exports.version = version;
275
+ function __wbg_get_imports() {
276
+ const import0 = {
277
+ __proto__: null,
278
+ __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
279
+ throw new Error(getStringFromWasm0(arg0, arg1));
280
+ },
281
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
282
+ let deferred0_0;
283
+ let deferred0_1;
284
+ try {
285
+ deferred0_0 = arg0;
286
+ deferred0_1 = arg1;
287
+ console.error(getStringFromWasm0(arg0, arg1));
288
+ } finally {
289
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
290
+ }
291
+ },
292
+ __wbg_new_227d7c05414eb861: function() {
293
+ const ret = new Error();
294
+ return ret;
295
+ },
296
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
297
+ const ret = arg1.stack;
298
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
299
+ const len1 = WASM_VECTOR_LEN;
300
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
301
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
302
+ },
303
+ __wbindgen_init_externref_table: function() {
304
+ const table = wasm.__wbindgen_externrefs;
305
+ const offset = table.grow(4);
306
+ table.set(0, undefined);
307
+ table.set(offset + 0, undefined);
308
+ table.set(offset + 1, null);
309
+ table.set(offset + 2, true);
310
+ table.set(offset + 3, false);
311
+ },
312
+ };
313
+ return {
314
+ __proto__: null,
315
+ "./rsvelte_lint_bg.js": import0,
316
+ };
317
+ }
318
+
319
+ const CompileResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
320
+ ? { register: () => {}, unregister: () => {} }
321
+ : new FinalizationRegistry(ptr => wasm.__wbg_compileresultwasm_free(ptr, 1));
322
+ const ParseResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
323
+ ? { register: () => {}, unregister: () => {} }
324
+ : new FinalizationRegistry(ptr => wasm.__wbg_parseresultwasm_free(ptr, 1));
325
+
326
+ let cachedDataViewMemory0 = null;
327
+ function getDataViewMemory0() {
328
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
329
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
330
+ }
331
+ return cachedDataViewMemory0;
332
+ }
333
+
334
+ function getStringFromWasm0(ptr, len) {
335
+ return decodeText(ptr >>> 0, len);
336
+ }
337
+
338
+ let cachedUint8ArrayMemory0 = null;
339
+ function getUint8ArrayMemory0() {
340
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
341
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
342
+ }
343
+ return cachedUint8ArrayMemory0;
344
+ }
345
+
346
+ function passStringToWasm0(arg, malloc, realloc) {
347
+ if (realloc === undefined) {
348
+ const buf = cachedTextEncoder.encode(arg);
349
+ const ptr = malloc(buf.length, 1) >>> 0;
350
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
351
+ WASM_VECTOR_LEN = buf.length;
352
+ return ptr;
353
+ }
354
+
355
+ let len = arg.length;
356
+ let ptr = malloc(len, 1) >>> 0;
357
+
358
+ const mem = getUint8ArrayMemory0();
359
+
360
+ let offset = 0;
361
+
362
+ for (; offset < len; offset++) {
363
+ const code = arg.charCodeAt(offset);
364
+ if (code > 0x7F) break;
365
+ mem[ptr + offset] = code;
366
+ }
367
+ if (offset !== len) {
368
+ if (offset !== 0) {
369
+ arg = arg.slice(offset);
370
+ }
371
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
372
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
373
+ const ret = cachedTextEncoder.encodeInto(arg, view);
374
+
375
+ offset += ret.written;
376
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
377
+ }
378
+
379
+ WASM_VECTOR_LEN = offset;
380
+ return ptr;
381
+ }
382
+
383
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
384
+ cachedTextDecoder.decode();
385
+ function decodeText(ptr, len) {
386
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
387
+ }
388
+
389
+ const cachedTextEncoder = new TextEncoder();
390
+
391
+ if (!('encodeInto' in cachedTextEncoder)) {
392
+ cachedTextEncoder.encodeInto = function (arg, view) {
393
+ const buf = cachedTextEncoder.encode(arg);
394
+ view.set(buf);
395
+ return {
396
+ read: arg.length,
397
+ written: buf.length
398
+ };
399
+ };
400
+ }
401
+
402
+ let WASM_VECTOR_LEN = 0;
403
+
404
+ const wasmPath = `${__dirname}/rsvelte_lint_bg.wasm`;
405
+ const wasmBytes = require('fs').readFileSync(wasmPath);
406
+ const wasmModule = new WebAssembly.Module(wasmBytes);
407
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
408
+ let wasm = wasmInstance.exports;
409
+ wasm.__wbindgen_start();
Binary file
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@rsvelte/language-server",
3
+ "version": "0.1.0",
4
+ "description": "Language Server for rsvelte — formatting (native rsvelte-fmt) and linting (bundled rsvelte_lint wasm)",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/baseballyama/rsvelte.git",
9
+ "directory": "apps/npm/language-server"
10
+ },
11
+ "homepage": "https://github.com/baseballyama/rsvelte/tree/main/apps/npm/language-server#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/baseballyama/rsvelte/issues"
14
+ },
15
+ "keywords": [
16
+ "svelte",
17
+ "language-server",
18
+ "lsp",
19
+ "formatter",
20
+ "linter",
21
+ "rust"
22
+ ],
23
+ "type": "module",
24
+ "bin": {
25
+ "rsvelte-language-server": "dist/server.mjs"
26
+ },
27
+ "files": [
28
+ "dist/server.mjs",
29
+ "dist/vendor/rsvelte_lint.cjs",
30
+ "dist/vendor/rsvelte_lint_bg.wasm"
31
+ ],
32
+ "scripts": {
33
+ "build": "node build.mjs",
34
+ "typecheck": "tsc --noEmit",
35
+ "test": "node --test \"test/*.test.mjs\"",
36
+ "prepublishOnly": "node -e \"for (const f of ['dist/server.mjs','dist/vendor/rsvelte_lint.cjs','dist/vendor/rsvelte_lint_bg.wasm']) if (!require('fs').existsSync(f)) { console.error('missing '+f+' — run build:language-server first'); process.exit(1) }\""
37
+ },
38
+ "dependencies": {
39
+ "vscode-languageserver": "^9.0.1",
40
+ "vscode-languageserver-textdocument": "^1.0.12"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.10.0",
44
+ "esbuild": "^0.28.0",
45
+ "typescript": "^5.7.0"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }