pi-lens 2.2.9 → 3.0.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 (304) hide show
  1. package/CHANGELOG.md +198 -0
  2. package/README.md +709 -519
  3. package/clients/__tests__/file-time.test.js +216 -0
  4. package/clients/__tests__/file-time.test.ts +276 -0
  5. package/clients/__tests__/format-service.test.js +245 -0
  6. package/clients/__tests__/format-service.test.ts +339 -0
  7. package/clients/__tests__/formatters.test.js +271 -0
  8. package/clients/__tests__/formatters.test.ts +401 -0
  9. package/clients/amain-types.js +164 -0
  10. package/clients/amain-types.ts +165 -0
  11. package/clients/architect-client.js +56 -12
  12. package/clients/architect-client.ts +81 -16
  13. package/clients/ast-grep-client.js +2 -2
  14. package/clients/ast-grep-client.ts +14 -39
  15. package/clients/ast-grep-parser.ts +1 -1
  16. package/clients/ast-grep-rule-manager.js +8 -0
  17. package/clients/ast-grep-rule-manager.ts +10 -1
  18. package/clients/ast-grep-types.js +9 -0
  19. package/clients/ast-grep-types.ts +106 -0
  20. package/clients/auto-loop.js +10 -0
  21. package/clients/auto-loop.ts +14 -1
  22. package/clients/biome-client.js +81 -19
  23. package/clients/biome-client.ts +103 -22
  24. package/clients/bus/bus.js +191 -0
  25. package/clients/bus/bus.ts +251 -0
  26. package/clients/bus/events.js +214 -0
  27. package/clients/bus/events.ts +279 -0
  28. package/clients/bus/index.js +8 -0
  29. package/clients/bus/index.ts +9 -0
  30. package/clients/bus/integration.js +158 -0
  31. package/clients/bus/integration.ts +214 -0
  32. package/clients/complexity-client.js +13 -7
  33. package/clients/complexity-client.ts +13 -7
  34. package/clients/config-validator.js +465 -0
  35. package/clients/config-validator.ts +558 -0
  36. package/clients/dependency-checker.js +4 -10
  37. package/clients/dependency-checker.ts +4 -10
  38. package/clients/dispatch/__tests__/autofix-integration.test.js +245 -0
  39. package/clients/dispatch/__tests__/autofix-integration.test.ts +300 -0
  40. package/clients/dispatch/__tests__/runner-registration.test.js +236 -0
  41. package/clients/dispatch/__tests__/runner-registration.test.ts +282 -0
  42. package/clients/dispatch/bus-dispatcher.js +177 -0
  43. package/clients/dispatch/bus-dispatcher.ts +251 -0
  44. package/clients/dispatch/dispatcher.edge.test.js +82 -0
  45. package/clients/dispatch/dispatcher.edge.test.ts +100 -0
  46. package/clients/dispatch/dispatcher.format.test.js +46 -0
  47. package/clients/dispatch/dispatcher.format.test.ts +58 -0
  48. package/clients/dispatch/dispatcher.inline.test.js +74 -0
  49. package/clients/dispatch/dispatcher.inline.test.ts +93 -0
  50. package/clients/dispatch/dispatcher.js +19 -53
  51. package/clients/dispatch/dispatcher.ts +20 -67
  52. package/clients/dispatch/plan.js +9 -4
  53. package/clients/dispatch/plan.ts +9 -4
  54. package/clients/dispatch/runners/architect.js +21 -7
  55. package/clients/dispatch/runners/architect.test.js +138 -0
  56. package/clients/dispatch/runners/architect.test.ts +162 -0
  57. package/clients/dispatch/runners/architect.ts +22 -7
  58. package/clients/dispatch/runners/ast-grep-napi.js +462 -0
  59. package/clients/dispatch/runners/ast-grep-napi.test.js +111 -0
  60. package/clients/dispatch/runners/ast-grep-napi.test.ts +133 -0
  61. package/clients/dispatch/runners/ast-grep-napi.ts +506 -0
  62. package/clients/dispatch/runners/ast-grep.js +62 -19
  63. package/clients/dispatch/runners/ast-grep.ts +70 -18
  64. package/clients/dispatch/runners/biome.js +29 -53
  65. package/clients/dispatch/runners/biome.ts +29 -63
  66. package/clients/dispatch/runners/config-validation.js +67 -0
  67. package/clients/dispatch/runners/config-validation.ts +82 -0
  68. package/clients/dispatch/runners/go-vet.js +4 -28
  69. package/clients/dispatch/runners/go-vet.ts +4 -32
  70. package/clients/dispatch/runners/index.js +30 -10
  71. package/clients/dispatch/runners/index.ts +30 -10
  72. package/clients/dispatch/runners/oxlint.js +141 -0
  73. package/clients/dispatch/runners/oxlint.test.js +230 -0
  74. package/clients/dispatch/runners/oxlint.test.ts +303 -0
  75. package/clients/dispatch/runners/oxlint.ts +175 -0
  76. package/clients/dispatch/runners/pyright.js +40 -70
  77. package/clients/dispatch/runners/pyright.test.js +16 -2
  78. package/clients/dispatch/runners/pyright.test.ts +14 -2
  79. package/clients/dispatch/runners/pyright.ts +48 -91
  80. package/clients/dispatch/runners/python-slop.js +97 -0
  81. package/clients/dispatch/runners/python-slop.test.js +203 -0
  82. package/clients/dispatch/runners/python-slop.test.ts +298 -0
  83. package/clients/dispatch/runners/python-slop.ts +124 -0
  84. package/clients/dispatch/runners/ruff.js +18 -71
  85. package/clients/dispatch/runners/ruff.ts +19 -79
  86. package/clients/dispatch/runners/rust-clippy.js +28 -32
  87. package/clients/dispatch/runners/rust-clippy.ts +29 -31
  88. package/clients/dispatch/runners/scan_codebase.test.js +89 -0
  89. package/clients/dispatch/runners/scan_codebase.test.ts +105 -0
  90. package/clients/dispatch/runners/shellcheck.js +147 -0
  91. package/clients/dispatch/runners/shellcheck.test.js +98 -0
  92. package/clients/dispatch/runners/shellcheck.test.ts +129 -0
  93. package/clients/dispatch/runners/shellcheck.ts +188 -0
  94. package/clients/dispatch/runners/similarity.js +230 -0
  95. package/clients/dispatch/runners/similarity.ts +339 -0
  96. package/clients/dispatch/runners/spellcheck.js +106 -0
  97. package/clients/dispatch/runners/spellcheck.test.js +158 -0
  98. package/clients/dispatch/runners/spellcheck.test.ts +214 -0
  99. package/clients/dispatch/runners/spellcheck.ts +136 -0
  100. package/clients/dispatch/runners/tree-sitter.js +107 -0
  101. package/clients/dispatch/runners/tree-sitter.ts +135 -0
  102. package/clients/dispatch/runners/ts-lsp.js +104 -33
  103. package/clients/dispatch/runners/ts-lsp.ts +120 -38
  104. package/clients/dispatch/runners/ts-slop.js +113 -0
  105. package/clients/dispatch/runners/ts-slop.test.js +180 -0
  106. package/clients/dispatch/runners/ts-slop.test.ts +230 -0
  107. package/clients/dispatch/runners/ts-slop.ts +142 -0
  108. package/clients/dispatch/runners/utils/diagnostic-parsers.js +134 -0
  109. package/clients/dispatch/runners/utils/diagnostic-parsers.ts +186 -0
  110. package/clients/dispatch/runners/utils/runner-helpers.js +115 -0
  111. package/clients/dispatch/runners/utils/runner-helpers.ts +167 -0
  112. package/clients/dispatch/runners/utils.js +2 -4
  113. package/clients/dispatch/runners/utils.ts +2 -4
  114. package/clients/dispatch/types.ts +1 -1
  115. package/clients/dispatch/utils/format-utils.js +49 -0
  116. package/clients/dispatch/utils/format-utils.ts +60 -0
  117. package/clients/dogfood.test.js +201 -0
  118. package/clients/dogfood.test.ts +269 -0
  119. package/clients/file-time.js +152 -0
  120. package/clients/file-time.ts +208 -0
  121. package/clients/file-utils.js +40 -0
  122. package/clients/file-utils.ts +44 -0
  123. package/clients/fix-scanners.js +10 -20
  124. package/clients/fix-scanners.ts +10 -22
  125. package/clients/format-service.js +172 -0
  126. package/clients/format-service.ts +254 -0
  127. package/clients/formatters.js +435 -0
  128. package/clients/formatters.ts +508 -0
  129. package/clients/go-client.js +5 -14
  130. package/clients/go-client.ts +5 -13
  131. package/clients/installer/index.js +356 -0
  132. package/clients/installer/index.ts +426 -0
  133. package/clients/jscpd-client.js +11 -9
  134. package/clients/jscpd-client.ts +12 -8
  135. package/clients/knip-client.js +3 -7
  136. package/clients/knip-client.ts +3 -6
  137. package/clients/lsp/__tests__/client.test.js +325 -0
  138. package/clients/lsp/__tests__/client.test.ts +434 -0
  139. package/clients/lsp/__tests__/config.test.js +166 -0
  140. package/clients/lsp/__tests__/config.test.ts +209 -0
  141. package/clients/lsp/__tests__/error-recovery.test.js +213 -0
  142. package/clients/lsp/__tests__/error-recovery.test.ts +279 -0
  143. package/clients/lsp/__tests__/integration.test.js +127 -0
  144. package/clients/lsp/__tests__/integration.test.ts +160 -0
  145. package/clients/lsp/__tests__/launch.test.js +260 -0
  146. package/clients/lsp/__tests__/launch.test.ts +329 -0
  147. package/clients/lsp/__tests__/server.test.js +259 -0
  148. package/clients/lsp/__tests__/server.test.ts +332 -0
  149. package/clients/lsp/__tests__/service.test.js +417 -0
  150. package/clients/lsp/__tests__/service.test.ts +499 -0
  151. package/clients/lsp/client.js +235 -0
  152. package/clients/lsp/client.ts +328 -0
  153. package/clients/lsp/config.js +115 -0
  154. package/clients/lsp/config.ts +149 -0
  155. package/clients/lsp/index.js +222 -0
  156. package/clients/lsp/index.ts +280 -0
  157. package/clients/lsp/installer/index.js +391 -0
  158. package/clients/lsp/interactive-install.js +210 -0
  159. package/clients/lsp/interactive-install.ts +251 -0
  160. package/clients/lsp/language.js +170 -0
  161. package/clients/lsp/language.ts +216 -0
  162. package/clients/lsp/launch.js +174 -0
  163. package/clients/lsp/launch.ts +240 -0
  164. package/clients/lsp/lsp/launch.js +116 -0
  165. package/clients/lsp/lsp/server.js +532 -0
  166. package/clients/lsp/lsp-index.js +10 -0
  167. package/clients/lsp/lsp-index.ts +11 -0
  168. package/clients/lsp/path-utils.js +48 -0
  169. package/clients/lsp/path-utils.ts +52 -0
  170. package/clients/lsp/server.js +615 -0
  171. package/clients/lsp/server.ts +800 -0
  172. package/clients/lsp/test-py-spawn/requirements.txt +1 -0
  173. package/clients/lsp/test-py-spawn/test.py +3 -0
  174. package/clients/lsp/test-py-svc/requirements.txt +1 -0
  175. package/clients/lsp/test-py-svc/test.py +3 -0
  176. package/clients/lsp/test-python-project/requirements.txt +1 -0
  177. package/clients/lsp/test-python-project/test.py +5 -0
  178. package/clients/metrics-history.js +2 -2
  179. package/clients/metrics-history.ts +2 -2
  180. package/clients/production-readiness.js +522 -0
  181. package/clients/production-readiness.ts +556 -0
  182. package/clients/project-index.js +255 -0
  183. package/clients/project-index.ts +383 -0
  184. package/clients/project-metadata.js +531 -0
  185. package/clients/project-metadata.ts +624 -0
  186. package/clients/ruff-client.js +56 -16
  187. package/clients/ruff-client.ts +72 -15
  188. package/clients/runner-tracker.js +152 -0
  189. package/clients/runner-tracker.ts +213 -0
  190. package/clients/rust-client.js +4 -11
  191. package/clients/rust-client.ts +5 -11
  192. package/clients/safe-spawn.js +96 -0
  193. package/clients/safe-spawn.ts +128 -0
  194. package/clients/scan-architectural-debt.js +3 -6
  195. package/clients/scan-architectural-debt.ts +3 -6
  196. package/clients/scan-utils.js +5 -20
  197. package/clients/scan-utils.ts +5 -29
  198. package/clients/secrets-scanner.js +3 -17
  199. package/clients/secrets-scanner.ts +4 -20
  200. package/clients/services/__tests__/effect-integration.test.js +86 -0
  201. package/clients/services/__tests__/effect-integration.test.ts +111 -0
  202. package/clients/services/effect-integration.js +194 -0
  203. package/clients/services/effect-integration.ts +268 -0
  204. package/clients/services/index.js +7 -0
  205. package/clients/services/index.ts +8 -0
  206. package/clients/services/runner-service.js +105 -0
  207. package/clients/services/runner-service.ts +179 -0
  208. package/clients/sg-runner.js +87 -13
  209. package/clients/sg-runner.ts +97 -13
  210. package/clients/state-matrix.js +160 -0
  211. package/clients/state-matrix.ts +202 -0
  212. package/clients/subprocess-client.js +10 -9
  213. package/clients/subprocess-client.ts +10 -8
  214. package/clients/test-runner-client.js +3 -7
  215. package/clients/test-runner-client.ts +3 -6
  216. package/clients/tool-availability.js +4 -10
  217. package/clients/tool-availability.ts +4 -9
  218. package/clients/tree-sitter-client.js +564 -0
  219. package/clients/tree-sitter-client.ts +797 -0
  220. package/clients/tree-sitter-query-loader.js +355 -0
  221. package/clients/tree-sitter-query-loader.ts +425 -0
  222. package/clients/type-coverage-client.js +3 -7
  223. package/clients/type-coverage-client.ts +3 -6
  224. package/clients/typescript-client.codefix.test.js +157 -0
  225. package/clients/typescript-client.codefix.test.ts +186 -0
  226. package/clients/typescript-client.js +43 -0
  227. package/clients/typescript-client.ts +98 -0
  228. package/commands/booboo.js +799 -219
  229. package/commands/booboo.ts +1004 -225
  230. package/commands/clients/ast-grep-client.js +250 -0
  231. package/commands/clients/ast-grep-parser.js +86 -0
  232. package/commands/clients/ast-grep-rule-manager.js +91 -0
  233. package/commands/clients/ast-grep-types.js +9 -0
  234. package/commands/clients/biome-client.js +380 -0
  235. package/commands/clients/complexity-client.js +667 -0
  236. package/commands/clients/file-kinds.js +177 -0
  237. package/commands/clients/file-utils.js +40 -0
  238. package/commands/clients/jscpd-client.js +169 -0
  239. package/commands/clients/knip-client.js +211 -0
  240. package/commands/clients/ruff-client.js +297 -0
  241. package/commands/clients/safe-spawn.js +88 -0
  242. package/commands/clients/scan-utils.js +83 -0
  243. package/commands/clients/sg-runner.js +190 -0
  244. package/commands/clients/types.js +11 -0
  245. package/commands/clients/typescript-client.js +505 -0
  246. package/commands/fix-from-booboo.js +398 -0
  247. package/commands/fix-from-booboo.ts +485 -0
  248. package/commands/fix-simplified.js +618 -0
  249. package/commands/fix-simplified.ts +768 -0
  250. package/commands/rate.js +10 -14
  251. package/commands/rate.ts +9 -16
  252. package/default-architect.yaml +59 -15
  253. package/index.ts +342 -429
  254. package/package.json +16 -3
  255. package/rules/ast-grep-rules/rules/empty-catch.yml +38 -13
  256. package/rules/ast-grep-rules/rules/no-array-constructor.yml +1 -0
  257. package/rules/ast-grep-rules/rules/no-debugger.yml +2 -0
  258. package/rules/python-slop-rules/.sgconfig.yml +4 -0
  259. package/rules/python-slop-rules/rules/slop-rules.yml +647 -0
  260. package/rules/tree-sitter-queries/python/bare-except.yml +54 -0
  261. package/rules/tree-sitter-queries/python/eval-exec.yml +50 -0
  262. package/rules/tree-sitter-queries/python/is-vs-equals.yml +60 -0
  263. package/rules/tree-sitter-queries/python/mutable-default-arg.yml +57 -0
  264. package/rules/tree-sitter-queries/python/unreachable-except.yml +60 -0
  265. package/rules/tree-sitter-queries/python/wildcard-import.yml +46 -0
  266. package/rules/tree-sitter-queries/tsx/dangerously-set-inner-html.yml +63 -0
  267. package/rules/tree-sitter-queries/typescript/await-in-loop.yml +56 -0
  268. package/rules/tree-sitter-queries/typescript/console-statement.yml +47 -0
  269. package/rules/tree-sitter-queries/typescript/debugger.yml +47 -0
  270. package/rules/tree-sitter-queries/typescript/deep-nesting.yml +117 -0
  271. package/rules/tree-sitter-queries/typescript/deep-promise-chain.yml +73 -0
  272. package/rules/tree-sitter-queries/typescript/empty-catch.yml +64 -0
  273. package/rules/tree-sitter-queries/typescript/eval.yml +48 -0
  274. package/rules/tree-sitter-queries/typescript/hardcoded-secrets.yml +78 -0
  275. package/rules/tree-sitter-queries/typescript/long-parameter-list.yml +62 -0
  276. package/rules/tree-sitter-queries/typescript/mixed-async-styles.yml +49 -0
  277. package/rules/tree-sitter-queries/typescript/nested-ternary.yml +45 -0
  278. package/rules/ts-slop-rules/.sgconfig.yml +4 -0
  279. package/rules/ts-slop-rules/rules/in-correct-optional-input-type.yml +10 -0
  280. package/rules/ts-slop-rules/rules/jwt-no-verify.yml +13 -0
  281. package/rules/ts-slop-rules/rules/no-architecture-violation.yml +10 -0
  282. package/rules/ts-slop-rules/rules/no-case-declarations.yml +10 -0
  283. package/rules/ts-slop-rules/rules/no-dangerously-set-inner-html.yml +10 -0
  284. package/rules/ts-slop-rules/rules/no-debugger.yml +10 -0
  285. package/rules/ts-slop-rules/rules/no-dupe-args.yml +10 -0
  286. package/rules/ts-slop-rules/rules/no-dupe-class-members.yml +10 -0
  287. package/rules/ts-slop-rules/rules/no-dupe-keys.yml +10 -0
  288. package/rules/ts-slop-rules/rules/no-eval.yml +13 -0
  289. package/rules/ts-slop-rules/rules/no-hardcoded-secrets.yml +12 -0
  290. package/rules/ts-slop-rules/rules/no-implied-eval.yml +12 -0
  291. package/rules/ts-slop-rules/rules/no-inner-html.yml +13 -0
  292. package/rules/ts-slop-rules/rules/no-javascript-url.yml +10 -0
  293. package/rules/ts-slop-rules/rules/no-mutable-default.yml +10 -0
  294. package/rules/ts-slop-rules/rules/no-nested-links.yml +12 -0
  295. package/rules/ts-slop-rules/rules/no-new-symbol.yml +10 -0
  296. package/rules/ts-slop-rules/rules/no-new-wrappers.yml +13 -0
  297. package/rules/ts-slop-rules/rules/no-open-redirect.yml +16 -0
  298. package/rules/ts-slop-rules/rules/slop-rules.yml +455 -0
  299. package/rules/ts-slop-rules/rules/weak-rsa-key.yml +12 -0
  300. package/skills/ast-grep/SKILL.md +182 -0
  301. package/clients/dispatch/runners/secrets.js +0 -109
  302. package/commands/fix.js +0 -244
  303. package/commands/fix.ts +0 -373
  304. package/rules/ast-grep-rules/rules/no-lonely-if.yml +0 -13
@@ -0,0 +1,800 @@
1
+ /**
2
+ * LSP Server Definitions for pi-lens
3
+ *
4
+ * Defines 40+ language servers with:
5
+ * - Root detection (monorepo support)
6
+ * - Auto-installation strategies
7
+ * - Platform-specific handling
8
+ */
9
+
10
+ import path from "node:path";
11
+ import { ensureTool, getToolEnvironment } from "../installer/index.js";
12
+ import {
13
+ promptForInstall,
14
+ supportsInteractiveInstall,
15
+ } from "./interactive-install.js";
16
+ import {
17
+ type LSPProcess,
18
+ launchLSP,
19
+ launchViaPackageManager,
20
+ } from "./launch.js";
21
+
22
+ // --- Types ---
23
+
24
+ export type RootFunction = (file: string) => Promise<string | undefined>;
25
+
26
+ export interface LSPServerInfo {
27
+ id: string;
28
+ name: string;
29
+ extensions: string[];
30
+ root: RootFunction;
31
+ spawn(
32
+ root: string,
33
+ ): Promise<
34
+ | { process: LSPProcess; initialization?: Record<string, unknown> }
35
+ | undefined
36
+ >;
37
+ autoInstall?: () => Promise<boolean>;
38
+ }
39
+
40
+ // --- Root Detection Helpers ---
41
+
42
+ import { dirname } from "node:path";
43
+ import { fileURLToPath } from "node:url";
44
+
45
+ const __filename = fileURLToPath(import.meta.url);
46
+ const __dirname = dirname(__filename);
47
+
48
+ // --- Interactive Install Helper ---
49
+
50
+ /**
51
+ * Spawn LSP with interactive install support for common languages
52
+ *
53
+ * For Go, Rust, YAML, JSON, Bash: prompts user to install if tool not found
54
+ * Other languages: throws error with install instructions
55
+ */
56
+ async function spawnWithInteractiveInstall(
57
+ language: string,
58
+ _command: string,
59
+ _args: string[],
60
+ options: { cwd: string },
61
+ spawnFn: () => LSPProcess,
62
+ ): Promise<LSPProcess | undefined> {
63
+ try {
64
+ return spawnFn();
65
+ } catch (error) {
66
+ // Check if this is a "command not found" error
67
+ const errorMsg = String(error);
68
+ if (!errorMsg.includes("not found") && !errorMsg.includes("ENOENT")) {
69
+ throw error; // Re-throw if it's a different error
70
+ }
71
+
72
+ // Check if language supports interactive install
73
+ if (supportsInteractiveInstall(language)) {
74
+ const shouldInstall = await promptForInstall(language, options.cwd);
75
+ if (shouldInstall) {
76
+ // Try again after install
77
+ return spawnFn();
78
+ }
79
+ // User declined, return undefined to skip this LSP
80
+ return undefined;
81
+ }
82
+
83
+ // For other languages, throw with install instructions
84
+ throw error;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Walk up the tree looking for project root markers
90
+ */
91
+ export function createRootDetector(
92
+ includePatterns: string[],
93
+ excludePatterns?: string[],
94
+ ): RootFunction {
95
+ return async (file: string): Promise<string | undefined> => {
96
+ let currentDir = path.dirname(file);
97
+ const root = path.parse(currentDir).root;
98
+
99
+ while (currentDir !== root) {
100
+ // Check exclude patterns first
101
+ if (excludePatterns) {
102
+ for (const pattern of excludePatterns) {
103
+ const checkPath = path.join(currentDir, pattern);
104
+ try {
105
+ const stat = await import("node:fs/promises").then((fs) =>
106
+ fs.stat(checkPath),
107
+ );
108
+ if (stat) return undefined; // Excluded
109
+ } catch {
110
+ /* not found */
111
+ }
112
+ }
113
+ }
114
+
115
+ // Check include patterns
116
+ for (const pattern of includePatterns) {
117
+ const checkPath = path.join(currentDir, pattern);
118
+ try {
119
+ const stat = await import("node:fs/promises").then((fs) =>
120
+ fs.stat(checkPath),
121
+ );
122
+ if (stat) return currentDir;
123
+ } catch {
124
+ /* not found */
125
+ }
126
+ }
127
+
128
+ currentDir = path.dirname(currentDir);
129
+ }
130
+
131
+ return undefined;
132
+ };
133
+ }
134
+
135
+ // --- Server Definitions ---
136
+
137
+ export const TypeScriptServer: LSPServerInfo = {
138
+ id: "typescript",
139
+ name: "TypeScript Language Server",
140
+ extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"],
141
+ root: createRootDetector(
142
+ [
143
+ "package-lock.json",
144
+ "bun.lockb",
145
+ "bun.lock",
146
+ "pnpm-lock.yaml",
147
+ "yarn.lock",
148
+ "package.json",
149
+ ],
150
+ [".pi-lens"],
151
+ ),
152
+ async spawn(root) {
153
+ const path = await import("node:path");
154
+ const fs = await import("node:fs/promises");
155
+
156
+ // Find typescript-language-server - prefer local project version
157
+ let lspPath: string | undefined;
158
+ const localLsp = path.join(
159
+ root,
160
+ "node_modules",
161
+ ".bin",
162
+ "typescript-language-server",
163
+ );
164
+ const localLspCmd = path.join(
165
+ root,
166
+ "node_modules",
167
+ ".bin",
168
+ "typescript-language-server.cmd",
169
+ );
170
+
171
+ // Check for local version first (Windows .cmd first, then Unix)
172
+ for (const checkPath of [localLspCmd, localLsp]) {
173
+ try {
174
+ await fs.access(checkPath);
175
+ lspPath = checkPath;
176
+ break;
177
+ } catch {
178
+ /* not found */
179
+ }
180
+ }
181
+
182
+ // Fall back to auto-installed version
183
+ if (!lspPath) {
184
+ lspPath = await ensureTool("typescript-language-server");
185
+ if (!lspPath) {
186
+ console.error("[lsp] typescript-language-server not found");
187
+ return undefined;
188
+ }
189
+ }
190
+
191
+ // Find tsserver.js path (needed for TypeScript LSP initialization)
192
+ // Check relative to the LSP path first, then project root
193
+ let tsserverPath: string | undefined;
194
+ const tsserverCandidates = [
195
+ // Relative to LSP binary (for locally installed)
196
+ path.join(
197
+ path.dirname(lspPath),
198
+ "..",
199
+ "typescript",
200
+ "lib",
201
+ "tsserver.js",
202
+ ),
203
+ // Project root
204
+ path.join(root, "node_modules", "typescript", "lib", "tsserver.js"),
205
+ // Current working directory
206
+ path.join(
207
+ process.cwd(),
208
+ "node_modules",
209
+ "typescript",
210
+ "lib",
211
+ "tsserver.js",
212
+ ),
213
+ ];
214
+
215
+ for (const checkPath of tsserverCandidates) {
216
+ try {
217
+ await fs.access(checkPath);
218
+ tsserverPath = checkPath;
219
+ break;
220
+ } catch {
221
+ /* not found */
222
+ }
223
+ }
224
+
225
+ // Use absolute path and proper environment
226
+ const env = await getToolEnvironment();
227
+ const proc = launchLSP(lspPath, ["--stdio"], {
228
+ cwd: root,
229
+ env: {
230
+ ...env,
231
+ TSSERVER_PATH: tsserverPath,
232
+ },
233
+ });
234
+
235
+ return {
236
+ process: proc,
237
+ initialization: tsserverPath
238
+ ? { tsserver: { path: tsserverPath } }
239
+ : undefined,
240
+ };
241
+ },
242
+ };
243
+
244
+ export const PythonServer: LSPServerInfo = {
245
+ id: "python",
246
+ name: "Pyright Language Server",
247
+ extensions: [".py", ".pyi"],
248
+ root: createRootDetector(
249
+ [
250
+ "pyproject.toml",
251
+ "setup.py",
252
+ "setup.cfg",
253
+ "requirements.txt",
254
+ "Pipfile",
255
+ "poetry.lock",
256
+ ],
257
+ [".pi-lens"],
258
+ ),
259
+ async spawn(root) {
260
+ const env = await getToolEnvironment();
261
+ const proc = launchViaPackageManager("pyright-langserver", ["--stdio"], {
262
+ cwd: root,
263
+ env,
264
+ });
265
+
266
+ // Detect virtual environment
267
+ const initialization: Record<string, unknown> = {};
268
+ const venvPaths = [
269
+ path.join(root, ".venv"),
270
+ path.join(root, "venv"),
271
+ process.env.VIRTUAL_ENV,
272
+ ].filter(Boolean);
273
+
274
+ for (const venv of venvPaths) {
275
+ if (!venv) continue;
276
+ try {
277
+ const pythonPath =
278
+ process.platform === "win32"
279
+ ? path.join(venv, "Scripts", "python.exe")
280
+ : path.join(venv, "bin", "python");
281
+
282
+ await import("node:fs/promises").then((fs) => fs.access(pythonPath));
283
+ // Pyright expects pythonPath at top level, not nested
284
+ initialization.pythonPath = pythonPath;
285
+ break;
286
+ } catch {
287
+ /* not found */
288
+ }
289
+ }
290
+
291
+ return { process: proc, initialization };
292
+ },
293
+ };
294
+
295
+ export const GoServer: LSPServerInfo = {
296
+ id: "go",
297
+ name: "gopls",
298
+ extensions: [".go"],
299
+ root: createRootDetector(["go.mod", "go.sum"], [".pi-lens"]),
300
+ async spawn(root) {
301
+ const proc = await spawnWithInteractiveInstall(
302
+ "go",
303
+ "gopls",
304
+ [],
305
+ { cwd: root },
306
+ () => launchLSP("gopls", [], { cwd: root }),
307
+ );
308
+ return proc ? { process: proc } : undefined;
309
+ },
310
+ };
311
+
312
+ export const RustServer: LSPServerInfo = {
313
+ id: "rust",
314
+ name: "rust-analyzer",
315
+ extensions: [".rs"],
316
+ root: createRootDetector(["Cargo.toml", "Cargo.lock"], [".pi-lens"]),
317
+ async spawn(root) {
318
+ const proc = await spawnWithInteractiveInstall(
319
+ "rust",
320
+ "rust-analyzer",
321
+ [],
322
+ { cwd: root },
323
+ () => launchLSP("rust-analyzer", [], { cwd: root }),
324
+ );
325
+ return proc ? { process: proc } : undefined;
326
+ },
327
+ };
328
+
329
+ export const RubyServer: LSPServerInfo = {
330
+ id: "ruby",
331
+ name: "Ruby LSP",
332
+ extensions: [".rb", ".rake", ".gemspec", ".ru"],
333
+ root: createRootDetector(["Gemfile", ".ruby-version"], [".pi-lens"]),
334
+ async spawn(root) {
335
+ // Try ruby-lsp first, fall back to solargraph
336
+ try {
337
+ const proc = launchLSP("ruby-lsp", [], { cwd: root });
338
+ return { process: proc };
339
+ } catch {
340
+ const proc = launchViaPackageManager("solargraph", ["stdio"], {
341
+ cwd: root,
342
+ });
343
+ return { process: proc };
344
+ }
345
+ },
346
+ };
347
+
348
+ export const PHPServer: LSPServerInfo = {
349
+ id: "php",
350
+ name: "Intelephense",
351
+ extensions: [".php"],
352
+ root: createRootDetector(["composer.json", "composer.lock"], [".pi-lens"]),
353
+ async spawn(root) {
354
+ const proc = launchViaPackageManager("intelephense", ["--stdio"], {
355
+ cwd: root,
356
+ });
357
+ return {
358
+ process: proc,
359
+ initialization: { storagePath: path.join(__dirname, ".intelephense") },
360
+ };
361
+ },
362
+ };
363
+
364
+ export const CSharpServer: LSPServerInfo = {
365
+ id: "csharp",
366
+ name: "csharp-ls",
367
+ extensions: [".cs"],
368
+ root: createRootDetector([".sln", ".csproj", ".slnx"], [".pi-lens"]),
369
+ async spawn(root) {
370
+ const proc = launchLSP("csharp-ls", [], { cwd: root });
371
+ return { process: proc };
372
+ },
373
+ };
374
+
375
+ export const FSharpServer: LSPServerInfo = {
376
+ id: "fsharp",
377
+ name: "FSAutocomplete",
378
+ extensions: [".fs", ".fsi", ".fsx"],
379
+ root: createRootDetector([".sln", ".fsproj"], [".pi-lens"]),
380
+ async spawn(root) {
381
+ const proc = launchLSP("fsautocomplete", [], { cwd: root });
382
+ return { process: proc };
383
+ },
384
+ };
385
+
386
+ export const JavaServer: LSPServerInfo = {
387
+ id: "java",
388
+ name: "JDT Language Server",
389
+ extensions: [".java"],
390
+ root: createRootDetector(
391
+ ["pom.xml", "build.gradle", ".classpath"],
392
+ [".pi-lens"],
393
+ ),
394
+ async spawn(root) {
395
+ // JDTLS requires special handling - paths to launcher jar
396
+ const jdtlsPath = process.env.JDTLS_PATH || "jdtls";
397
+ const proc = launchLSP(jdtlsPath, [], { cwd: root });
398
+ return { process: proc };
399
+ },
400
+ };
401
+
402
+ export const KotlinServer: LSPServerInfo = {
403
+ id: "kotlin",
404
+ name: "Kotlin Language Server",
405
+ extensions: [".kt", ".kts"],
406
+ root: createRootDetector(
407
+ ["build.gradle.kts", "build.gradle", "pom.xml"],
408
+ [".pi-lens"],
409
+ ),
410
+ async spawn(root) {
411
+ const proc = launchLSP("kotlin-language-server", [], { cwd: root });
412
+ return { process: proc };
413
+ },
414
+ };
415
+
416
+ export const SwiftServer: LSPServerInfo = {
417
+ id: "swift",
418
+ name: "SourceKit-LSP",
419
+ extensions: [".swift"],
420
+ root: createRootDetector(["Package.swift"], [".pi-lens"]),
421
+ async spawn(root) {
422
+ const proc = launchLSP("sourcekit-lsp", [], { cwd: root });
423
+ return { process: proc };
424
+ },
425
+ };
426
+
427
+ export const DartServer: LSPServerInfo = {
428
+ id: "dart",
429
+ name: "Dart Analysis Server",
430
+ extensions: [".dart"],
431
+ root: createRootDetector(["pubspec.yaml"], [".pi-lens"]),
432
+ async spawn(root) {
433
+ const proc = launchLSP("dart", ["language-server", "--protocol=lsp"], {
434
+ cwd: root,
435
+ });
436
+ return { process: proc };
437
+ },
438
+ };
439
+
440
+ export const LuaServer: LSPServerInfo = {
441
+ id: "lua",
442
+ name: "Lua Language Server",
443
+ extensions: [".lua"],
444
+ root: createRootDetector([".luarc.json", ".luacheckrc"], [".pi-lens"]),
445
+ async spawn(root) {
446
+ const proc = launchLSP("lua-language-server", [], { cwd: root });
447
+ return { process: proc };
448
+ },
449
+ };
450
+
451
+ export const CppServer: LSPServerInfo = {
452
+ id: "cpp",
453
+ name: "clangd",
454
+ extensions: [".c", ".cpp", ".cc", ".cxx", ".h", ".hpp"],
455
+ root: createRootDetector([
456
+ "compile_commands.json",
457
+ ".clangd",
458
+ "CMakeLists.txt",
459
+ "Makefile",
460
+ ]),
461
+ async spawn(root) {
462
+ const proc = launchLSP("clangd", ["--background-index"], { cwd: root });
463
+ return { process: proc };
464
+ },
465
+ };
466
+
467
+ export const ZigServer: LSPServerInfo = {
468
+ id: "zig",
469
+ name: "ZLS",
470
+ extensions: [".zig", ".zon"],
471
+ root: createRootDetector(["build.zig"], [".pi-lens"]),
472
+ async spawn(root) {
473
+ const proc = launchLSP("zls", [], { cwd: root });
474
+ return { process: proc };
475
+ },
476
+ };
477
+
478
+ export const HaskellServer: LSPServerInfo = {
479
+ id: "haskell",
480
+ name: "Haskell Language Server",
481
+ extensions: [".hs", ".lhs"],
482
+ root: createRootDetector(
483
+ ["stack.yaml", "cabal.project", "*.cabal"],
484
+ [".pi-lens"],
485
+ ),
486
+ async spawn(root) {
487
+ const proc = launchLSP("haskell-language-server-wrapper", ["--lsp"], {
488
+ cwd: root,
489
+ });
490
+ return { process: proc };
491
+ },
492
+ };
493
+
494
+ export const ElixirServer: LSPServerInfo = {
495
+ id: "elixir",
496
+ name: "ElixirLS",
497
+ extensions: [".ex", ".exs"],
498
+ root: createRootDetector(["mix.exs"], [".pi-lens"]),
499
+ async spawn(root) {
500
+ const proc = launchLSP("elixir-ls", [], { cwd: root });
501
+ return { process: proc };
502
+ },
503
+ };
504
+
505
+ export const GleamServer: LSPServerInfo = {
506
+ id: "gleam",
507
+ name: "Gleam LSP",
508
+ extensions: [".gleam"],
509
+ root: createRootDetector(["gleam.toml"], [".pi-lens"]),
510
+ async spawn(root) {
511
+ const proc = launchLSP("gleam", ["lsp"], { cwd: root });
512
+ return { process: proc };
513
+ },
514
+ };
515
+
516
+ export const OCamlServer: LSPServerInfo = {
517
+ id: "ocaml",
518
+ name: "ocamllsp",
519
+ extensions: [".ml", ".mli"],
520
+ root: createRootDetector(["dune-project", "opam"], [".pi-lens"]),
521
+ async spawn(root) {
522
+ const proc = launchLSP("ocamllsp", [], { cwd: root });
523
+ return { process: proc };
524
+ },
525
+ };
526
+
527
+ export const ClojureServer: LSPServerInfo = {
528
+ id: "clojure",
529
+ name: "Clojure LSP",
530
+ extensions: [".clj", ".cljs", ".cljc", ".edn"],
531
+ root: createRootDetector(["deps.edn", "project.clj"], [".pi-lens"]),
532
+ async spawn(root) {
533
+ const proc = launchLSP("clojure-lsp", [], { cwd: root });
534
+ return { process: proc };
535
+ },
536
+ };
537
+
538
+ export const TerraformServer: LSPServerInfo = {
539
+ id: "terraform",
540
+ name: "Terraform LSP",
541
+ extensions: [".tf", ".tfvars"],
542
+ root: createRootDetector([".terraform.lock.hcl"], [".pi-lens"]),
543
+ async spawn(root) {
544
+ const proc = launchLSP("terraform-ls", ["serve"], { cwd: root });
545
+ return { process: proc };
546
+ },
547
+ };
548
+
549
+ export const NixServer: LSPServerInfo = {
550
+ id: "nix",
551
+ name: "nixd",
552
+ extensions: [".nix"],
553
+ root: createRootDetector(["flake.nix"], [".pi-lens"]),
554
+ async spawn(root) {
555
+ const proc = launchLSP("nixd", [], { cwd: root });
556
+ return { process: proc };
557
+ },
558
+ };
559
+
560
+ export const BashServer: LSPServerInfo = {
561
+ id: "bash",
562
+ name: "Bash Language Server",
563
+ extensions: [".sh", ".bash", ".zsh"],
564
+ root: async () => process.cwd(),
565
+ async spawn() {
566
+ const cwd = process.cwd();
567
+ const proc = await spawnWithInteractiveInstall(
568
+ "bash",
569
+ "bash-language-server",
570
+ ["start"],
571
+ { cwd },
572
+ () => launchLSP("bash-language-server", ["start"], {}),
573
+ );
574
+ return proc ? { process: proc } : undefined;
575
+ },
576
+ };
577
+
578
+ export const DockerServer: LSPServerInfo = {
579
+ id: "docker",
580
+ name: "Dockerfile Language Server",
581
+ extensions: [".dockerfile", "Dockerfile"],
582
+ root: async () => process.cwd(),
583
+ async spawn() {
584
+ // Use npx since it's not auto-installed
585
+ const proc = launchViaPackageManager(
586
+ "dockerfile-language-server-nodejs",
587
+ ["--stdio"],
588
+ {},
589
+ );
590
+ return { process: proc };
591
+ },
592
+ };
593
+
594
+ export const YamlServer: LSPServerInfo = {
595
+ id: "yaml",
596
+ name: "YAML Language Server",
597
+ extensions: [".yaml", ".yml"],
598
+ root: async () => process.cwd(),
599
+ async spawn() {
600
+ const cwd = process.cwd();
601
+ const proc = await spawnWithInteractiveInstall(
602
+ "yaml",
603
+ "yaml-language-server",
604
+ ["--stdio"],
605
+ { cwd },
606
+ () => launchLSP("yaml-language-server", ["--stdio"], {}),
607
+ );
608
+ return proc ? { process: proc } : undefined;
609
+ },
610
+ };
611
+
612
+ export const JsonServer: LSPServerInfo = {
613
+ id: "json",
614
+ name: "VSCode JSON Language Server",
615
+ extensions: [".json", ".jsonc"],
616
+ root: async () => process.cwd(),
617
+ async spawn() {
618
+ const cwd = process.cwd();
619
+ const proc = await spawnWithInteractiveInstall(
620
+ "json",
621
+ "vscode-json-languageserver",
622
+ ["--stdio"],
623
+ { cwd },
624
+ () => launchLSP("vscode-json-languageserver", ["--stdio"], {}),
625
+ );
626
+ return proc ? { process: proc } : undefined;
627
+ },
628
+ };
629
+
630
+ export const PrismaServer: LSPServerInfo = {
631
+ id: "prisma",
632
+ name: "Prisma Language Server",
633
+ extensions: [".prisma"],
634
+ root: createRootDetector(["prisma/schema.prisma"], [".pi-lens"]),
635
+ async spawn(root) {
636
+ // Use npx since it's not auto-installed
637
+ const proc = launchViaPackageManager(
638
+ "@prisma/language-server",
639
+ ["--stdio"],
640
+ { cwd: root },
641
+ );
642
+ return { process: proc };
643
+ },
644
+ };
645
+
646
+ // --- Web Framework & Styling Servers ---
647
+
648
+ export const VueServer: LSPServerInfo = {
649
+ id: "vue",
650
+ name: "Vue Language Server",
651
+ extensions: [".vue"],
652
+ root: createRootDetector(
653
+ [
654
+ "package-lock.json",
655
+ "bun.lockb",
656
+ "bun.lock",
657
+ "pnpm-lock.yaml",
658
+ "yarn.lock",
659
+ ],
660
+ [".pi-lens"],
661
+ ),
662
+ async spawn(root) {
663
+ // Use npx since it's not auto-installed
664
+ const proc = launchViaPackageManager("@vue/language-server", ["--stdio"], {
665
+ cwd: root,
666
+ });
667
+ return { process: proc };
668
+ },
669
+ };
670
+
671
+ export const SvelteServer: LSPServerInfo = {
672
+ id: "svelte",
673
+ name: "Svelte Language Server",
674
+ extensions: [".svelte"],
675
+ root: createRootDetector(
676
+ [
677
+ "package-lock.json",
678
+ "bun.lockb",
679
+ "bun.lock",
680
+ "pnpm-lock.yaml",
681
+ "yarn.lock",
682
+ ],
683
+ [".pi-lens"],
684
+ ),
685
+ async spawn(root) {
686
+ // Use npx since it's not auto-installed
687
+ const proc = launchViaPackageManager(
688
+ "svelte-language-server",
689
+ ["--stdio"],
690
+ { cwd: root },
691
+ );
692
+ return { process: proc };
693
+ },
694
+ };
695
+
696
+ export const ESLintServer: LSPServerInfo = {
697
+ id: "eslint",
698
+ name: "ESLint Language Server",
699
+ extensions: [".js", ".jsx", ".vue", ".svelte"], // Note: .ts/.tsx handled by TypeScript LSP + Biome
700
+ root: createRootDetector([
701
+ ".eslintrc",
702
+ ".eslintrc.json",
703
+ ".eslintrc.js",
704
+ "eslint.config.js",
705
+ "eslint.config.mjs",
706
+ "package.json",
707
+ ]),
708
+ async spawn(root) {
709
+ // Try via package manager (npx) since it's not auto-installed
710
+ try {
711
+ const proc = launchViaPackageManager(
712
+ "vscode-eslint-language-server",
713
+ ["--stdio"],
714
+ { cwd: root },
715
+ );
716
+ return { process: proc };
717
+ } catch {
718
+ // Fall back to global install message
719
+ console.error(
720
+ "[lsp] ESLint Language Server not found. Install: npm install -g vscode-langservers-extracted",
721
+ );
722
+ return undefined;
723
+ }
724
+ },
725
+ };
726
+
727
+ export const CssServer: LSPServerInfo = {
728
+ id: "css",
729
+ name: "CSS Language Server",
730
+ extensions: [".css", ".scss", ".sass", ".less"],
731
+ root: async () => process.cwd(),
732
+ async spawn() {
733
+ // Use npx since it's not auto-installed
734
+ const proc = launchViaPackageManager(
735
+ "vscode-css-languageserver",
736
+ ["--stdio"],
737
+ {},
738
+ );
739
+ return { process: proc };
740
+ },
741
+ };
742
+
743
+ // --- Registry ---
744
+
745
+ export const LSP_SERVERS: LSPServerInfo[] = [
746
+ TypeScriptServer,
747
+ PythonServer,
748
+ GoServer,
749
+ RustServer,
750
+ RubyServer,
751
+ PHPServer,
752
+ CSharpServer,
753
+ FSharpServer,
754
+ JavaServer,
755
+ KotlinServer,
756
+ SwiftServer,
757
+ DartServer,
758
+ LuaServer,
759
+ CppServer,
760
+ ZigServer,
761
+ HaskellServer,
762
+ ElixirServer,
763
+ GleamServer,
764
+ OCamlServer,
765
+ ClojureServer,
766
+ TerraformServer,
767
+ NixServer,
768
+ BashServer,
769
+ DockerServer,
770
+ YamlServer,
771
+ JsonServer,
772
+ PrismaServer,
773
+ // Web frameworks & styling
774
+ VueServer,
775
+ SvelteServer,
776
+ ESLintServer,
777
+ CssServer,
778
+ ];
779
+
780
+ /**
781
+ * Get server for a file extension
782
+ */
783
+ export function getServerForExtension(ext: string): LSPServerInfo | undefined {
784
+ return LSP_SERVERS.find((server) => server.extensions.includes(ext));
785
+ }
786
+
787
+ /**
788
+ * Get server by ID
789
+ */
790
+ export function getServerById(id: string): LSPServerInfo | undefined {
791
+ return LSP_SERVERS.find((server) => server.id === id);
792
+ }
793
+
794
+ /**
795
+ * Get all servers for a file (may have multiple matches)
796
+ */
797
+ export function getServersForFile(filePath: string): LSPServerInfo[] {
798
+ const ext = path.extname(filePath).toLowerCase();
799
+ return LSP_SERVERS.filter((server) => server.extensions.includes(ext));
800
+ }