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,412 +0,0 @@
1
- /**
2
- * LSP Client Test Suite
3
- *
4
- * Tests for the LSP Client including:
5
- * - Connection lifecycle (initialize, shutdown)
6
- * - Document synchronization (didOpen, didChange)
7
- * - Diagnostics handling with debouncing
8
- * - JSON-RPC communication
9
- */
10
-
11
- import { EventEmitter } from "node:events";
12
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
13
- import { createLSPClient, type LSPDiagnostic } from "../client.js";
14
- import type { LSPProcess } from "../launch.js";
15
-
16
- // Mock vscode-jsonrpc
17
- const mockConnection = {
18
- listen: vi.fn(),
19
- onNotification: vi.fn(),
20
- onRequest: vi.fn(),
21
- sendRequest: vi.fn().mockResolvedValue({}),
22
- sendNotification: vi.fn().mockResolvedValue(undefined),
23
- dispose: vi.fn(),
24
- };
25
-
26
- vi.mock("vscode-jsonrpc/node.js", () => ({
27
- createMessageConnection: vi.fn(() => mockConnection),
28
- StreamMessageReader: vi.fn(),
29
- StreamMessageWriter: vi.fn(),
30
- }));
31
-
32
- import { createMessageConnection } from "vscode-jsonrpc/node.js";
33
-
34
- describe("createLSPClient", () => {
35
- let mockProcess: LSPProcess;
36
-
37
- beforeEach(() => {
38
- vi.clearAllMocks();
39
-
40
- mockProcess = {
41
- process: { pid: 123, kill: vi.fn() } as any,
42
- stdin: new EventEmitter() as any,
43
- stdout: new EventEmitter() as any,
44
- stderr: new EventEmitter() as any,
45
- pid: 123,
46
- };
47
-
48
- // Reset mock connection behavior
49
- mockConnection.sendRequest.mockResolvedValue({});
50
- mockConnection.sendNotification.mockResolvedValue(undefined);
51
- });
52
-
53
- afterEach(() => {
54
- vi.clearAllMocks();
55
- });
56
-
57
- describe("initialization", () => {
58
- it("should create JSON-RPC connection", async () => {
59
- await createLSPClient({
60
- serverId: "test-server",
61
- process: mockProcess,
62
- root: "/test",
63
- });
64
-
65
- expect(createMessageConnection).toHaveBeenCalled();
66
- expect(mockConnection.listen).toHaveBeenCalled();
67
- });
68
-
69
- it("should send initialize request with correct parameters", async () => {
70
- await createLSPClient({
71
- serverId: "test-server",
72
- process: mockProcess,
73
- root: "/test/project",
74
- });
75
-
76
- expect(mockConnection.sendRequest).toHaveBeenCalledWith(
77
- "initialize",
78
- expect.objectContaining({
79
- processId: expect.any(Number),
80
- rootUri: expect.stringContaining("test/project"),
81
- capabilities: expect.objectContaining({
82
- textDocument: expect.objectContaining({
83
- synchronization: expect.any(Object),
84
- publishDiagnostics: expect.any(Object),
85
- }),
86
- workspace: expect.any(Object),
87
- }),
88
- }),
89
- );
90
- });
91
-
92
- it("should send initialized notification after initialize", async () => {
93
- await createLSPClient({
94
- serverId: "test-server",
95
- process: mockProcess,
96
- root: "/test",
97
- });
98
-
99
- expect(mockConnection.sendNotification).toHaveBeenCalledWith(
100
- "initialized",
101
- {},
102
- );
103
- });
104
-
105
- it.skip("should handle initialization timeout", async () => {
106
- // This test is timing-sensitive and flaky in test environment
107
- // The timeout logic works correctly in production
108
- });
109
-
110
- it("should register workspace folder handler", async () => {
111
- await createLSPClient({
112
- serverId: "test-server",
113
- process: mockProcess,
114
- root: "/test/project",
115
- });
116
-
117
- expect(mockConnection.onRequest).toHaveBeenCalledWith(
118
- "workspace/workspaceFolders",
119
- expect.any(Function),
120
- );
121
- });
122
-
123
- it("should register capability handlers", async () => {
124
- await createLSPClient({
125
- serverId: "test-server",
126
- process: mockProcess,
127
- root: "/test",
128
- });
129
-
130
- expect(mockConnection.onRequest).toHaveBeenCalledWith(
131
- "client/registerCapability",
132
- expect.any(Function),
133
- );
134
- expect(mockConnection.onRequest).toHaveBeenCalledWith(
135
- "client/unregisterCapability",
136
- expect.any(Function),
137
- );
138
- });
139
- });
140
-
141
- describe("document notifications", () => {
142
- it("should send didOpen notification", async () => {
143
- const client = await createLSPClient({
144
- serverId: "test-server",
145
- process: mockProcess,
146
- root: "/test",
147
- });
148
-
149
- await client.notify.open("/test/file.ts", "const x = 1;", "typescript");
150
-
151
- expect(mockConnection.sendNotification).toHaveBeenCalledWith(
152
- "textDocument/didOpen",
153
- {
154
- textDocument: {
155
- uri: expect.stringContaining("file.ts"),
156
- languageId: "typescript",
157
- version: 0,
158
- text: "const x = 1;",
159
- },
160
- },
161
- );
162
- });
163
-
164
- it("should send didChange notification with version increment", async () => {
165
- const client = await createLSPClient({
166
- serverId: "test-server",
167
- process: mockProcess,
168
- root: "/test",
169
- });
170
-
171
- // First open the file
172
- await client.notify.open("/test/file.ts", "const x = 1;", "typescript");
173
-
174
- // Then change it
175
- await client.notify.change("/test/file.ts", "const x = 2;");
176
-
177
- const didChangeCalls = mockConnection.sendNotification.mock.calls.filter(
178
- (call: any) => call[0] === "textDocument/didChange",
179
- );
180
- expect(didChangeCalls).toHaveLength(1);
181
- expect(didChangeCalls[0][1]).toMatchObject({
182
- textDocument: { version: 1 },
183
- contentChanges: [{ text: "const x = 2;" }],
184
- });
185
- });
186
-
187
- it("should handle multiple document versions", async () => {
188
- const client = await createLSPClient({
189
- serverId: "test-server",
190
- process: mockProcess,
191
- root: "/test",
192
- });
193
-
194
- await client.notify.open("/test/file.ts", "v0", "typescript");
195
- await client.notify.change("/test/file.ts", "v1");
196
- await client.notify.change("/test/file.ts", "v2");
197
- await client.notify.change("/test/file.ts", "v3");
198
-
199
- const didChangeCalls = mockConnection.sendNotification.mock.calls.filter(
200
- (call: any) => call[0] === "textDocument/didChange",
201
- );
202
-
203
- expect(
204
- didChangeCalls.map((call: any) => call[1].textDocument.version),
205
- ).toEqual([1, 2, 3]);
206
- });
207
- });
208
-
209
- describe("diagnostics handling", () => {
210
- beforeEach(() => {
211
- vi.useFakeTimers({ shouldAdvanceTime: true });
212
- });
213
-
214
- afterEach(() => {
215
- vi.useRealTimers();
216
- });
217
-
218
- it("should set up diagnostics notification handler", async () => {
219
- await createLSPClient({
220
- serverId: "test-server",
221
- process: mockProcess,
222
- root: "/test",
223
- });
224
-
225
- expect(mockConnection.onNotification).toHaveBeenCalledWith(
226
- "textDocument/publishDiagnostics",
227
- expect.any(Function),
228
- );
229
- });
230
-
231
- it.skip("should store diagnostics for retrieval", async () => {
232
- const client = await createLSPClient({
233
- serverId: "test-server",
234
- process: mockProcess,
235
- root: "/test",
236
- });
237
-
238
- // Get the registered handler and call it directly with diagnostics
239
- const handler = mockConnection.onNotification.mock.calls.find(
240
- (call: any) => call[0] === "textDocument/publishDiagnostics",
241
- )?.[1];
242
-
243
- const mockDiagnostics: LSPDiagnostic[] = [
244
- {
245
- severity: 1,
246
- message: "Error",
247
- range: {
248
- start: { line: 0, character: 0 },
249
- end: { line: 0, character: 1 },
250
- },
251
- },
252
- ];
253
-
254
- handler?.({ uri: "file:///test/file.ts", diagnostics: mockDiagnostics });
255
- await vi.advanceTimersByTimeAsync(200);
256
-
257
- const stored = client.getDiagnostics("/test/file.ts");
258
- expect(stored).toEqual(mockDiagnostics);
259
- });
260
-
261
- it("should return empty array for unknown files", async () => {
262
- const client = await createLSPClient({
263
- serverId: "test-server",
264
- process: mockProcess,
265
- root: "/test",
266
- });
267
-
268
- const diags = client.getDiagnostics("/unknown/file.ts");
269
- expect(diags).toEqual([]);
270
- });
271
-
272
- it("should wait for diagnostics with timeout", async () => {
273
- const client = await createLSPClient({
274
- serverId: "test-server",
275
- process: mockProcess,
276
- root: "/test",
277
- });
278
-
279
- // waitForDiagnostics resolves via timeout when no notification arrives
280
- const promise = client.waitForDiagnostics("/test/file.ts", 100);
281
- await vi.advanceTimersByTimeAsync(150);
282
- await promise;
283
- // If we got here, the timeout resolved — test passes
284
- });
285
-
286
- it.skip("should resolve waitForDiagnostics immediately if diagnostics exist", async () => {
287
- const client = await createLSPClient({
288
- serverId: "test-server",
289
- process: mockProcess,
290
- root: "/test",
291
- });
292
-
293
- // Pre-populate diagnostics via the publishDiagnostics handler
294
- const handler = mockConnection.onNotification.mock.calls.find(
295
- (call: any) => call[0] === "textDocument/publishDiagnostics",
296
- )?.[1];
297
-
298
- handler?.({
299
- uri: "file:///test/file.ts",
300
- diagnostics: [
301
- {
302
- severity: 1,
303
- message: "Error",
304
- range: {
305
- start: { line: 0, character: 0 },
306
- end: { line: 0, character: 1 },
307
- },
308
- },
309
- ],
310
- });
311
- await vi.advanceTimersByTimeAsync(200);
312
-
313
- // getDiagnostics should have data now
314
- const stored = client.getDiagnostics("/test/file.ts");
315
- expect(stored.length).toBeGreaterThan(0);
316
-
317
- // waitForDiagnostics should return immediately (diagnostics.has() check)
318
- // No need to advance timers — it short-circuits
319
- await client.waitForDiagnostics("/test/file.ts", 5000);
320
- });
321
- });
322
-
323
- describe("shutdown", () => {
324
- beforeEach(() => {
325
- // Use real timers for shutdown tests
326
- vi.useRealTimers();
327
- });
328
-
329
- it("should send shutdown request", async () => {
330
- const client = await createLSPClient({
331
- serverId: "test-server",
332
- process: mockProcess,
333
- root: "/test",
334
- });
335
-
336
- await client.shutdown();
337
-
338
- expect(mockConnection.sendRequest).toHaveBeenCalledWith("shutdown");
339
- });
340
-
341
- it("should send exit notification", async () => {
342
- const client = await createLSPClient({
343
- serverId: "test-server",
344
- process: mockProcess,
345
- root: "/test",
346
- });
347
-
348
- await client.shutdown();
349
-
350
- expect(mockConnection.sendNotification).toHaveBeenCalledWith("exit");
351
- });
352
-
353
- it("should dispose connection", async () => {
354
- const client = await createLSPClient({
355
- serverId: "test-server",
356
- process: mockProcess,
357
- root: "/test",
358
- });
359
-
360
- await client.shutdown();
361
-
362
- expect(mockConnection.dispose).toHaveBeenCalled();
363
- });
364
-
365
- it("should kill process", async () => {
366
- const mockKill = vi.fn();
367
- const processWithKill = {
368
- ...mockProcess,
369
- process: { ...mockProcess.process, kill: mockKill },
370
- };
371
-
372
- const client = await createLSPClient({
373
- serverId: "test-server",
374
- process: processWithKill as any,
375
- root: "/test",
376
- });
377
-
378
- await client.shutdown();
379
-
380
- expect(mockKill).toHaveBeenCalled();
381
- });
382
-
383
- it("should handle shutdown errors gracefully", async () => {
384
- const client = await createLSPClient({
385
- serverId: "test-server",
386
- process: mockProcess,
387
- root: "/test",
388
- });
389
-
390
- // Make shutdown request fail (after successful initialize)
391
- mockConnection.sendRequest.mockRejectedValue(
392
- new Error("Connection error"),
393
- );
394
-
395
- // Should not throw
396
- await expect(client.shutdown()).resolves.not.toThrow();
397
- });
398
- });
399
-
400
- describe("client info", () => {
401
- it("should return serverId and root", async () => {
402
- const client = await createLSPClient({
403
- serverId: "my-lsp-server",
404
- process: mockProcess,
405
- root: "/my/project",
406
- });
407
-
408
- expect(client.serverId).toBe("my-lsp-server");
409
- expect(client.root).toBe("/my/project");
410
- });
411
- });
412
- });
@@ -1,167 +0,0 @@
1
- /**
2
- * LSP Configuration Test Suite
3
- *
4
- * Tests for configuration including:
5
- * - Config file loading
6
- * - Custom server creation
7
- * - Server registry management
8
- * - Disabled server handling
9
- */
10
- import { beforeEach, describe, expect, it, vi } from "vitest";
11
- // Mock fs/promises before any imports that use it
12
- const mockReadFile = vi.fn();
13
- const mockAccess = vi.fn();
14
- const mockStat = vi.fn();
15
- vi.mock("node:fs/promises", async () => {
16
- return {
17
- readFile: mockReadFile,
18
- access: mockAccess,
19
- stat: mockStat,
20
- };
21
- });
22
- // Import after mocking - mocks are already defined above
23
- const { loadLSPConfig, createCustomServer, initLSPConfig, getAllServers, isServerDisabled, getServersForFileWithConfig, } = await import("../config.js");
24
- describe("loadLSPConfig", () => {
25
- beforeEach(() => {
26
- vi.clearAllMocks();
27
- });
28
- it.skip("should load config from .pi-lens/lsp.json", async () => {
29
- const config = {
30
- servers: {
31
- "my-server": {
32
- name: "My Custom Server",
33
- extensions: [".myext"],
34
- command: "my-lsp",
35
- args: ["--stdio"],
36
- },
37
- },
38
- };
39
- mockReadFile.mockResolvedValue(JSON.stringify(config));
40
- const result = await loadLSPConfig("/project");
41
- expect(result).toEqual(config);
42
- expect(mockReadFile).toHaveBeenCalled();
43
- });
44
- it("should return empty config when file not found", async () => {
45
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
46
- const result = await loadLSPConfig("/project");
47
- expect(result).toEqual({});
48
- });
49
- it("should handle invalid JSON gracefully", async () => {
50
- mockReadFile.mockResolvedValue("not valid json");
51
- const result = await loadLSPConfig("/project");
52
- expect(result).toEqual({});
53
- });
54
- it.skip("should try multiple config paths", async () => {
55
- mockReadFile
56
- .mockRejectedValueOnce(new Error("ENOENT"))
57
- .mockRejectedValueOnce(new Error("ENOENT"))
58
- .mockResolvedValueOnce(JSON.stringify({ servers: {} }));
59
- const result = await loadLSPConfig("/project");
60
- expect(mockReadFile).toHaveBeenCalledTimes(3);
61
- expect(result).toEqual({ servers: {} });
62
- });
63
- });
64
- describe("createCustomServer", () => {
65
- it("should create server from config", () => {
66
- const config = {
67
- name: "Custom LSP",
68
- extensions: [".custom"],
69
- command: "custom-lsp",
70
- args: ["--stdio", "--verbose"],
71
- rootMarkers: [".customrc"],
72
- };
73
- const server = createCustomServer(config, "custom-server");
74
- expect(server.id).toBe("custom-server");
75
- expect(server.name).toBe("Custom LSP");
76
- expect(server.extensions).toEqual([".custom"]);
77
- expect(typeof server.spawn).toBe("function");
78
- expect(typeof server.root).toBe("function");
79
- });
80
- it("should use process.cwd() as root when no markers specified", async () => {
81
- const config = {
82
- name: "Simple LSP",
83
- extensions: [".simple"],
84
- command: "simple-lsp",
85
- };
86
- const server = createCustomServer(config, "simple");
87
- const root = await server.root("/any/path/file.simple");
88
- expect(root).toBe(process.cwd());
89
- });
90
- });
91
- describe("initLSPConfig", () => {
92
- beforeEach(() => {
93
- vi.clearAllMocks();
94
- // Reset by calling init with empty config
95
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
96
- return initLSPConfig("/test-reset");
97
- });
98
- it("should initialize with empty config", async () => {
99
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
100
- await initLSPConfig("/project");
101
- const servers = getAllServers();
102
- // Should have built-in servers
103
- expect(servers.some((s) => s.id === "typescript")).toBe(true);
104
- });
105
- it.skip("should register custom servers from config", async () => {
106
- const config = {
107
- servers: {
108
- "custom-test-server": {
109
- name: "Custom Test Server",
110
- extensions: [".ctest"],
111
- command: "ctest-lsp",
112
- },
113
- },
114
- };
115
- mockReadFile.mockResolvedValue(JSON.stringify(config));
116
- await initLSPConfig("/project");
117
- const servers = getAllServers();
118
- expect(servers.some((s) => s.id === "custom-test-server")).toBe(true);
119
- });
120
- it.skip("should handle disabled servers", async () => {
121
- const config = {
122
- disabledServers: ["python"],
123
- };
124
- mockReadFile.mockResolvedValue(JSON.stringify(config));
125
- await initLSPConfig("/project");
126
- expect(isServerDisabled("python")).toBe(true);
127
- expect(isServerDisabled("typescript")).toBe(false);
128
- });
129
- });
130
- describe("getAllServers", () => {
131
- beforeEach(async () => {
132
- vi.clearAllMocks();
133
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
134
- await initLSPConfig("/test");
135
- });
136
- it("should include built-in servers", () => {
137
- const servers = getAllServers();
138
- expect(servers.some((s) => s.id === "typescript")).toBe(true);
139
- expect(servers.some((s) => s.id === "python")).toBe(true);
140
- expect(servers.some((s) => s.id === "go")).toBe(true);
141
- expect(servers.some((s) => s.id === "rust")).toBe(true);
142
- });
143
- });
144
- describe("getServersForFileWithConfig", () => {
145
- beforeEach(async () => {
146
- vi.clearAllMocks();
147
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
148
- await initLSPConfig("/test");
149
- });
150
- it("should find TypeScript server for .ts files", () => {
151
- const servers = getServersForFileWithConfig("/project/file.ts");
152
- expect(servers.some((s) => s.id === "typescript")).toBe(true);
153
- });
154
- it("should find Python server for .py files", () => {
155
- const servers = getServersForFileWithConfig("/project/file.py");
156
- expect(servers.some((s) => s.id === "python")).toBe(true);
157
- });
158
- it("should return empty array for unknown file type", () => {
159
- const servers = getServersForFileWithConfig("/project/file.unknown");
160
- expect(servers).toEqual([]);
161
- });
162
- it("should be case insensitive for extensions", () => {
163
- const servers1 = getServersForFileWithConfig("/project/file.TS");
164
- const servers2 = getServersForFileWithConfig("/project/file.ts");
165
- expect(servers1.map((s) => s.id)).toEqual(servers2.map((s) => s.id));
166
- });
167
- });