summaryrefslogtreecommitdiffhomepage
path: root/packages/lsp/src/config.test.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-11 21:12:03 +0900
committerAdam Malczewski <[email protected]>2026-06-11 21:12:03 +0900
commite7eada4802ceebd86c83bcd6e3eca70152e7f331 (patch)
tree447095fd60b43980358d1565506f3ae2430e5f29 /packages/lsp/src/config.test.ts
parent35937cee7f838e414eb8147c67205e01d85a4da0 (diff)
downloaddispatch-e7eada4802ceebd86c83bcd6e3eca70152e7f331.tar.gz
dispatch-e7eada4802ceebd86c83bcd6e3eca70152e7f331.zip
feat(lsp,cwd): LSP integration + per-conversation cwd; fix cache-warming cache bust
LSP + per-conversation CWD feature: - new bundled `lsp` extension: hand-rolled JSON-RPC codec (framing/rpc), lazy one-server-per-(serverID,root), per-cwd config resolution, on-demand `lsp` tool - `conversation-store`: getCwd/setCwd (cwdKey); `session-orchestrator` defaults a turn's cwd from the store - `transport-http`: cwd + lsp status endpoints; wire types in transport-contract - host-bin: register lsp; config wiring Cache-warming fix (the warm read 0% on the first reheat after a message): - warm assembled tools under a different cwd than the real turn (a reheat sends no cwd, and the warm service had no store fallback). The skills filter rewrites the cwd-sensitive `load_skill` description, so the tools block — the first bytes of the prompt-cache prefix — diverged and the cache missed entirely. Warm now resolves cwd as opts.cwd ?? conversationStore.getCwd(), mirroring handleMessage. - capture warm sends as `provider.request` spans flagged `warm:true` (thread a child logger into providerOpts) so warm vs real bodies are diffable (obs §3.1). - kernel logger: span-close now merges child-bound attrs like span-open, so a `warm:true` query finds the closed span (with usage/status), not just the open. Tests: warm forwards a warm-flagged logger; warm falls back to stored cwd; logger open/close attr consistency. Full suite green (873).
Diffstat (limited to 'packages/lsp/src/config.test.ts')
-rw-r--r--packages/lsp/src/config.test.ts119
1 files changed, 119 insertions, 0 deletions
diff --git a/packages/lsp/src/config.test.ts b/packages/lsp/src/config.test.ts
new file mode 100644
index 0000000..1462490
--- /dev/null
+++ b/packages/lsp/src/config.test.ts
@@ -0,0 +1,119 @@
+import { describe, expect, it } from "vitest";
+import { resolveServers } from "./config.js";
+
+describe("config", () => {
+ it("built-in typescript resolves when tsconfig.json exists", async () => {
+ const servers = await resolveServers({
+ cwd: "/project",
+ dispatchLspJson: null,
+ opencodeJson: null,
+ exists: async (path) => path === "/project/tsconfig.json",
+ });
+
+ const ts = servers.find((s) => s.id === "typescript");
+ expect(ts).toBeDefined();
+ expect(ts?.command).toEqual(["typescript-language-server", "--stdio"]);
+ expect(ts?.extensions).toContain(".ts");
+ expect(ts?.rootMarkers).toContain("tsconfig.json");
+ });
+
+ it(".dispatch/lsp.json servers resolve", async () => {
+ const config = JSON.stringify({
+ servers: {
+ mylsp: {
+ command: ["my-lsp", "--stdio"],
+ extensions: [".ml"],
+ rootMarkers: ["Makefile"],
+ },
+ },
+ });
+
+ const servers = await resolveServers({
+ cwd: "/project",
+ dispatchLspJson: config,
+ opencodeJson: null,
+ exists: async () => false,
+ });
+
+ expect(servers).toHaveLength(1);
+ expect(servers[0]?.id).toBe("mylsp");
+ expect(servers[0]?.command).toEqual(["my-lsp", "--stdio"]);
+ });
+
+ it("opencode.json lsp is used only as fallback", async () => {
+ const opencodeConfig = JSON.stringify({
+ lsp: {
+ fallback: {
+ command: ["fallback-lsp"],
+ extensions: [".fb"],
+ },
+ },
+ });
+
+ const servers = await resolveServers({
+ cwd: "/project",
+ dispatchLspJson: null,
+ opencodeJson: opencodeConfig,
+ exists: async () => false,
+ });
+
+ expect(servers).toHaveLength(1);
+ expect(servers[0]?.id).toBe("fallback");
+ });
+
+ it(".dispatch/lsp.json wins over opencode.json", async () => {
+ const dispatchConfig = JSON.stringify({
+ servers: { primary: { command: ["primary-lsp"], extensions: [".p"] } },
+ });
+ const opencodeConfig = JSON.stringify({
+ lsp: { fallback: { command: ["fallback-lsp"], extensions: [".f"] } },
+ });
+
+ const servers = await resolveServers({
+ cwd: "/project",
+ dispatchLspJson: dispatchConfig,
+ opencodeJson: opencodeConfig,
+ exists: async () => false,
+ });
+
+ expect(servers).toHaveLength(1);
+ expect(servers[0]?.id).toBe("primary");
+ });
+
+ it("luau-lsp sourcemap.autogenerate yields a rojo --watch sidecar", async () => {
+ const config = JSON.stringify({
+ servers: {
+ luau: {
+ command: ["luau-lsp", "lsp"],
+ extensions: [".luau"],
+ initialization: {
+ "luau-lsp": {
+ sourcemap: {
+ autogenerate: true,
+ rojoProjectFile: "default.project.json",
+ },
+ },
+ },
+ },
+ },
+ });
+
+ const servers = await resolveServers({
+ cwd: "/project",
+ dispatchLspJson: config,
+ opencodeJson: null,
+ exists: async () => false,
+ });
+
+ expect(servers).toHaveLength(1);
+ expect(servers[0]?.sidecar).toBeDefined();
+ expect(servers[0]?.sidecar?.command).toEqual([
+ "rojo",
+ "sourcemap",
+ "default.project.json",
+ "--watch",
+ "-o",
+ "sourcemap.json",
+ ]);
+ });
+});