pi-lens 3.1.2 → 3.2.0

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 (154) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +16 -12
  3. package/clients/ast-grep-client.js +8 -1
  4. package/clients/ast-grep-client.ts +9 -1
  5. package/clients/biome-client.js +51 -38
  6. package/clients/biome-client.ts +60 -58
  7. package/clients/dependency-checker.js +30 -1
  8. package/clients/dependency-checker.ts +35 -1
  9. package/clients/dispatch/__tests__/runner-registration.test.ts +286 -282
  10. package/clients/dispatch/bus-dispatcher.js +15 -14
  11. package/clients/dispatch/bus-dispatcher.ts +32 -25
  12. package/clients/dispatch/dispatcher.js +18 -25
  13. package/clients/dispatch/dispatcher.test.ts +2 -1
  14. package/clients/dispatch/dispatcher.ts +17 -28
  15. package/clients/dispatch/plan.js +77 -32
  16. package/clients/dispatch/plan.ts +78 -32
  17. package/clients/dispatch/runners/ast-grep-napi.js +36 -376
  18. package/clients/dispatch/runners/ast-grep-napi.ts +60 -433
  19. package/clients/dispatch/runners/index.js +8 -4
  20. package/clients/dispatch/runners/index.ts +8 -4
  21. package/clients/dispatch/runners/lsp.js +65 -0
  22. package/clients/dispatch/runners/lsp.ts +125 -0
  23. package/clients/dispatch/runners/oxlint.js +2 -2
  24. package/clients/dispatch/runners/oxlint.ts +2 -2
  25. package/clients/dispatch/runners/pyright.js +24 -8
  26. package/clients/dispatch/runners/pyright.ts +28 -14
  27. package/clients/dispatch/runners/rust-clippy.js +2 -2
  28. package/clients/dispatch/runners/rust-clippy.ts +2 -4
  29. package/clients/dispatch/runners/tree-sitter.js +14 -2
  30. package/clients/dispatch/runners/tree-sitter.ts +15 -2
  31. package/clients/dispatch/runners/ts-lsp.js +3 -3
  32. package/clients/dispatch/runners/ts-lsp.ts +8 -5
  33. package/clients/dispatch/runners/yaml-rule-parser.js +292 -0
  34. package/clients/dispatch/runners/yaml-rule-parser.ts +338 -0
  35. package/clients/dispatch/types.js +3 -0
  36. package/clients/dispatch/types.ts +3 -0
  37. package/clients/formatters.js +67 -14
  38. package/clients/formatters.ts +68 -15
  39. package/clients/installer/index.js +78 -10
  40. package/clients/installer/index.ts +519 -426
  41. package/clients/jscpd-client.js +28 -0
  42. package/clients/jscpd-client.ts +41 -3
  43. package/clients/knip-client.js +30 -1
  44. package/clients/knip-client.ts +34 -2
  45. package/clients/lsp/__tests__/client.test.ts +64 -41
  46. package/clients/lsp/__tests__/config.test.ts +25 -17
  47. package/clients/lsp/__tests__/launch.test.ts +108 -43
  48. package/clients/lsp/__tests__/service.test.ts +76 -48
  49. package/clients/lsp/client.js +87 -2
  50. package/clients/lsp/client.ts +150 -6
  51. package/clients/lsp/config.js +8 -11
  52. package/clients/lsp/config.ts +24 -21
  53. package/clients/lsp/index.js +69 -0
  54. package/clients/lsp/index.ts +82 -0
  55. package/clients/lsp/interactive-install.js +19 -8
  56. package/clients/lsp/interactive-install.ts +52 -27
  57. package/clients/lsp/launch.js +182 -32
  58. package/clients/lsp/launch.ts +241 -38
  59. package/clients/lsp/path-utils.js +3 -46
  60. package/clients/lsp/path-utils.ts +11 -51
  61. package/clients/lsp/server.js +93 -71
  62. package/clients/lsp/server.ts +173 -131
  63. package/clients/path-utils.js +142 -0
  64. package/clients/path-utils.ts +153 -0
  65. package/clients/ruff-client.js +33 -4
  66. package/clients/ruff-client.ts +44 -13
  67. package/clients/safe-spawn.js +3 -1
  68. package/clients/safe-spawn.ts +3 -1
  69. package/clients/services/effect-integration.js +11 -7
  70. package/clients/services/effect-integration.ts +34 -26
  71. package/clients/sg-runner.js +51 -9
  72. package/clients/sg-runner.ts +58 -15
  73. package/clients/tree-sitter-client.js +12 -0
  74. package/clients/tree-sitter-client.ts +12 -0
  75. package/clients/typescript-client.js +6 -2
  76. package/clients/typescript-client.ts +9 -2
  77. package/commands/booboo.js +2 -4
  78. package/commands/booboo.ts +2 -4
  79. package/index.ts +377 -93
  80. package/package.json +2 -1
  81. package/rules/tree-sitter-queries/tsx/no-nested-links.yml +45 -0
  82. package/rules/tree-sitter-queries/typescript/constructor-super.yml +55 -0
  83. package/rules/tree-sitter-queries/typescript/debugger.yml +1 -1
  84. package/rules/tree-sitter-queries/typescript/no-dupe-class-members.yml +47 -0
  85. package/tsconfig.json +1 -1
  86. package/clients/__tests__/file-time.test.js +0 -216
  87. package/clients/__tests__/format-service.test.js +0 -245
  88. package/clients/__tests__/formatters.test.js +0 -271
  89. package/clients/agent-behavior-client.test.js +0 -94
  90. package/clients/ast-grep-client.test.js +0 -129
  91. package/clients/ast-grep-client.test.ts +0 -155
  92. package/clients/biome-client.test.js +0 -144
  93. package/clients/cache-manager.test.js +0 -197
  94. package/clients/complexity-client.test.js +0 -234
  95. package/clients/dependency-checker.test.js +0 -60
  96. package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
  97. package/clients/dispatch/__tests__/runner-registration.test.js +0 -236
  98. package/clients/dispatch/dispatcher.edge.test.js +0 -82
  99. package/clients/dispatch/dispatcher.format.test.js +0 -46
  100. package/clients/dispatch/dispatcher.inline.test.js +0 -74
  101. package/clients/dispatch/dispatcher.test.js +0 -115
  102. package/clients/dispatch/runners/architect.test.js +0 -138
  103. package/clients/dispatch/runners/ast-grep-napi.test.js +0 -106
  104. package/clients/dispatch/runners/oxlint.test.js +0 -230
  105. package/clients/dispatch/runners/pyright.test.js +0 -98
  106. package/clients/dispatch/runners/python-slop.test.js +0 -203
  107. package/clients/dispatch/runners/scan_codebase.test.js +0 -89
  108. package/clients/dispatch/runners/shellcheck.test.js +0 -98
  109. package/clients/dispatch/runners/spellcheck.test.js +0 -158
  110. package/clients/dispatch/runners/ts-slop.test.js +0 -180
  111. package/clients/dispatch/runners/ts-slop.test.ts +0 -230
  112. package/clients/dogfood.test.js +0 -201
  113. package/clients/file-kinds.test.js +0 -169
  114. package/clients/go-client.test.js +0 -127
  115. package/clients/jscpd-client.test.js +0 -127
  116. package/clients/knip-client.test.js +0 -112
  117. package/clients/lsp/__tests__/client.test.js +0 -325
  118. package/clients/lsp/__tests__/config.test.js +0 -166
  119. package/clients/lsp/__tests__/error-recovery.test.js +0 -213
  120. package/clients/lsp/__tests__/integration.test.js +0 -127
  121. package/clients/lsp/__tests__/launch.test.js +0 -260
  122. package/clients/lsp/__tests__/server.test.js +0 -259
  123. package/clients/lsp/__tests__/service.test.js +0 -417
  124. package/clients/metrics-client.test.js +0 -141
  125. package/clients/ruff-client.test.js +0 -132
  126. package/clients/rust-client.test.js +0 -108
  127. package/clients/sanitize.test.js +0 -177
  128. package/clients/secrets-scanner.test.js +0 -100
  129. package/clients/services/__tests__/effect-integration.test.js +0 -86
  130. package/clients/test-runner-client.test.js +0 -192
  131. package/clients/todo-scanner.test.js +0 -301
  132. package/clients/type-coverage-client.test.js +0 -105
  133. package/clients/typescript-client.codefix.test.js +0 -157
  134. package/clients/typescript-client.test.js +0 -105
  135. package/commands/clients/ast-grep-client.js +0 -250
  136. package/commands/clients/ast-grep-parser.js +0 -86
  137. package/commands/clients/ast-grep-rule-manager.js +0 -91
  138. package/commands/clients/ast-grep-types.js +0 -9
  139. package/commands/clients/biome-client.js +0 -380
  140. package/commands/clients/complexity-client.js +0 -667
  141. package/commands/clients/file-kinds.js +0 -177
  142. package/commands/clients/file-utils.js +0 -40
  143. package/commands/clients/jscpd-client.js +0 -169
  144. package/commands/clients/knip-client.js +0 -211
  145. package/commands/clients/ruff-client.js +0 -297
  146. package/commands/clients/safe-spawn.js +0 -88
  147. package/commands/clients/scan-utils.js +0 -83
  148. package/commands/clients/sg-runner.js +0 -190
  149. package/commands/clients/types.js +0 -11
  150. package/commands/clients/typescript-client.js +0 -505
  151. package/commands/rate.test.js +0 -119
  152. package/rules/ast-grep-rules/rules/no-dangerously-set-inner-html.yml +0 -13
  153. package/rules/ast-grep-rules/rules/no-debugger.yml +0 -12
  154. package/rules/ast-grep-rules/rules/no-eval.yml +0 -13
@@ -1,325 +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
- import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
11
- import { createLSPClient } from "../client.js";
12
- import { EventEmitter } from "events";
13
- // Mock vscode-jsonrpc
14
- const mockConnection = {
15
- listen: vi.fn(),
16
- onNotification: vi.fn(),
17
- onRequest: vi.fn(),
18
- sendRequest: vi.fn().mockResolvedValue({}),
19
- sendNotification: vi.fn().mockResolvedValue(undefined),
20
- dispose: vi.fn(),
21
- };
22
- vi.mock("vscode-jsonrpc/node.js", () => ({
23
- createMessageConnection: vi.fn(() => mockConnection),
24
- StreamMessageReader: vi.fn(),
25
- StreamMessageWriter: vi.fn(),
26
- }));
27
- vi.mock("../../bus/events.js", () => ({
28
- DiagnosticFound: {
29
- publish: vi.fn(),
30
- },
31
- }));
32
- import { DiagnosticFound } from "../../bus/events.js";
33
- import { createMessageConnection } from "vscode-jsonrpc/node.js";
34
- describe("createLSPClient", () => {
35
- let mockProcess;
36
- beforeEach(() => {
37
- vi.clearAllMocks();
38
- mockProcess = {
39
- process: { pid: 123 },
40
- stdin: new EventEmitter(),
41
- stdout: new EventEmitter(),
42
- stderr: new EventEmitter(),
43
- pid: 123,
44
- };
45
- // Reset mock connection behavior
46
- mockConnection.sendRequest.mockResolvedValue({});
47
- mockConnection.sendNotification.mockResolvedValue(undefined);
48
- });
49
- afterEach(() => {
50
- vi.clearAllMocks();
51
- });
52
- describe("initialization", () => {
53
- it("should create JSON-RPC connection", async () => {
54
- await createLSPClient({
55
- serverId: "test-server",
56
- process: mockProcess,
57
- root: "/test",
58
- });
59
- expect(createMessageConnection).toHaveBeenCalled();
60
- expect(mockConnection.listen).toHaveBeenCalled();
61
- });
62
- it("should send initialize request with correct parameters", async () => {
63
- await createLSPClient({
64
- serverId: "test-server",
65
- process: mockProcess,
66
- root: "/test/project",
67
- });
68
- expect(mockConnection.sendRequest).toHaveBeenCalledWith("initialize", expect.objectContaining({
69
- processId: 123,
70
- rootUri: expect.stringContaining("/test/project"),
71
- capabilities: expect.objectContaining({
72
- textDocument: expect.objectContaining({
73
- synchronization: expect.any(Object),
74
- publishDiagnostics: expect.any(Object),
75
- }),
76
- workspace: expect.any(Object),
77
- }),
78
- }));
79
- });
80
- it("should send initialized notification after initialize", async () => {
81
- await createLSPClient({
82
- serverId: "test-server",
83
- process: mockProcess,
84
- root: "/test",
85
- });
86
- expect(mockConnection.sendNotification).toHaveBeenCalledWith("initialized", {});
87
- });
88
- it.skip("should handle initialization timeout", async () => {
89
- // This test is timing-sensitive and flaky in test environment
90
- // The timeout logic works correctly in production
91
- });
92
- it("should register workspace folder handler", async () => {
93
- await createLSPClient({
94
- serverId: "test-server",
95
- process: mockProcess,
96
- root: "/test/project",
97
- });
98
- expect(mockConnection.onRequest).toHaveBeenCalledWith("workspace/workspaceFolders", expect.any(Function));
99
- });
100
- it("should register capability handlers", async () => {
101
- await createLSPClient({
102
- serverId: "test-server",
103
- process: mockProcess,
104
- root: "/test",
105
- });
106
- expect(mockConnection.onRequest).toHaveBeenCalledWith("client/registerCapability", expect.any(Function));
107
- expect(mockConnection.onRequest).toHaveBeenCalledWith("client/unregisterCapability", expect.any(Function));
108
- });
109
- });
110
- describe("document notifications", () => {
111
- it("should send didOpen notification", async () => {
112
- const client = await createLSPClient({
113
- serverId: "test-server",
114
- process: mockProcess,
115
- root: "/test",
116
- });
117
- await client.notify.open("/test/file.ts", "const x = 1;", "typescript");
118
- expect(mockConnection.sendNotification).toHaveBeenCalledWith("textDocument/didOpen", {
119
- textDocument: {
120
- uri: expect.stringContaining("file.ts"),
121
- languageId: "typescript",
122
- version: 0,
123
- text: "const x = 1;",
124
- },
125
- });
126
- });
127
- it("should send didChange notification with version increment", async () => {
128
- const client = await createLSPClient({
129
- serverId: "test-server",
130
- process: mockProcess,
131
- root: "/test",
132
- });
133
- // First open the file
134
- await client.notify.open("/test/file.ts", "const x = 1;", "typescript");
135
- // Then change it
136
- await client.notify.change("/test/file.ts", "const x = 2;");
137
- const didChangeCalls = mockConnection.sendNotification.mock.calls.filter((call) => call[0] === "textDocument/didChange");
138
- expect(didChangeCalls).toHaveLength(1);
139
- expect(didChangeCalls[0][1]).toMatchObject({
140
- textDocument: { version: 1 },
141
- contentChanges: [{ text: "const x = 2;" }],
142
- });
143
- });
144
- it("should handle multiple document versions", async () => {
145
- const client = await createLSPClient({
146
- serverId: "test-server",
147
- process: mockProcess,
148
- root: "/test",
149
- });
150
- await client.notify.open("/test/file.ts", "v0", "typescript");
151
- await client.notify.change("/test/file.ts", "v1");
152
- await client.notify.change("/test/file.ts", "v2");
153
- await client.notify.change("/test/file.ts", "v3");
154
- const didChangeCalls = mockConnection.sendNotification.mock.calls.filter((call) => call[0] === "textDocument/didChange");
155
- expect(didChangeCalls.map((call) => call[1].textDocument.version))
156
- .toEqual([1, 2, 3]);
157
- });
158
- });
159
- describe("diagnostics handling", () => {
160
- beforeEach(() => {
161
- vi.useFakeTimers({ shouldAdvanceTime: true });
162
- });
163
- afterEach(() => {
164
- vi.useRealTimers();
165
- });
166
- it("should set up diagnostics notification handler", async () => {
167
- await createLSPClient({
168
- serverId: "test-server",
169
- process: mockProcess,
170
- root: "/test",
171
- });
172
- expect(mockConnection.onNotification).toHaveBeenCalledWith("textDocument/publishDiagnostics", expect.any(Function));
173
- });
174
- it("should publish diagnostics to bus", async () => {
175
- await createLSPClient({
176
- serverId: "test-server",
177
- process: mockProcess,
178
- root: "/test",
179
- });
180
- // Get the registered handler
181
- const handler = mockConnection.onNotification.mock.calls.find((call) => call[0] === "textDocument/publishDiagnostics")?.[1];
182
- expect(handler).toBeDefined();
183
- // Simulate receiving diagnostics
184
- const mockDiagnostics = [
185
- {
186
- severity: 1,
187
- message: "Type error",
188
- range: {
189
- start: { line: 0, character: 0 },
190
- end: { line: 0, character: 5 },
191
- },
192
- code: "TS2345",
193
- },
194
- ];
195
- // Call handler directly (would be debounced in real scenario)
196
- handler?.({ uri: "file:///test/file.ts", diagnostics: mockDiagnostics });
197
- // Advance past debounce (150ms)
198
- await vi.advanceTimersByTimeAsync(200);
199
- expect(DiagnosticFound.publish).toHaveBeenCalled();
200
- });
201
- it("should store diagnostics for retrieval", async () => {
202
- const client = await createLSPClient({
203
- serverId: "test-server",
204
- process: mockProcess,
205
- root: "/test",
206
- });
207
- // Get the registered handler and call it directly with diagnostics
208
- const handler = mockConnection.onNotification.mock.calls.find((call) => call[0] === "textDocument/publishDiagnostics")?.[1];
209
- const mockDiagnostics = [
210
- {
211
- severity: 1,
212
- message: "Error",
213
- range: { start: { line: 0, character: 0 }, end: { line: 0, character: 1 } },
214
- },
215
- ];
216
- handler?.({ uri: "file:///test/file.ts", diagnostics: mockDiagnostics });
217
- await vi.advanceTimersByTimeAsync(200);
218
- const stored = client.getDiagnostics("/test/file.ts");
219
- expect(stored).toEqual(mockDiagnostics);
220
- });
221
- it("should return empty array for unknown files", async () => {
222
- const client = await createLSPClient({
223
- serverId: "test-server",
224
- process: mockProcess,
225
- root: "/test",
226
- });
227
- const diags = client.getDiagnostics("/unknown/file.ts");
228
- expect(diags).toEqual([]);
229
- });
230
- it("should wait for diagnostics with timeout", async () => {
231
- const client = await createLSPClient({
232
- serverId: "test-server",
233
- process: mockProcess,
234
- root: "/test",
235
- });
236
- const startTime = Date.now();
237
- await client.waitForDiagnostics("/test/file.ts", 100);
238
- const elapsed = Date.now() - startTime;
239
- expect(elapsed).toBeGreaterThanOrEqual(100);
240
- });
241
- it("should resolve waitForDiagnostics immediately if diagnostics exist", async () => {
242
- const client = await createLSPClient({
243
- serverId: "test-server",
244
- process: mockProcess,
245
- root: "/test",
246
- });
247
- // Pre-populate diagnostics
248
- const handler = mockConnection.onNotification.mock.calls.find((call) => call[0] === "textDocument/publishDiagnostics")?.[1];
249
- handler?.({
250
- uri: "file:///test/file.ts",
251
- diagnostics: [{ severity: 1, message: "Error", range: { start: { line: 0, character: 0 }, end: { line: 0, character: 1 } } }],
252
- });
253
- await vi.advanceTimersByTimeAsync(200);
254
- const startTime = Date.now();
255
- await client.waitForDiagnostics("/test/file.ts", 5000);
256
- const elapsed = Date.now() - startTime;
257
- expect(elapsed).toBeLessThan(500); // Allow some time for test overhead
258
- });
259
- });
260
- describe("shutdown", () => {
261
- beforeEach(() => {
262
- // Use real timers for shutdown tests
263
- vi.useRealTimers();
264
- });
265
- it("should send shutdown request", async () => {
266
- const client = await createLSPClient({
267
- serverId: "test-server",
268
- process: mockProcess,
269
- root: "/test",
270
- });
271
- await client.shutdown();
272
- expect(mockConnection.sendRequest).toHaveBeenCalledWith("shutdown");
273
- });
274
- it("should send exit notification", async () => {
275
- const client = await createLSPClient({
276
- serverId: "test-server",
277
- process: mockProcess,
278
- root: "/test",
279
- });
280
- await client.shutdown();
281
- expect(mockConnection.sendNotification).toHaveBeenCalledWith("exit");
282
- });
283
- it("should dispose connection", async () => {
284
- const client = await createLSPClient({
285
- serverId: "test-server",
286
- process: mockProcess,
287
- root: "/test",
288
- });
289
- await client.shutdown();
290
- expect(mockConnection.dispose).toHaveBeenCalled();
291
- });
292
- it("should kill process", async () => {
293
- const mockKill = vi.fn();
294
- const processWithKill = { ...mockProcess, process: { ...mockProcess.process, kill: mockKill } };
295
- const client = await createLSPClient({
296
- serverId: "test-server",
297
- process: processWithKill,
298
- root: "/test",
299
- });
300
- await client.shutdown();
301
- expect(mockKill).toHaveBeenCalled();
302
- });
303
- it("should handle shutdown errors gracefully", async () => {
304
- mockConnection.sendRequest.mockRejectedValue(new Error("Connection error"));
305
- const client = await createLSPClient({
306
- serverId: "test-server",
307
- process: mockProcess,
308
- root: "/test",
309
- });
310
- // Should not throw
311
- await expect(client.shutdown()).resolves.not.toThrow();
312
- });
313
- });
314
- describe("client info", () => {
315
- it("should return serverId and root", async () => {
316
- const client = await createLSPClient({
317
- serverId: "my-lsp-server",
318
- process: mockProcess,
319
- root: "/my/project",
320
- });
321
- expect(client.serverId).toBe("my-lsp-server");
322
- expect(client.root).toBe("/my/project");
323
- });
324
- });
325
- });
@@ -1,166 +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 { describe, it, expect, beforeEach, vi } from "vitest";
11
- import * as fs from "fs/promises";
12
- // Mock fs/promises before importing the module under test
13
- vi.mock("fs/promises", async () => {
14
- return {
15
- readFile: vi.fn(),
16
- access: vi.fn(),
17
- stat: vi.fn(),
18
- };
19
- });
20
- // Import after mocking
21
- const { loadLSPConfig, createCustomServer, initLSPConfig, getAllServers, isServerDisabled, getServersForFileWithConfig } = await import("../config.js");
22
- const mockReadFile = vi.mocked(fs.readFile);
23
- describe("loadLSPConfig", () => {
24
- beforeEach(() => {
25
- vi.clearAllMocks();
26
- });
27
- it("should load config from .pi-lens/lsp.json", async () => {
28
- const config = {
29
- servers: {
30
- "my-server": {
31
- name: "My Custom Server",
32
- extensions: [".myext"],
33
- command: "my-lsp",
34
- args: ["--stdio"],
35
- },
36
- },
37
- };
38
- mockReadFile.mockResolvedValue(JSON.stringify(config));
39
- const result = await loadLSPConfig("/project");
40
- expect(result).toEqual(config);
41
- expect(mockReadFile).toHaveBeenCalled();
42
- });
43
- it("should return empty config when file not found", async () => {
44
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
45
- const result = await loadLSPConfig("/project");
46
- expect(result).toEqual({});
47
- });
48
- it("should handle invalid JSON gracefully", async () => {
49
- mockReadFile.mockResolvedValue("not valid json");
50
- const result = await loadLSPConfig("/project");
51
- expect(result).toEqual({});
52
- });
53
- it("should try multiple config paths", async () => {
54
- mockReadFile
55
- .mockRejectedValueOnce(new Error("ENOENT"))
56
- .mockRejectedValueOnce(new Error("ENOENT"))
57
- .mockResolvedValueOnce(JSON.stringify({ servers: {} }));
58
- const result = await loadLSPConfig("/project");
59
- expect(mockReadFile).toHaveBeenCalledTimes(3);
60
- expect(result).toEqual({ servers: {} });
61
- });
62
- });
63
- describe("createCustomServer", () => {
64
- it("should create server from config", () => {
65
- const config = {
66
- name: "Custom LSP",
67
- extensions: [".custom"],
68
- command: "custom-lsp",
69
- args: ["--stdio", "--verbose"],
70
- rootMarkers: [".customrc"],
71
- };
72
- const server = createCustomServer(config, "custom-server");
73
- expect(server.id).toBe("custom-server");
74
- expect(server.name).toBe("Custom LSP");
75
- expect(server.extensions).toEqual([".custom"]);
76
- expect(typeof server.spawn).toBe("function");
77
- expect(typeof server.root).toBe("function");
78
- });
79
- it("should use process.cwd() as root when no markers specified", async () => {
80
- const config = {
81
- name: "Simple LSP",
82
- extensions: [".simple"],
83
- command: "simple-lsp",
84
- };
85
- const server = createCustomServer(config, "simple");
86
- const root = await server.root("/any/path/file.simple");
87
- expect(root).toBe(process.cwd());
88
- });
89
- });
90
- describe("initLSPConfig", () => {
91
- beforeEach(() => {
92
- vi.clearAllMocks();
93
- // Reset by calling init with empty config
94
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
95
- return initLSPConfig("/test-reset");
96
- });
97
- it("should initialize with empty config", async () => {
98
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
99
- await initLSPConfig("/project");
100
- const servers = getAllServers();
101
- // Should have built-in servers
102
- expect(servers.some((s) => s.id === "typescript")).toBe(true);
103
- });
104
- it("should register custom servers from config", async () => {
105
- const config = {
106
- servers: {
107
- "custom-test-server": {
108
- name: "Custom Test Server",
109
- extensions: [".ctest"],
110
- command: "ctest-lsp",
111
- },
112
- },
113
- };
114
- mockReadFile.mockResolvedValue(JSON.stringify(config));
115
- await initLSPConfig("/project");
116
- const servers = getAllServers();
117
- expect(servers.some((s) => s.id === "custom-test-server")).toBe(true);
118
- });
119
- it("should handle disabled servers", async () => {
120
- const config = {
121
- disabledServers: ["python"],
122
- };
123
- mockReadFile.mockResolvedValue(JSON.stringify(config));
124
- await initLSPConfig("/project");
125
- expect(isServerDisabled("python")).toBe(true);
126
- expect(isServerDisabled("typescript")).toBe(false);
127
- });
128
- });
129
- describe("getAllServers", () => {
130
- beforeEach(async () => {
131
- vi.clearAllMocks();
132
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
133
- await initLSPConfig("/test");
134
- });
135
- it("should include built-in servers", () => {
136
- const servers = getAllServers();
137
- expect(servers.some((s) => s.id === "typescript")).toBe(true);
138
- expect(servers.some((s) => s.id === "python")).toBe(true);
139
- expect(servers.some((s) => s.id === "go")).toBe(true);
140
- expect(servers.some((s) => s.id === "rust")).toBe(true);
141
- });
142
- });
143
- describe("getServersForFileWithConfig", () => {
144
- beforeEach(async () => {
145
- vi.clearAllMocks();
146
- mockReadFile.mockRejectedValue(new Error("ENOENT"));
147
- await initLSPConfig("/test");
148
- });
149
- it("should find TypeScript server for .ts files", () => {
150
- const servers = getServersForFileWithConfig("/project/file.ts");
151
- expect(servers.some((s) => s.id === "typescript")).toBe(true);
152
- });
153
- it("should find Python server for .py files", () => {
154
- const servers = getServersForFileWithConfig("/project/file.py");
155
- expect(servers.some((s) => s.id === "python")).toBe(true);
156
- });
157
- it("should return empty array for unknown file type", () => {
158
- const servers = getServersForFileWithConfig("/project/file.unknown");
159
- expect(servers).toEqual([]);
160
- });
161
- it("should be case insensitive for extensions", () => {
162
- const servers1 = getServersForFileWithConfig("/project/file.TS");
163
- const servers2 = getServersForFileWithConfig("/project/file.ts");
164
- expect(servers1.map((s) => s.id)).toEqual(servers2.map((s) => s.id));
165
- });
166
- });