pi-lens 3.6.2 → 3.6.4
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/CHANGELOG.md +10 -2
- package/package.json +4 -4
- package/tsconfig.json +1 -1
- package/clients/__tests__/file-time.test.js +0 -216
- package/clients/__tests__/file-time.test.ts +0 -276
- package/clients/__tests__/format-service.test.js +0 -245
- package/clients/__tests__/format-service.test.ts +0 -339
- package/clients/__tests__/formatters.test.js +0 -271
- package/clients/__tests__/formatters.test.ts +0 -401
- package/clients/agent-behavior-client.js +0 -110
- package/clients/agent-behavior-client.test.js +0 -94
- package/clients/agent-behavior-client.test.ts +0 -116
- package/clients/amain-types.js +0 -164
- package/clients/architect-client.js +0 -291
- package/clients/ast-grep-client.js +0 -253
- package/clients/ast-grep-parser.js +0 -84
- package/clients/ast-grep-rule-manager.js +0 -89
- package/clients/ast-grep-types.js +0 -9
- package/clients/auto-loop.js +0 -131
- package/clients/biome-client.js +0 -420
- package/clients/biome-client.test.js +0 -144
- package/clients/biome-client.test.ts +0 -163
- package/clients/cache/rule-cache.js +0 -72
- package/clients/cache-manager.js +0 -245
- package/clients/cache-manager.test.js +0 -197
- package/clients/cache-manager.test.ts +0 -299
- package/clients/complexity-client.js +0 -675
- package/clients/complexity-client.test.js +0 -234
- package/clients/complexity-client.test.ts +0 -255
- package/clients/config-validator.js +0 -465
- package/clients/dependency-checker.js +0 -325
- package/clients/dependency-checker.test.js +0 -60
- package/clients/dependency-checker.test.ts +0 -71
- package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
- package/clients/dispatch/__tests__/autofix-integration.test.ts +0 -300
- package/clients/dispatch/__tests__/runner-registration.test.js +0 -234
- package/clients/dispatch/__tests__/runner-registration.test.ts +0 -286
- package/clients/dispatch/debug.log +0 -1
- package/clients/dispatch/dispatcher.edge.test.js +0 -82
- package/clients/dispatch/dispatcher.edge.test.ts +0 -100
- package/clients/dispatch/dispatcher.format.test.js +0 -46
- package/clients/dispatch/dispatcher.format.test.ts +0 -58
- package/clients/dispatch/dispatcher.inline.test.js +0 -74
- package/clients/dispatch/dispatcher.inline.test.ts +0 -93
- package/clients/dispatch/dispatcher.js +0 -381
- package/clients/dispatch/dispatcher.test.js +0 -116
- package/clients/dispatch/dispatcher.test.ts +0 -149
- package/clients/dispatch/integration.js +0 -108
- package/clients/dispatch/plan.js +0 -183
- package/clients/dispatch/runners/architect.js +0 -83
- package/clients/dispatch/runners/architect.test.js +0 -138
- package/clients/dispatch/runners/architect.test.ts +0 -162
- package/clients/dispatch/runners/ast-grep-napi.js +0 -405
- package/clients/dispatch/runners/ast-grep-napi.test.js +0 -107
- package/clients/dispatch/runners/ast-grep-napi.test.ts +0 -129
- package/clients/dispatch/runners/ast-grep.js +0 -157
- package/clients/dispatch/runners/biome.js +0 -55
- package/clients/dispatch/runners/config-validation.js +0 -67
- package/clients/dispatch/runners/go-vet.js +0 -48
- package/clients/dispatch/runners/index.js +0 -47
- package/clients/dispatch/runners/lsp.js +0 -102
- package/clients/dispatch/runners/oxlint.js +0 -67
- package/clients/dispatch/runners/oxlint.test.js +0 -230
- package/clients/dispatch/runners/oxlint.test.ts +0 -303
- package/clients/dispatch/runners/pyright.js +0 -100
- package/clients/dispatch/runners/pyright.test.js +0 -98
- package/clients/dispatch/runners/pyright.test.ts +0 -121
- package/clients/dispatch/runners/python-slop.js +0 -97
- package/clients/dispatch/runners/python-slop.test.js +0 -203
- package/clients/dispatch/runners/python-slop.test.ts +0 -298
- package/clients/dispatch/runners/ruff.js +0 -48
- package/clients/dispatch/runners/rust-clippy.js +0 -102
- package/clients/dispatch/runners/scan_codebase.test.js +0 -89
- package/clients/dispatch/runners/scan_codebase.test.ts +0 -105
- package/clients/dispatch/runners/shellcheck.js +0 -147
- package/clients/dispatch/runners/shellcheck.test.js +0 -98
- package/clients/dispatch/runners/shellcheck.test.ts +0 -129
- package/clients/dispatch/runners/similarity.js +0 -230
- package/clients/dispatch/runners/spellcheck.js +0 -106
- package/clients/dispatch/runners/spellcheck.test.js +0 -158
- package/clients/dispatch/runners/spellcheck.test.ts +0 -214
- package/clients/dispatch/runners/tree-sitter.js +0 -246
- package/clients/dispatch/runners/ts-lsp.js +0 -125
- package/clients/dispatch/runners/ts-slop.js +0 -113
- package/clients/dispatch/runners/type-safety.js +0 -142
- package/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -134
- package/clients/dispatch/runners/utils/runner-helpers.js +0 -115
- package/clients/dispatch/runners/utils.js +0 -51
- package/clients/dispatch/runners/yaml-rule-parser.js +0 -360
- package/clients/dispatch/types.js +0 -16
- package/clients/dispatch/utils/format-utils.js +0 -44
- package/clients/dogfood.test.js +0 -201
- package/clients/dogfood.test.ts +0 -269
- package/clients/file-kinds.js +0 -177
- package/clients/file-kinds.test.js +0 -169
- package/clients/file-kinds.test.ts +0 -210
- package/clients/file-time.js +0 -152
- package/clients/file-utils.js +0 -40
- package/clients/fix-scanners.js +0 -204
- package/clients/format-service.js +0 -184
- package/clients/formatters.js +0 -488
- package/clients/go-client.js +0 -203
- package/clients/go-client.test.js +0 -127
- package/clients/go-client.test.ts +0 -143
- package/clients/installer/index.js +0 -403
- package/clients/interviewer-templates.js +0 -75
- package/clients/interviewer.js +0 -173
- package/clients/jscpd-client.js +0 -196
- package/clients/jscpd-client.test.js +0 -127
- package/clients/jscpd-client.test.ts +0 -145
- package/clients/knip-client.js +0 -239
- package/clients/knip-client.test.js +0 -112
- package/clients/knip-client.test.ts +0 -128
- package/clients/latency-logger.js +0 -40
- package/clients/lsp/__tests__/client.test.js +0 -310
- package/clients/lsp/__tests__/client.test.ts +0 -412
- package/clients/lsp/__tests__/config.test.js +0 -167
- package/clients/lsp/__tests__/config.test.ts +0 -217
- package/clients/lsp/__tests__/error-recovery.test.js +0 -213
- package/clients/lsp/__tests__/error-recovery.test.ts +0 -279
- package/clients/lsp/__tests__/integration.test.js +0 -127
- package/clients/lsp/__tests__/integration.test.ts +0 -160
- package/clients/lsp/__tests__/launch.test.js +0 -313
- package/clients/lsp/__tests__/launch.test.ts +0 -394
- package/clients/lsp/__tests__/server.test.js +0 -259
- package/clients/lsp/__tests__/server.test.ts +0 -332
- package/clients/lsp/__tests__/service.test.js +0 -438
- package/clients/lsp/__tests__/service.test.ts +0 -530
- package/clients/lsp/client.js +0 -350
- package/clients/lsp/config.js +0 -112
- package/clients/lsp/index.js +0 -318
- package/clients/lsp/installer/index.js +0 -391
- package/clients/lsp/interactive-install.js +0 -221
- package/clients/lsp/language.js +0 -170
- package/clients/lsp/launch.js +0 -329
- package/clients/lsp/lsp/launch.js +0 -116
- package/clients/lsp/lsp/server.js +0 -532
- package/clients/lsp/lsp-index.js +0 -10
- package/clients/lsp/path-utils.js +0 -5
- package/clients/lsp/server.js +0 -725
- package/clients/lsp/test-py-spawn/requirements.txt +0 -1
- package/clients/lsp/test-py-spawn/test.py +0 -3
- package/clients/lsp/test-py-svc/requirements.txt +0 -1
- package/clients/lsp/test-py-svc/test.py +0 -3
- package/clients/lsp/test-python-project/requirements.txt +0 -1
- package/clients/lsp/test-python-project/test.py +0 -5
- package/clients/metrics-client.js +0 -107
- package/clients/metrics-client.test.js +0 -128
- package/clients/metrics-client.test.ts +0 -163
- package/clients/metrics-history.js +0 -367
- package/clients/path-utils.js +0 -142
- package/clients/pipeline.js +0 -272
- package/clients/production-readiness.js +0 -522
- package/clients/project-index.js +0 -255
- package/clients/project-metadata.js +0 -531
- package/clients/ruff-client.js +0 -325
- package/clients/ruff-client.test.js +0 -132
- package/clients/ruff-client.test.ts +0 -153
- package/clients/rules-scanner.js +0 -97
- package/clients/runner-tracker.js +0 -152
- package/clients/rust-client.js +0 -205
- package/clients/rust-client.test.js +0 -108
- package/clients/rust-client.test.ts +0 -130
- package/clients/safe-spawn-async.js +0 -163
- package/clients/safe-spawn.js +0 -241
- package/clients/sanitize.js +0 -291
- package/clients/sanitize.test.js +0 -177
- package/clients/sanitize.test.ts +0 -223
- package/clients/scan-architectural-debt.js +0 -167
- package/clients/scan-utils.js +0 -83
- package/clients/secrets-scanner.js +0 -119
- package/clients/secrets-scanner.test.js +0 -100
- package/clients/secrets-scanner.test.ts +0 -113
- package/clients/sg-runner.js +0 -292
- package/clients/state-matrix.js +0 -160
- package/clients/subprocess-client.js +0 -65
- package/clients/symbol-types.js +0 -5
- package/clients/test-runner-client.js +0 -523
- package/clients/test-runner-client.test.js +0 -192
- package/clients/test-runner-client.test.ts +0 -253
- package/clients/test-utils.js +0 -27
- package/clients/test-utils.ts +0 -36
- package/clients/todo-scanner.js +0 -200
- package/clients/todo-scanner.test.js +0 -301
- package/clients/todo-scanner.test.ts +0 -352
- package/clients/tool-availability.js +0 -207
- package/clients/tree-sitter-client.js +0 -601
- package/clients/tree-sitter-query-loader.js +0 -355
- package/clients/tree-sitter-symbol-extractor.js +0 -289
- package/clients/ts-service.js +0 -129
- package/clients/type-coverage-client.js +0 -127
- package/clients/type-coverage-client.test.js +0 -105
- package/clients/type-coverage-client.test.ts +0 -125
- package/clients/type-safety-client.js +0 -138
- package/clients/types.js +0 -11
- package/clients/typescript-client.codefix.test.js +0 -157
- package/clients/typescript-client.codefix.test.ts +0 -186
- package/clients/typescript-client.js +0 -509
- package/clients/typescript-client.test.js +0 -105
- package/clients/typescript-client.test.ts +0 -126
- package/commands/booboo.js +0 -1007
- package/commands/fix-from-booboo.js +0 -398
- package/commands/fix-simplified.js +0 -618
- package/commands/rate.js +0 -281
- package/commands/rate.test.js +0 -119
- package/commands/rate.test.ts +0 -131
- package/commands/refactor.js +0 -130
|
@@ -1,530 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LSP Service Test Suite
|
|
3
|
-
*
|
|
4
|
-
* Tests for the LSP Service layer including:
|
|
5
|
-
* - Client lifecycle management
|
|
6
|
-
* - Effect-TS integration
|
|
7
|
-
* - File operations (open/update/getDiagnostics)
|
|
8
|
-
* - Server availability checking
|
|
9
|
-
* - Cleanup and shutdown
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { Effect } from "effect";
|
|
13
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
14
|
-
import type { LSPClientInfo } from "../client.js";
|
|
15
|
-
import {
|
|
16
|
-
getLSPService,
|
|
17
|
-
LSPService,
|
|
18
|
-
lspEffect,
|
|
19
|
-
resetLSPService,
|
|
20
|
-
} from "../index.js";
|
|
21
|
-
import type { LSPServerInfo } from "../server.js";
|
|
22
|
-
|
|
23
|
-
// Mock the dependencies
|
|
24
|
-
vi.mock("../server.js", async () => {
|
|
25
|
-
const actual =
|
|
26
|
-
await vi.importActual<typeof import("../server.js")>("../server.js");
|
|
27
|
-
return {
|
|
28
|
-
...actual,
|
|
29
|
-
getServersForFileWithConfig: vi.fn(),
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
vi.mock("../config.js", () => ({
|
|
34
|
-
initLSPConfig: vi.fn(),
|
|
35
|
-
getServersForFileWithConfig: vi.fn(),
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
vi.mock("../language.js", () => ({
|
|
39
|
-
getLanguageId: vi.fn(() => "typescript"),
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
vi.mock("../launch.js", () => ({
|
|
43
|
-
launchLSP: vi.fn(),
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
vi.mock("../client.js", () => ({
|
|
47
|
-
createLSPClient: vi.fn(),
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
import { createLSPClient as mockCreateLSPClient } from "../client.js";
|
|
51
|
-
import { getServersForFileWithConfig as mockGetServersForFile } from "../config.js";
|
|
52
|
-
|
|
53
|
-
describe("LSPService", () => {
|
|
54
|
-
let service: LSPService;
|
|
55
|
-
|
|
56
|
-
beforeEach(() => {
|
|
57
|
-
resetLSPService();
|
|
58
|
-
service = getLSPService();
|
|
59
|
-
vi.clearAllMocks();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
afterEach(async () => {
|
|
63
|
-
await service.shutdown();
|
|
64
|
-
resetLSPService();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe("constructor", () => {
|
|
68
|
-
it("should initialize with empty state", () => {
|
|
69
|
-
const status = service.getStatus();
|
|
70
|
-
expect(status).toEqual([]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should create fresh LSPState", () => {
|
|
74
|
-
// Verify service was created with initial state
|
|
75
|
-
expect(service).toBeDefined();
|
|
76
|
-
expect(service).toBeInstanceOf(LSPService);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("hasLSP", () => {
|
|
81
|
-
it("should return false when no servers match file extension", async () => {
|
|
82
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([]);
|
|
83
|
-
|
|
84
|
-
const result = await service.hasLSP("/test/file.unknown");
|
|
85
|
-
expect(result).toBe(false);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should return true when server matches and provides root", async () => {
|
|
89
|
-
const mockServer: LSPServerInfo = {
|
|
90
|
-
id: "typescript",
|
|
91
|
-
name: "TypeScript Server",
|
|
92
|
-
extensions: [".ts"],
|
|
93
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
94
|
-
spawn: vi.fn(),
|
|
95
|
-
};
|
|
96
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
97
|
-
|
|
98
|
-
const result = await service.hasLSP("/project/test.ts");
|
|
99
|
-
expect(result).toBe(true);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("should return false when server cannot determine root", async () => {
|
|
103
|
-
const mockServer: LSPServerInfo = {
|
|
104
|
-
id: "typescript",
|
|
105
|
-
name: "TypeScript Server",
|
|
106
|
-
extensions: [".ts"],
|
|
107
|
-
root: vi.fn().mockResolvedValue(undefined),
|
|
108
|
-
spawn: vi.fn(),
|
|
109
|
-
};
|
|
110
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
111
|
-
|
|
112
|
-
const result = await service.hasLSP("/project/test.ts");
|
|
113
|
-
expect(result).toBe(false);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should check all matching servers until root is found", async () => {
|
|
117
|
-
const server1: LSPServerInfo = {
|
|
118
|
-
id: "server1",
|
|
119
|
-
name: "Server 1",
|
|
120
|
-
extensions: [".ts"],
|
|
121
|
-
root: vi.fn().mockResolvedValue(undefined),
|
|
122
|
-
spawn: vi.fn(),
|
|
123
|
-
};
|
|
124
|
-
const server2: LSPServerInfo = {
|
|
125
|
-
id: "server2",
|
|
126
|
-
name: "Server 2",
|
|
127
|
-
extensions: [".ts"],
|
|
128
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
129
|
-
spawn: vi.fn(),
|
|
130
|
-
};
|
|
131
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([server1, server2]);
|
|
132
|
-
|
|
133
|
-
const result = await service.hasLSP("/project/test.ts");
|
|
134
|
-
expect(result).toBe(true);
|
|
135
|
-
expect(server1.root).toHaveBeenCalled();
|
|
136
|
-
expect(server2.root).toHaveBeenCalled();
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe("getClientForFile", () => {
|
|
141
|
-
it("should return undefined when no servers match", async () => {
|
|
142
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([]);
|
|
143
|
-
|
|
144
|
-
const result = await service.getClientForFile("/test/file.unknown");
|
|
145
|
-
expect(result).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("should cache and reuse existing client", async () => {
|
|
149
|
-
const mockClient = createMockClient();
|
|
150
|
-
const mockServer: LSPServerInfo = {
|
|
151
|
-
id: "typescript",
|
|
152
|
-
name: "TypeScript Server",
|
|
153
|
-
extensions: [".ts"],
|
|
154
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
155
|
-
spawn: vi.fn().mockResolvedValue({
|
|
156
|
-
process: { pid: 123 } as any,
|
|
157
|
-
}),
|
|
158
|
-
};
|
|
159
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
160
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
161
|
-
|
|
162
|
-
// First call creates client
|
|
163
|
-
const result1 = await service.getClientForFile("/project/test.ts");
|
|
164
|
-
expect(result1).toBeDefined();
|
|
165
|
-
expect(mockCreateLSPClient).toHaveBeenCalledTimes(1);
|
|
166
|
-
|
|
167
|
-
// Second call returns cached client
|
|
168
|
-
const result2 = await service.getClientForFile("/project/other.ts");
|
|
169
|
-
expect(result2?.client).toBe(result1?.client);
|
|
170
|
-
expect(mockCreateLSPClient).toHaveBeenCalledTimes(1); // Not called again
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("should handle server spawn failure", async () => {
|
|
174
|
-
const mockSpawn = vi.fn().mockRejectedValue(new Error("Spawn failed"));
|
|
175
|
-
const mockServer: LSPServerInfo = {
|
|
176
|
-
id: "typescript",
|
|
177
|
-
name: "TypeScript Server",
|
|
178
|
-
extensions: [".ts"],
|
|
179
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
180
|
-
spawn: mockSpawn as any,
|
|
181
|
-
};
|
|
182
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
183
|
-
|
|
184
|
-
const result = await service.getClientForFile("/project/test.ts");
|
|
185
|
-
expect(result).toBeUndefined();
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("should try next server when first fails", async () => {
|
|
189
|
-
const mockClient = createMockClient();
|
|
190
|
-
const failingServer: LSPServerInfo = {
|
|
191
|
-
id: "server1",
|
|
192
|
-
name: "Failing Server",
|
|
193
|
-
extensions: [".ts"],
|
|
194
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
195
|
-
spawn: vi.fn().mockRejectedValue(new Error("Spawn failed")) as any,
|
|
196
|
-
};
|
|
197
|
-
const workingServer: LSPServerInfo = {
|
|
198
|
-
id: "server2",
|
|
199
|
-
name: "Working Server",
|
|
200
|
-
extensions: [".ts"],
|
|
201
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
202
|
-
spawn: vi.fn().mockResolvedValue({
|
|
203
|
-
process: { pid: 456 } as any,
|
|
204
|
-
}),
|
|
205
|
-
};
|
|
206
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([
|
|
207
|
-
failingServer,
|
|
208
|
-
workingServer,
|
|
209
|
-
]);
|
|
210
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
211
|
-
|
|
212
|
-
const result = await service.getClientForFile("/project/test.ts");
|
|
213
|
-
expect(result).toBeDefined();
|
|
214
|
-
expect(result?.info.id).toBe("server2");
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
describe("openFile", () => {
|
|
219
|
-
it("should send didOpen notification with correct parameters", async () => {
|
|
220
|
-
const mockClient = createMockClient();
|
|
221
|
-
const mockServer: LSPServerInfo = {
|
|
222
|
-
id: "typescript",
|
|
223
|
-
name: "TypeScript Server",
|
|
224
|
-
extensions: [".ts"],
|
|
225
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
226
|
-
spawn: vi.fn().mockResolvedValue({
|
|
227
|
-
process: { pid: 123 } as any,
|
|
228
|
-
}),
|
|
229
|
-
};
|
|
230
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
231
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
232
|
-
|
|
233
|
-
await service.openFile("/project/test.ts", "const x = 1;");
|
|
234
|
-
|
|
235
|
-
expect(mockClient.notify.open).toHaveBeenCalledWith(
|
|
236
|
-
"/project/test.ts",
|
|
237
|
-
"const x = 1;",
|
|
238
|
-
"typescript",
|
|
239
|
-
);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it("should do nothing when no LSP available", async () => {
|
|
243
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([]);
|
|
244
|
-
|
|
245
|
-
// Should not throw
|
|
246
|
-
await expect(
|
|
247
|
-
service.openFile("/test.unknown", "content"),
|
|
248
|
-
).resolves.not.toThrow();
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
describe("updateFile", () => {
|
|
253
|
-
it("should send didChange notification", async () => {
|
|
254
|
-
const mockClient = createMockClient();
|
|
255
|
-
const mockServer: LSPServerInfo = {
|
|
256
|
-
id: "typescript",
|
|
257
|
-
name: "TypeScript Server",
|
|
258
|
-
extensions: [".ts"],
|
|
259
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
260
|
-
spawn: vi.fn().mockResolvedValue({
|
|
261
|
-
process: { pid: 123 } as any,
|
|
262
|
-
}),
|
|
263
|
-
};
|
|
264
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
265
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
266
|
-
|
|
267
|
-
await service.updateFile("/project/test.ts", "const x = 2;");
|
|
268
|
-
|
|
269
|
-
expect(mockClient.notify.change).toHaveBeenCalledWith(
|
|
270
|
-
"/project/test.ts",
|
|
271
|
-
"const x = 2;",
|
|
272
|
-
);
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
describe("getDiagnostics", () => {
|
|
277
|
-
it("should return diagnostics from client", async () => {
|
|
278
|
-
const mockDiagnostics = [
|
|
279
|
-
{
|
|
280
|
-
severity: 1 as const,
|
|
281
|
-
message: "Type error",
|
|
282
|
-
range: {
|
|
283
|
-
start: { line: 0, character: 0 },
|
|
284
|
-
end: { line: 0, character: 5 },
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
];
|
|
288
|
-
const mockClient = createMockClient(mockDiagnostics);
|
|
289
|
-
const mockServer: LSPServerInfo = {
|
|
290
|
-
id: "typescript",
|
|
291
|
-
name: "TypeScript Server",
|
|
292
|
-
extensions: [".ts"],
|
|
293
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
294
|
-
spawn: vi.fn().mockResolvedValue({
|
|
295
|
-
process: { pid: 123 } as any,
|
|
296
|
-
}),
|
|
297
|
-
};
|
|
298
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
299
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
300
|
-
|
|
301
|
-
const result = await service.getDiagnostics("/project/test.ts");
|
|
302
|
-
|
|
303
|
-
expect(result).toEqual(mockDiagnostics);
|
|
304
|
-
expect(mockClient.waitForDiagnostics).toHaveBeenCalled();
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("should return empty array when no LSP available", async () => {
|
|
308
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([]);
|
|
309
|
-
|
|
310
|
-
const result = await service.getDiagnostics("/test.unknown");
|
|
311
|
-
expect(result).toEqual([]);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
describe("shutdown", () => {
|
|
316
|
-
it("should shutdown all clients", async () => {
|
|
317
|
-
const mockClient1 = createMockClient();
|
|
318
|
-
const mockClient2 = createMockClient();
|
|
319
|
-
|
|
320
|
-
// Add clients to service
|
|
321
|
-
const mockServer1: LSPServerInfo = {
|
|
322
|
-
id: "typescript",
|
|
323
|
-
name: "TypeScript Server",
|
|
324
|
-
extensions: [".ts"],
|
|
325
|
-
root: vi.fn().mockResolvedValue("/project1"),
|
|
326
|
-
spawn: vi.fn().mockResolvedValue({ process: { pid: 1 } as any }),
|
|
327
|
-
};
|
|
328
|
-
const mockServer2: LSPServerInfo = {
|
|
329
|
-
id: "python",
|
|
330
|
-
name: "Python Server",
|
|
331
|
-
extensions: [".py"],
|
|
332
|
-
root: vi.fn().mockResolvedValue("/project2"),
|
|
333
|
-
spawn: vi.fn().mockResolvedValue({ process: { pid: 2 } as any }),
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
vi.mocked(mockGetServersForFile)
|
|
337
|
-
.mockReturnValueOnce([mockServer1])
|
|
338
|
-
.mockReturnValueOnce([mockServer2]);
|
|
339
|
-
|
|
340
|
-
vi.mocked(mockCreateLSPClient)
|
|
341
|
-
.mockResolvedValueOnce(mockClient1)
|
|
342
|
-
.mockResolvedValueOnce(mockClient2);
|
|
343
|
-
|
|
344
|
-
// Create clients
|
|
345
|
-
await service.getClientForFile("/project1/test.ts");
|
|
346
|
-
await service.getClientForFile("/project2/test.py");
|
|
347
|
-
|
|
348
|
-
await service.shutdown();
|
|
349
|
-
|
|
350
|
-
expect(mockClient1.shutdown).toHaveBeenCalled();
|
|
351
|
-
expect(mockClient2.shutdown).toHaveBeenCalled();
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it("should handle shutdown errors gracefully", async () => {
|
|
355
|
-
const mockClient = createMockClient();
|
|
356
|
-
(mockClient.shutdown as any).mockRejectedValue(
|
|
357
|
-
new Error("Shutdown failed"),
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
const mockServer: LSPServerInfo = {
|
|
361
|
-
id: "typescript",
|
|
362
|
-
name: "TypeScript Server",
|
|
363
|
-
extensions: [".ts"],
|
|
364
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
365
|
-
spawn: vi.fn().mockResolvedValue({ process: { pid: 123 } as any }),
|
|
366
|
-
};
|
|
367
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
368
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
369
|
-
|
|
370
|
-
await service.getClientForFile("/project/test.ts");
|
|
371
|
-
|
|
372
|
-
// Should not throw even when client shutdown fails
|
|
373
|
-
await expect(service.shutdown()).resolves.not.toThrow();
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
describe("getStatus", () => {
|
|
378
|
-
it("should return status of all active clients", async () => {
|
|
379
|
-
const mockClient = createMockClient();
|
|
380
|
-
const mockServer: LSPServerInfo = {
|
|
381
|
-
id: "typescript",
|
|
382
|
-
name: "TypeScript Server",
|
|
383
|
-
extensions: [".ts"],
|
|
384
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
385
|
-
spawn: vi.fn().mockResolvedValue({ process: { pid: 123 } as any }),
|
|
386
|
-
};
|
|
387
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
388
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
389
|
-
|
|
390
|
-
await service.getClientForFile("/project/test.ts");
|
|
391
|
-
|
|
392
|
-
const status = service.getStatus();
|
|
393
|
-
expect(status).toHaveLength(1);
|
|
394
|
-
expect(status[0]).toEqual({
|
|
395
|
-
serverId: "typescript",
|
|
396
|
-
root: "/project",
|
|
397
|
-
connected: true,
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
describe("lspEffect", () => {
|
|
404
|
-
let service: LSPService;
|
|
405
|
-
let effect: ReturnType<typeof lspEffect>;
|
|
406
|
-
|
|
407
|
-
beforeEach(() => {
|
|
408
|
-
resetLSPService();
|
|
409
|
-
service = getLSPService();
|
|
410
|
-
effect = lspEffect(service);
|
|
411
|
-
vi.clearAllMocks();
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
afterEach(async () => {
|
|
415
|
-
await service.shutdown();
|
|
416
|
-
resetLSPService();
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
describe("openFile Effect", () => {
|
|
420
|
-
it("should wrap openFile in Effect", async () => {
|
|
421
|
-
const mockClient = createMockClient();
|
|
422
|
-
const mockServer: LSPServerInfo = {
|
|
423
|
-
id: "typescript",
|
|
424
|
-
name: "TypeScript Server",
|
|
425
|
-
extensions: [".ts"],
|
|
426
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
427
|
-
spawn: vi.fn().mockResolvedValue({ process: { pid: 123 } as any }),
|
|
428
|
-
};
|
|
429
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
430
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
431
|
-
|
|
432
|
-
const program = effect.openFile("/project/test.ts", "content");
|
|
433
|
-
const result = await Effect.runPromise(program);
|
|
434
|
-
|
|
435
|
-
expect(result).toBeUndefined();
|
|
436
|
-
expect(mockClient.notify.open).toHaveBeenCalled();
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it("should handle errors in Effect", async () => {
|
|
440
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([]);
|
|
441
|
-
|
|
442
|
-
const program = effect.openFile("/test.unknown", "content");
|
|
443
|
-
// Should complete successfully (no-op for unknown files)
|
|
444
|
-
await expect(Effect.runPromise(program)).resolves.not.toThrow();
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
describe("getDiagnostics Effect", () => {
|
|
449
|
-
it("should wrap getDiagnostics in Effect", async () => {
|
|
450
|
-
const mockDiagnostics = [
|
|
451
|
-
{
|
|
452
|
-
severity: 1,
|
|
453
|
-
message: "Error",
|
|
454
|
-
range: {
|
|
455
|
-
start: { line: 0, character: 0 },
|
|
456
|
-
end: { line: 0, character: 1 },
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
];
|
|
460
|
-
const mockClient = createMockClient(mockDiagnostics);
|
|
461
|
-
const mockServer: LSPServerInfo = {
|
|
462
|
-
id: "typescript",
|
|
463
|
-
name: "TypeScript Server",
|
|
464
|
-
extensions: [".ts"],
|
|
465
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
466
|
-
spawn: vi.fn().mockResolvedValue({ process: { pid: 123 } as any }),
|
|
467
|
-
};
|
|
468
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
469
|
-
vi.mocked(mockCreateLSPClient).mockResolvedValue(mockClient as any);
|
|
470
|
-
|
|
471
|
-
const program = effect.getDiagnostics("/project/test.ts");
|
|
472
|
-
const result = await Effect.runPromise(program);
|
|
473
|
-
|
|
474
|
-
expect(result).toEqual(mockDiagnostics);
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
describe("hasLSP Effect", () => {
|
|
479
|
-
it("should wrap hasLSP in Effect", async () => {
|
|
480
|
-
const mockServer: LSPServerInfo = {
|
|
481
|
-
id: "typescript",
|
|
482
|
-
name: "TypeScript Server",
|
|
483
|
-
extensions: [".ts"],
|
|
484
|
-
root: vi.fn().mockResolvedValue("/project"),
|
|
485
|
-
spawn: vi.fn(),
|
|
486
|
-
};
|
|
487
|
-
vi.mocked(mockGetServersForFile).mockReturnValue([mockServer]);
|
|
488
|
-
|
|
489
|
-
const program = effect.hasLSP("/project/test.ts");
|
|
490
|
-
const result = await Effect.runPromise(program);
|
|
491
|
-
|
|
492
|
-
expect(result).toBe(true);
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
describe("shutdown Effect", () => {
|
|
497
|
-
it("should wrap shutdown in Effect", async () => {
|
|
498
|
-
const program = effect.shutdown();
|
|
499
|
-
const result = await Effect.runPromise(program);
|
|
500
|
-
|
|
501
|
-
expect(result).toBeUndefined();
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
// Helper function to create mock client
|
|
507
|
-
function createMockClient(diagnostics: any[] = []): LSPClientInfo {
|
|
508
|
-
return {
|
|
509
|
-
serverId: "test-server",
|
|
510
|
-
root: "/test",
|
|
511
|
-
connection: {} as any,
|
|
512
|
-
notify: {
|
|
513
|
-
open: vi.fn().mockResolvedValue(undefined),
|
|
514
|
-
change: vi.fn().mockResolvedValue(undefined),
|
|
515
|
-
},
|
|
516
|
-
getDiagnostics: vi.fn().mockReturnValue(diagnostics),
|
|
517
|
-
getAllDiagnostics: vi.fn().mockReturnValue(new Map()),
|
|
518
|
-
waitForDiagnostics: vi.fn().mockResolvedValue(undefined),
|
|
519
|
-
definition: vi.fn().mockResolvedValue([]),
|
|
520
|
-
references: vi.fn().mockResolvedValue([]),
|
|
521
|
-
hover: vi.fn().mockResolvedValue(null),
|
|
522
|
-
documentSymbol: vi.fn().mockResolvedValue([]),
|
|
523
|
-
workspaceSymbol: vi.fn().mockResolvedValue([]),
|
|
524
|
-
implementation: vi.fn().mockResolvedValue([]),
|
|
525
|
-
prepareCallHierarchy: vi.fn().mockResolvedValue([]),
|
|
526
|
-
incomingCalls: vi.fn().mockResolvedValue([]),
|
|
527
|
-
outgoingCalls: vi.fn().mockResolvedValue([]),
|
|
528
|
-
shutdown: vi.fn().mockResolvedValue(undefined),
|
|
529
|
-
};
|
|
530
|
-
}
|