Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ensure-wrapper-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jsoniq-language-server": minor
---

Add `--ensure-wrapper` to the server, which downloads the RumbleDB wrapper JAR unless it is cached, prints the command that starts it, and exits. Run it to download the JAR ahead of time, for example when building an image: `node dist/bundled/main.mjs --ensure-wrapper`. It replaces the `dist/integrations/rumble/executable/ensure-wrapper.mjs` script.
6 changes: 6 additions & 0 deletions packages/language-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Type-checking diagnostics, inferred types and running queries come from RumbleDB

The wrapper JAR is too large to ship in the npm package. The server downloads it from GitHub Releases when it is first needed, checks its SHA-256 against the bundled manifest, and caches it. Set `JSONIQ_LSP_CACHE_DIR` to control where it is stored. To use another wrapper JAR, such as one you built yourself, set `JSONIQ_LSP_WRAPPER_JAR` to its path.

To download the JAR ahead of time, for example when building an image, run the server with `--ensure-wrapper`. It downloads the JAR unless it is cached, prints the command that starts it, and exits:

```sh
node node_modules/jsoniq-language-server/dist/bundled/main.mjs --ensure-wrapper
```

If you don't want any of this, set `wrapper.enabled` to `false` (see below) and the server runs on the parser alone.

## Configuration
Expand Down
1 change: 0 additions & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"start": "node ./dist/main.mjs",
"test": "vitest run tests",
"clean": "rm -rf dist",
"ensure-wrapper": "node ./dist/integrations/rumble/executable/ensure-wrapper.mjs",
"lint": "oxlint",
"lint:fix": "oxlint --fix",
"fmt": "oxfmt",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ export async function resolveWrapperLaunchConfig(
};
}

/**
* `main.mjs --ensure-wrapper`: downloads the wrapper JAR unless it is cached, and prints the command that starts it.
* Exits with code 1 when the JAR cannot be resolved.
*/
export async function ensureWrapper(): Promise<void> {
try {
const { args } = await resolveWrapperLaunchConfig();
console.log(["java", ...args].join(" "));
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
}

async function resolveLaunchConfig(
options: WrapperResolutionOptions,
): Promise<WrapperLaunchConfig> {
Expand Down
7 changes: 6 additions & 1 deletion packages/language-server/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { startServer } from "./app/server.js";
import { ensureWrapper } from "./integrations/rumble/executable/index.js";
export type { ClientConfiguration } from "./app/server.js";
export type { LakehouseFormats } from "./app/configuration.js";

startServer();
if (process.argv.includes("--ensure-wrapper")) {
await ensureWrapper();
} else {
startServer();
}
35 changes: 35 additions & 0 deletions packages/language-server/tests/wrapper/ensure-wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { fileURLToPath } from "node:url";

import { ensureWrapper } from "server/integrations/rumble/executable/index.js";
import { afterEach, describe, expect, it, vi } from "vitest";

describe("ensure wrapper", () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.restoreAllMocks();
process.exitCode = undefined;
});

it("prints the command that starts the wrapper", async () => {
const jarPath = fileURLToPath(import.meta.url);
vi.stubEnv("JSONIQ_LSP_WRAPPER_JAR", jarPath);
const log = vi.spyOn(console, "log").mockImplementation(() => {});

await ensureWrapper();

const command: string = log.mock.calls[0]?.[0];
expect(command).toMatch(/^java /);
expect(command).toContain(`-jar ${jarPath} --daemon`);
expect(process.exitCode).toBeUndefined();
});

it("exits with code 1 when the wrapper cannot be resolved", async () => {
vi.stubEnv("JSONIQ_LSP_WRAPPER_JAR", "/missing/wrapper.jar");
const error = vi.spyOn(console, "error").mockImplementation(() => {});

await ensureWrapper();

expect(error).toHaveBeenCalledWith(expect.stringContaining("/missing/wrapper.jar"));
expect(process.exitCode).toBe(1);
});
});
1 change: 0 additions & 1 deletion packages/language-server/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default defineConfig([
"src/main.ts",
"src/lsp/protocol/notifications/index.ts",
"src/lsp/protocol/requests/index.ts",
"src/integrations/rumble/executable/ensure-wrapper.ts",
],
root: "src",
outDir: "dist",
Expand Down
Loading