@rsvelte/language-server 0.3.0 → 0.4.1

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 CHANGED
@@ -81,6 +81,18 @@ Most users won't run this directly — the
81
81
  bundles and launches it. For other editors, point your LSP client at the
82
82
  `rsvelte-language-server` binary with the `--stdio` transport.
83
83
 
84
+ ## Native server
85
+
86
+ `rsvelte-language-server` is a launcher. It prefers the prebuilt native (Rust)
87
+ server shipped in the optional `@rsvelte/language-server-<platform>` packages
88
+ and falls back to the bundled JS server when no platform package is installed
89
+ (unsupported platform, or an install that skipped optional dependencies).
90
+
91
+ | Environment variable | Effect |
92
+ | --- | --- |
93
+ | `RSVELTE_LANGUAGE_SERVER_BIN` | Run this binary instead of the resolved one. |
94
+ | `RSVELTE_LANGUAGE_SERVER_JS=1` | Force the bundled JS server. |
95
+
84
96
  ## License
85
97
 
86
98
  MIT
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ // Launcher for `rsvelte-language-server`.
3
+ //
4
+ // It prefers the native Rust server shipped in the optional
5
+ // `@rsvelte/language-server-<triple>` packages and falls back to the bundled
6
+ // JS server (`dist/server.mjs`) when no platform package is installed — so an
7
+ // unsupported platform, or an install that skipped optional dependencies,
8
+ // keeps the capabilities it has today instead of failing outright.
9
+ //
10
+ // Like the @rsvelte/fmt and @rsvelte/lint launchers, this file is never
11
+ // rewritten in place: pnpm bakes a shim interpreter from this file's shebang at
12
+ // link time, so swapping it for a native binary post-install would make that
13
+ // shim feed Mach-O/ELF bytes to Node.
14
+
15
+ import { spawnSync } from 'node:child_process';
16
+ import { constants as osConstants } from 'node:os';
17
+ import { existsSync } from 'node:fs';
18
+ import { dirname, join } from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+ import {
21
+ ensureExecutable,
22
+ platformPackage,
23
+ resolvePlatformBinary,
24
+ } from '../lib/resolve.mjs';
25
+
26
+ const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)));
27
+ const argv = process.argv.slice(2);
28
+
29
+ // Escape hatches for editors and debugging: point at a locally built server, or
30
+ // force the JS implementation when the native one misbehaves.
31
+ const override = process.env.RSVELTE_LANGUAGE_SERVER_BIN;
32
+ const forceJs = process.env.RSVELTE_LANGUAGE_SERVER_JS === '1';
33
+
34
+ let command;
35
+ let args;
36
+ if (override) {
37
+ command = override;
38
+ args = argv;
39
+ } else {
40
+ const native = forceJs ? null : resolvePlatformBinary();
41
+ if (native) {
42
+ ensureExecutable(native);
43
+ command = native;
44
+ args = argv;
45
+ } else {
46
+ const jsServer = join(pkgRoot, 'dist', 'server.mjs');
47
+ if (!existsSync(jsServer)) {
48
+ const { triple, pkgName } = platformPackage();
49
+ const why = forceJs
50
+ ? 'RSVELTE_LANGUAGE_SERVER_JS=1 forced it.'
51
+ : triple
52
+ ? `the native package "${pkgName}" isn't installed.\nTry reinstalling: npm install --include=optional ${pkgName}`
53
+ : `platform ${process.platform}-${process.arch} has no prebuilt binary.`;
54
+ console.error(
55
+ `[@rsvelte/language-server] No server to run: the JS fallback (${jsServer}) is missing and ${why}`,
56
+ );
57
+ process.exit(1);
58
+ }
59
+ command = process.execPath;
60
+ args = [jsServer, ...argv];
61
+ }
62
+ }
63
+
64
+ const result = spawnSync(command, args, { stdio: 'inherit', windowsHide: true });
65
+
66
+ if (result.error) {
67
+ console.error(
68
+ `[@rsvelte/language-server] Failed to exec ${command}: ${result.error.message}`,
69
+ );
70
+ process.exit(1);
71
+ }
72
+
73
+ // A signal termination leaves `status` null; returning `status ?? 0` would mask
74
+ // the crash as a clean exit.
75
+ if (result.signal) {
76
+ const signum = osConstants.signals[result.signal];
77
+ console.error(`[@rsvelte/language-server] ${command} was terminated by ${result.signal}.`);
78
+ process.exit(typeof signum === 'number' ? 128 + signum : 1);
79
+ }
80
+ process.exit(result.status ?? 0);
package/dist/server.mjs CHANGED
File without changes
Binary file
@@ -0,0 +1,74 @@
1
+ // Resolution helpers for the @rsvelte/language-server launcher: they find the
2
+ // platform-native `rsvelte-language-server` binary shipped in the optional
3
+ // `@rsvelte/language-server-<triple>` packages.
4
+ //
5
+ // ESM (not `.cjs` like the @rsvelte/fmt / @rsvelte/lint siblings) because this
6
+ // package is `"type": "module"`; the resolution logic itself is identical.
7
+
8
+ import { chmodSync, constants, statSync } from 'node:fs';
9
+ import { createRequire } from 'node:module';
10
+
11
+ const require = createRequire(import.meta.url);
12
+
13
+ /// Map the current platform/arch to a `@rsvelte/language-server-<triple>`
14
+ /// suffix, or `null` when unsupported. Mirrors the release build matrix.
15
+ export function resolveTriple() {
16
+ const { platform, arch } = process;
17
+ if (platform === 'darwin') {
18
+ if (arch === 'arm64') return 'darwin-arm64';
19
+ if (arch === 'x64') return 'darwin-x64';
20
+ } else if (platform === 'linux') {
21
+ // Node 18+ exposes the runtime glibc version; an empty value means musl.
22
+ let isMusl = false;
23
+ try {
24
+ const header = process.report.getReport().header;
25
+ isMusl = !header.glibcVersionRuntime;
26
+ } catch {
27
+ isMusl = false;
28
+ }
29
+ const libc = isMusl ? 'musl' : 'gnu';
30
+ if (arch === 'x64') return `linux-x64-${libc}`;
31
+ if (arch === 'arm64') return `linux-arm64-${libc}`;
32
+ } else if (platform === 'win32') {
33
+ if (arch === 'x64') return 'win32-x64-msvc';
34
+ }
35
+ return null;
36
+ }
37
+
38
+ /// The platform package name + binary basename for the current platform.
39
+ /// `triple` is `null` when the platform is unsupported.
40
+ export function platformPackage() {
41
+ const triple = resolveTriple();
42
+ if (!triple) return { triple: null, pkgName: null, binName: null };
43
+ const pkgName = `@rsvelte/language-server-${triple}`;
44
+ const binName =
45
+ process.platform === 'win32'
46
+ ? 'rsvelte-language-server.exe'
47
+ : 'rsvelte-language-server';
48
+ return { triple, pkgName, binName };
49
+ }
50
+
51
+ /// Resolve the absolute path to the prebuilt native server for this platform,
52
+ /// or `null` when the optional platform package isn't installed.
53
+ export function resolvePlatformBinary() {
54
+ const { pkgName, binName } = platformPackage();
55
+ if (!pkgName) return null;
56
+ try {
57
+ return require.resolve(`${pkgName}/${binName}`);
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+
63
+ /// Best-effort `chmod +x` on a POSIX file. No-op on Windows / read-only FS.
64
+ export function ensureExecutable(binPath) {
65
+ if (process.platform === 'win32') return;
66
+ try {
67
+ const mode = statSync(binPath).mode;
68
+ if (!(mode & constants.S_IXUSR)) {
69
+ chmodSync(binPath, (mode & 0o777) | 0o111);
70
+ }
71
+ } catch {
72
+ // Not fatal — a later spawn surfaces a clear error if it really can't run.
73
+ }
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsvelte/language-server",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Language Server for rsvelte — formatting (native rsvelte-fmt) and linting (bundled rsvelte_lint wasm)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,13 +22,22 @@
22
22
  ],
23
23
  "type": "module",
24
24
  "bin": {
25
- "rsvelte-language-server": "dist/server.mjs"
25
+ "rsvelte-language-server": "bin/rsvelte-language-server.mjs"
26
26
  },
27
27
  "files": [
28
+ "bin/rsvelte-language-server.mjs",
29
+ "lib/resolve.mjs",
28
30
  "dist/server.mjs",
29
31
  "dist/vendor/rsvelte_lint.cjs",
30
32
  "dist/vendor/rsvelte_lint_bg.wasm"
31
33
  ],
34
+ "optionalDependencies": {
35
+ "@rsvelte/language-server-darwin-arm64": "^0.4.1",
36
+ "@rsvelte/language-server-darwin-x64": "^0.4.1",
37
+ "@rsvelte/language-server-linux-arm64-gnu": "^0.4.1",
38
+ "@rsvelte/language-server-linux-x64-gnu": "^0.4.1",
39
+ "@rsvelte/language-server-win32-x64-msvc": "^0.4.1"
40
+ },
32
41
  "dependencies": {
33
42
  "vscode-languageserver": "^10.0.0",
34
43
  "vscode-languageserver-textdocument": "^1.0.12"