@zubra/language-server 5.0.2 → 5.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.
Files changed (3) hide show
  1. package/backend.js +26 -9
  2. package/package.json +1 -1
  3. package/server.js +2 -1
package/backend.js CHANGED
@@ -1,16 +1,33 @@
1
1
  // How the language server reaches the compiler: the WebAssembly build (@zubra/compiler) when it's
2
- // installed, otherwise the `zubra` CLI (or the one in `compiler`). Both give the same diagnostics.
2
+ // installed in the workspace (or beside the server), otherwise the `zubra` CLI (or the one in `compiler`). Both give the same diagnostics.
3
3
  import { spawnSync } from 'node:child_process';
4
- import { readFileSync } from 'node:fs';
5
- import { dirname, resolve } from 'node:path';
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { dirname, join, resolve } from 'node:path';
6
+ import { pathToFileURL } from 'node:url';
6
7
 
7
- export async function createBackend({ compiler } = {}) {
8
+ /**
9
+ * Where @zubra/compiler is installed for a workspace: the nearest node_modules above `root` that has it.
10
+ * The server can't rely on its own location for this: in the VS Code extension it sits inside the
11
+ * extension's folder, and the compiler is in the project being edited.
12
+ */
13
+ export function compilerEntries(root) {
14
+ const found = [];
15
+ for (let dir = root && resolve(root); dir; dir = dirname(dir) === dir ? null : dirname(dir)) {
16
+ const entry = join(dir, 'node_modules/@zubra/compiler/index.js');
17
+ if (existsSync(entry)) found.push(entry);
18
+ }
19
+ return found;
20
+ }
21
+
22
+ export async function createBackend({ compiler, root } = {}) {
8
23
  if (!compiler) {
9
- try {
10
- const wasm = await import('@zubra/compiler');
11
- if (wasm.available()) return wasmBackend(wasm);
12
- } catch {
13
- // Not installed.
24
+ for (const specifier of [...compilerEntries(root).map((entry) => pathToFileURL(entry).href), '@zubra/compiler']) {
25
+ try {
26
+ const wasm = await import(specifier);
27
+ if (wasm.available()) return wasmBackend(wasm);
28
+ } catch {
29
+ // Not installed there, or its WebAssembly isn't built.
30
+ }
14
31
  }
15
32
  }
16
33
  const chosen = compiler ?? process.env.ZUBRA_COMPILER;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubra/language-server",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
4
4
  "description": "Language server for .zb components: diagnostics, completion, hover and go to definition",
5
5
  "license": "ISC",
6
6
  "repository": {
package/server.js CHANGED
@@ -19,7 +19,8 @@ let backend;
19
19
  const manifests = new Map(); // path → { mtime, component }
20
20
 
21
21
  connection.onInitialize(async (params) => {
22
- backend = await createBackend(params.initializationOptions ?? {});
22
+ const folder = params.workspaceFolders?.[0]?.uri ?? params.rootUri;
23
+ backend = await createBackend({ ...params.initializationOptions, root: folder ? fileURLToPath(folder) : undefined });
23
24
  return {
24
25
  capabilities: {
25
26
  textDocumentSync: TextDocumentSyncKind.Incremental,