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.
Files changed (207) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/package.json +4 -4
  3. package/tsconfig.json +1 -1
  4. package/clients/__tests__/file-time.test.js +0 -216
  5. package/clients/__tests__/file-time.test.ts +0 -276
  6. package/clients/__tests__/format-service.test.js +0 -245
  7. package/clients/__tests__/format-service.test.ts +0 -339
  8. package/clients/__tests__/formatters.test.js +0 -271
  9. package/clients/__tests__/formatters.test.ts +0 -401
  10. package/clients/agent-behavior-client.js +0 -110
  11. package/clients/agent-behavior-client.test.js +0 -94
  12. package/clients/agent-behavior-client.test.ts +0 -116
  13. package/clients/amain-types.js +0 -164
  14. package/clients/architect-client.js +0 -291
  15. package/clients/ast-grep-client.js +0 -253
  16. package/clients/ast-grep-parser.js +0 -84
  17. package/clients/ast-grep-rule-manager.js +0 -89
  18. package/clients/ast-grep-types.js +0 -9
  19. package/clients/auto-loop.js +0 -131
  20. package/clients/biome-client.js +0 -420
  21. package/clients/biome-client.test.js +0 -144
  22. package/clients/biome-client.test.ts +0 -163
  23. package/clients/cache/rule-cache.js +0 -72
  24. package/clients/cache-manager.js +0 -245
  25. package/clients/cache-manager.test.js +0 -197
  26. package/clients/cache-manager.test.ts +0 -299
  27. package/clients/complexity-client.js +0 -675
  28. package/clients/complexity-client.test.js +0 -234
  29. package/clients/complexity-client.test.ts +0 -255
  30. package/clients/config-validator.js +0 -465
  31. package/clients/dependency-checker.js +0 -325
  32. package/clients/dependency-checker.test.js +0 -60
  33. package/clients/dependency-checker.test.ts +0 -71
  34. package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
  35. package/clients/dispatch/__tests__/autofix-integration.test.ts +0 -300
  36. package/clients/dispatch/__tests__/runner-registration.test.js +0 -234
  37. package/clients/dispatch/__tests__/runner-registration.test.ts +0 -286
  38. package/clients/dispatch/debug.log +0 -1
  39. package/clients/dispatch/dispatcher.edge.test.js +0 -82
  40. package/clients/dispatch/dispatcher.edge.test.ts +0 -100
  41. package/clients/dispatch/dispatcher.format.test.js +0 -46
  42. package/clients/dispatch/dispatcher.format.test.ts +0 -58
  43. package/clients/dispatch/dispatcher.inline.test.js +0 -74
  44. package/clients/dispatch/dispatcher.inline.test.ts +0 -93
  45. package/clients/dispatch/dispatcher.js +0 -381
  46. package/clients/dispatch/dispatcher.test.js +0 -116
  47. package/clients/dispatch/dispatcher.test.ts +0 -149
  48. package/clients/dispatch/integration.js +0 -108
  49. package/clients/dispatch/plan.js +0 -183
  50. package/clients/dispatch/runners/architect.js +0 -83
  51. package/clients/dispatch/runners/architect.test.js +0 -138
  52. package/clients/dispatch/runners/architect.test.ts +0 -162
  53. package/clients/dispatch/runners/ast-grep-napi.js +0 -405
  54. package/clients/dispatch/runners/ast-grep-napi.test.js +0 -107
  55. package/clients/dispatch/runners/ast-grep-napi.test.ts +0 -129
  56. package/clients/dispatch/runners/ast-grep.js +0 -157
  57. package/clients/dispatch/runners/biome.js +0 -55
  58. package/clients/dispatch/runners/config-validation.js +0 -67
  59. package/clients/dispatch/runners/go-vet.js +0 -48
  60. package/clients/dispatch/runners/index.js +0 -47
  61. package/clients/dispatch/runners/lsp.js +0 -102
  62. package/clients/dispatch/runners/oxlint.js +0 -67
  63. package/clients/dispatch/runners/oxlint.test.js +0 -230
  64. package/clients/dispatch/runners/oxlint.test.ts +0 -303
  65. package/clients/dispatch/runners/pyright.js +0 -100
  66. package/clients/dispatch/runners/pyright.test.js +0 -98
  67. package/clients/dispatch/runners/pyright.test.ts +0 -121
  68. package/clients/dispatch/runners/python-slop.js +0 -97
  69. package/clients/dispatch/runners/python-slop.test.js +0 -203
  70. package/clients/dispatch/runners/python-slop.test.ts +0 -298
  71. package/clients/dispatch/runners/ruff.js +0 -48
  72. package/clients/dispatch/runners/rust-clippy.js +0 -102
  73. package/clients/dispatch/runners/scan_codebase.test.js +0 -89
  74. package/clients/dispatch/runners/scan_codebase.test.ts +0 -105
  75. package/clients/dispatch/runners/shellcheck.js +0 -147
  76. package/clients/dispatch/runners/shellcheck.test.js +0 -98
  77. package/clients/dispatch/runners/shellcheck.test.ts +0 -129
  78. package/clients/dispatch/runners/similarity.js +0 -230
  79. package/clients/dispatch/runners/spellcheck.js +0 -106
  80. package/clients/dispatch/runners/spellcheck.test.js +0 -158
  81. package/clients/dispatch/runners/spellcheck.test.ts +0 -214
  82. package/clients/dispatch/runners/tree-sitter.js +0 -246
  83. package/clients/dispatch/runners/ts-lsp.js +0 -125
  84. package/clients/dispatch/runners/ts-slop.js +0 -113
  85. package/clients/dispatch/runners/type-safety.js +0 -142
  86. package/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -134
  87. package/clients/dispatch/runners/utils/runner-helpers.js +0 -115
  88. package/clients/dispatch/runners/utils.js +0 -51
  89. package/clients/dispatch/runners/yaml-rule-parser.js +0 -360
  90. package/clients/dispatch/types.js +0 -16
  91. package/clients/dispatch/utils/format-utils.js +0 -44
  92. package/clients/dogfood.test.js +0 -201
  93. package/clients/dogfood.test.ts +0 -269
  94. package/clients/file-kinds.js +0 -177
  95. package/clients/file-kinds.test.js +0 -169
  96. package/clients/file-kinds.test.ts +0 -210
  97. package/clients/file-time.js +0 -152
  98. package/clients/file-utils.js +0 -40
  99. package/clients/fix-scanners.js +0 -204
  100. package/clients/format-service.js +0 -184
  101. package/clients/formatters.js +0 -488
  102. package/clients/go-client.js +0 -203
  103. package/clients/go-client.test.js +0 -127
  104. package/clients/go-client.test.ts +0 -143
  105. package/clients/installer/index.js +0 -403
  106. package/clients/interviewer-templates.js +0 -75
  107. package/clients/interviewer.js +0 -173
  108. package/clients/jscpd-client.js +0 -196
  109. package/clients/jscpd-client.test.js +0 -127
  110. package/clients/jscpd-client.test.ts +0 -145
  111. package/clients/knip-client.js +0 -239
  112. package/clients/knip-client.test.js +0 -112
  113. package/clients/knip-client.test.ts +0 -128
  114. package/clients/latency-logger.js +0 -40
  115. package/clients/lsp/__tests__/client.test.js +0 -310
  116. package/clients/lsp/__tests__/client.test.ts +0 -412
  117. package/clients/lsp/__tests__/config.test.js +0 -167
  118. package/clients/lsp/__tests__/config.test.ts +0 -217
  119. package/clients/lsp/__tests__/error-recovery.test.js +0 -213
  120. package/clients/lsp/__tests__/error-recovery.test.ts +0 -279
  121. package/clients/lsp/__tests__/integration.test.js +0 -127
  122. package/clients/lsp/__tests__/integration.test.ts +0 -160
  123. package/clients/lsp/__tests__/launch.test.js +0 -313
  124. package/clients/lsp/__tests__/launch.test.ts +0 -394
  125. package/clients/lsp/__tests__/server.test.js +0 -259
  126. package/clients/lsp/__tests__/server.test.ts +0 -332
  127. package/clients/lsp/__tests__/service.test.js +0 -438
  128. package/clients/lsp/__tests__/service.test.ts +0 -530
  129. package/clients/lsp/client.js +0 -350
  130. package/clients/lsp/config.js +0 -112
  131. package/clients/lsp/index.js +0 -318
  132. package/clients/lsp/installer/index.js +0 -391
  133. package/clients/lsp/interactive-install.js +0 -221
  134. package/clients/lsp/language.js +0 -170
  135. package/clients/lsp/launch.js +0 -329
  136. package/clients/lsp/lsp/launch.js +0 -116
  137. package/clients/lsp/lsp/server.js +0 -532
  138. package/clients/lsp/lsp-index.js +0 -10
  139. package/clients/lsp/path-utils.js +0 -5
  140. package/clients/lsp/server.js +0 -725
  141. package/clients/lsp/test-py-spawn/requirements.txt +0 -1
  142. package/clients/lsp/test-py-spawn/test.py +0 -3
  143. package/clients/lsp/test-py-svc/requirements.txt +0 -1
  144. package/clients/lsp/test-py-svc/test.py +0 -3
  145. package/clients/lsp/test-python-project/requirements.txt +0 -1
  146. package/clients/lsp/test-python-project/test.py +0 -5
  147. package/clients/metrics-client.js +0 -107
  148. package/clients/metrics-client.test.js +0 -128
  149. package/clients/metrics-client.test.ts +0 -163
  150. package/clients/metrics-history.js +0 -367
  151. package/clients/path-utils.js +0 -142
  152. package/clients/pipeline.js +0 -272
  153. package/clients/production-readiness.js +0 -522
  154. package/clients/project-index.js +0 -255
  155. package/clients/project-metadata.js +0 -531
  156. package/clients/ruff-client.js +0 -325
  157. package/clients/ruff-client.test.js +0 -132
  158. package/clients/ruff-client.test.ts +0 -153
  159. package/clients/rules-scanner.js +0 -97
  160. package/clients/runner-tracker.js +0 -152
  161. package/clients/rust-client.js +0 -205
  162. package/clients/rust-client.test.js +0 -108
  163. package/clients/rust-client.test.ts +0 -130
  164. package/clients/safe-spawn-async.js +0 -163
  165. package/clients/safe-spawn.js +0 -241
  166. package/clients/sanitize.js +0 -291
  167. package/clients/sanitize.test.js +0 -177
  168. package/clients/sanitize.test.ts +0 -223
  169. package/clients/scan-architectural-debt.js +0 -167
  170. package/clients/scan-utils.js +0 -83
  171. package/clients/secrets-scanner.js +0 -119
  172. package/clients/secrets-scanner.test.js +0 -100
  173. package/clients/secrets-scanner.test.ts +0 -113
  174. package/clients/sg-runner.js +0 -292
  175. package/clients/state-matrix.js +0 -160
  176. package/clients/subprocess-client.js +0 -65
  177. package/clients/symbol-types.js +0 -5
  178. package/clients/test-runner-client.js +0 -523
  179. package/clients/test-runner-client.test.js +0 -192
  180. package/clients/test-runner-client.test.ts +0 -253
  181. package/clients/test-utils.js +0 -27
  182. package/clients/test-utils.ts +0 -36
  183. package/clients/todo-scanner.js +0 -200
  184. package/clients/todo-scanner.test.js +0 -301
  185. package/clients/todo-scanner.test.ts +0 -352
  186. package/clients/tool-availability.js +0 -207
  187. package/clients/tree-sitter-client.js +0 -601
  188. package/clients/tree-sitter-query-loader.js +0 -355
  189. package/clients/tree-sitter-symbol-extractor.js +0 -289
  190. package/clients/ts-service.js +0 -129
  191. package/clients/type-coverage-client.js +0 -127
  192. package/clients/type-coverage-client.test.js +0 -105
  193. package/clients/type-coverage-client.test.ts +0 -125
  194. package/clients/type-safety-client.js +0 -138
  195. package/clients/types.js +0 -11
  196. package/clients/typescript-client.codefix.test.js +0 -157
  197. package/clients/typescript-client.codefix.test.ts +0 -186
  198. package/clients/typescript-client.js +0 -509
  199. package/clients/typescript-client.test.js +0 -105
  200. package/clients/typescript-client.test.ts +0 -126
  201. package/commands/booboo.js +0 -1007
  202. package/commands/fix-from-booboo.js +0 -398
  203. package/commands/fix-simplified.js +0 -618
  204. package/commands/rate.js +0 -281
  205. package/commands/rate.test.js +0 -119
  206. package/commands/rate.test.ts +0 -131
  207. 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
- }