@mastra/code-sdk 1.0.3-alpha.0 → 1.1.0-alpha.2

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 (258) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/acp/agent.js +155 -167
  3. package/dist/acp/agent.js.map +1 -1
  4. package/dist/acp/event-mapper.js +193 -168
  5. package/dist/acp/event-mapper.js.map +1 -1
  6. package/dist/acp/index.js +60 -49
  7. package/dist/acp/index.js.map +1 -1
  8. package/dist/acp/server.js +31 -30
  9. package/dist/acp/server.js.map +1 -1
  10. package/dist/acp.js +1 -4
  11. package/dist/agents/credential-resolver.js +40 -29
  12. package/dist/agents/credential-resolver.js.map +1 -1
  13. package/dist/agents/custom-provider-source.js +16 -9
  14. package/dist/agents/custom-provider-source.js.map +1 -1
  15. package/dist/agents/instructions.js +27 -36
  16. package/dist/agents/instructions.js.map +1 -1
  17. package/dist/agents/mastracode-gateway.js +355 -428
  18. package/dist/agents/mastracode-gateway.js.map +1 -1
  19. package/dist/agents/memory.js +87 -78
  20. package/dist/agents/memory.js.map +1 -1
  21. package/dist/agents/model.js +114 -119
  22. package/dist/agents/model.js.map +1 -1
  23. package/dist/agents/modes/build.js +12 -13
  24. package/dist/agents/modes/build.js.map +1 -1
  25. package/dist/agents/modes/explore.js +14 -13
  26. package/dist/agents/modes/explore.js.map +1 -1
  27. package/dist/agents/modes/plan.js +14 -15
  28. package/dist/agents/modes/plan.js.map +1 -1
  29. package/dist/agents/prompts/agent-instructions.js +78 -69
  30. package/dist/agents/prompts/agent-instructions.js.map +1 -1
  31. package/dist/agents/prompts/build.js +19 -16
  32. package/dist/agents/prompts/build.js.map +1 -1
  33. package/dist/agents/prompts/fast.js +8 -4
  34. package/dist/agents/prompts/fast.js.map +1 -1
  35. package/dist/agents/prompts/index.js +48 -47
  36. package/dist/agents/prompts/index.js.map +1 -1
  37. package/dist/agents/prompts/model.js +6 -5
  38. package/dist/agents/prompts/model.js.map +1 -1
  39. package/dist/agents/prompts/plan.js +20 -16
  40. package/dist/agents/prompts/plan.js.map +1 -1
  41. package/dist/agents/prompts/tool-guidance.js +77 -109
  42. package/dist/agents/prompts/tool-guidance.js.map +1 -1
  43. package/dist/agents/sandbox-filesystem.js +245 -259
  44. package/dist/agents/sandbox-filesystem.js.map +1 -1
  45. package/dist/agents/sandbox-reattach.js +9 -11
  46. package/dist/agents/sandbox-reattach.js.map +1 -1
  47. package/dist/agents/thread-caveman-state.js +92 -81
  48. package/dist/agents/thread-caveman-state.js.map +1 -1
  49. package/dist/agents/tool-availability.js +62 -80
  50. package/dist/agents/tool-availability.js.map +1 -1
  51. package/dist/agents/tools.js +99 -139
  52. package/dist/agents/tools.js.map +1 -1
  53. package/dist/agents/workspace.js +232 -225
  54. package/dist/agents/workspace.js.map +1 -1
  55. package/dist/analytics.js +139 -128
  56. package/dist/analytics.js.map +1 -1
  57. package/dist/auth/authorization-input.js +39 -25
  58. package/dist/auth/authorization-input.js.map +1 -1
  59. package/dist/auth/device-code.js +112 -80
  60. package/dist/auth/device-code.js.map +1 -1
  61. package/dist/auth/index.js +2 -9
  62. package/dist/auth/pkce.js +27 -16
  63. package/dist/auth/pkce.js.map +1 -1
  64. package/dist/auth/providers/anthropic.js +107 -93
  65. package/dist/auth/providers/anthropic.js.map +1 -1
  66. package/dist/auth/providers/github-copilot.js +304 -293
  67. package/dist/auth/providers/github-copilot.js.map +1 -1
  68. package/dist/auth/providers/openai-codex.js +442 -460
  69. package/dist/auth/providers/openai-codex.js.map +1 -1
  70. package/dist/auth/providers/xai.js +179 -145
  71. package/dist/auth/providers/xai.js.map +1 -1
  72. package/dist/auth/storage.js +182 -175
  73. package/dist/auth/storage.js.map +1 -1
  74. package/dist/auth/types.js +1 -1
  75. package/dist/clipboard/index.js +206 -172
  76. package/dist/clipboard/index.js.map +1 -1
  77. package/dist/constants.js +11 -16
  78. package/dist/constants.js.map +1 -1
  79. package/dist/error-classification.js +19 -11
  80. package/dist/error-classification.js.map +1 -1
  81. package/dist/evals/context-builder.js +145 -104
  82. package/dist/evals/context-builder.js.map +1 -1
  83. package/dist/evals/index.js +4 -7
  84. package/dist/evals/scorers/classify-command.js +62 -41
  85. package/dist/evals/scorers/classify-command.js.map +1 -1
  86. package/dist/evals/scorers/efficiency.js +239 -181
  87. package/dist/evals/scorers/efficiency.js.map +1 -1
  88. package/dist/evals/scorers/extract-tools.js +51 -47
  89. package/dist/evals/scorers/extract-tools.js.map +1 -1
  90. package/dist/evals/scorers/index.js +1 -5
  91. package/dist/evals/scorers/outcome.js +321 -212
  92. package/dist/evals/scorers/outcome.js.map +1 -1
  93. package/dist/goal-manager.js +266 -261
  94. package/dist/goal-manager.js.map +1 -1
  95. package/dist/goal-signal.js +14 -13
  96. package/dist/goal-signal.js.map +1 -1
  97. package/dist/headless/cli.js +153 -154
  98. package/dist/headless/cli.js.map +1 -1
  99. package/dist/headless/flags.js +180 -178
  100. package/dist/headless/flags.js.map +1 -1
  101. package/dist/headless/format.js +72 -71
  102. package/dist/headless/format.js.map +1 -1
  103. package/dist/headless/index.js +5 -31
  104. package/dist/headless/policy.js +35 -31
  105. package/dist/headless/policy.js.map +1 -1
  106. package/dist/headless/run-mc.js +332 -334
  107. package/dist/headless/run-mc.js.map +1 -1
  108. package/dist/headless/types.js +16 -7
  109. package/dist/headless/types.js.map +1 -1
  110. package/dist/hooks/config.js +56 -61
  111. package/dist/hooks/config.js.map +1 -1
  112. package/dist/hooks/executor.js +118 -116
  113. package/dist/hooks/executor.js.map +1 -1
  114. package/dist/hooks/index.js +4 -15
  115. package/dist/hooks/manager.js +221 -280
  116. package/dist/hooks/manager.js.map +1 -1
  117. package/dist/hooks/types.js +5 -4
  118. package/dist/hooks/types.js.map +1 -1
  119. package/dist/index.d.ts.map +1 -1
  120. package/dist/index.js +632 -712
  121. package/dist/index.js.map +1 -1
  122. package/dist/ipc/ipc-reporter.js +19 -22
  123. package/dist/ipc/ipc-reporter.js.map +1 -1
  124. package/dist/lsp/client.js +248 -306
  125. package/dist/lsp/client.js.map +1 -1
  126. package/dist/lsp/index.js +1 -6
  127. package/dist/lsp/language.js +39 -43
  128. package/dist/lsp/language.js.map +1 -1
  129. package/dist/lsp/manager.js +78 -93
  130. package/dist/lsp/manager.js.map +1 -1
  131. package/dist/lsp/server.js +151 -120
  132. package/dist/lsp/server.js.map +1 -1
  133. package/dist/lsp/workspace.js +50 -47
  134. package/dist/lsp/workspace.js.map +1 -1
  135. package/dist/mcp/config.js +210 -199
  136. package/dist/mcp/config.js.map +1 -1
  137. package/dist/mcp/index.js +2 -9
  138. package/dist/mcp/manager.js +482 -475
  139. package/dist/mcp/manager.js.map +1 -1
  140. package/dist/mcp/types.js +1 -1
  141. package/dist/onboarding/custom-packs.js +14 -17
  142. package/dist/onboarding/custom-packs.js.map +1 -1
  143. package/dist/onboarding/custom-providers.js +22 -20
  144. package/dist/onboarding/custom-providers.js.map +1 -1
  145. package/dist/onboarding/index.d.ts +1 -1
  146. package/dist/onboarding/index.d.ts.map +1 -1
  147. package/dist/onboarding/index.js +3 -21
  148. package/dist/onboarding/om-settings.d.ts +5 -0
  149. package/dist/onboarding/om-settings.d.ts.map +1 -1
  150. package/dist/onboarding/om-settings.js +41 -20
  151. package/dist/onboarding/om-settings.js.map +1 -1
  152. package/dist/onboarding/packs.d.ts +4 -6
  153. package/dist/onboarding/packs.d.ts.map +1 -1
  154. package/dist/onboarding/packs.js +154 -105
  155. package/dist/onboarding/packs.js.map +1 -1
  156. package/dist/onboarding/settings.js +575 -517
  157. package/dist/onboarding/settings.js.map +1 -1
  158. package/dist/permissions.js +112 -99
  159. package/dist/permissions.js.map +1 -1
  160. package/dist/plugin.js +21 -23
  161. package/dist/plugin.js.map +1 -1
  162. package/dist/plugins/dependencies.js +64 -87
  163. package/dist/plugins/dependencies.js.map +1 -1
  164. package/dist/plugins/install.js +159 -169
  165. package/dist/plugins/install.js.map +1 -1
  166. package/dist/plugins/loader.js +170 -185
  167. package/dist/plugins/loader.js.map +1 -1
  168. package/dist/plugins/manager.js +374 -380
  169. package/dist/plugins/manager.js.map +1 -1
  170. package/dist/plugins/manifest.js +38 -63
  171. package/dist/plugins/manifest.js.map +1 -1
  172. package/dist/plugins/package-link.js +48 -64
  173. package/dist/plugins/package-link.js.map +1 -1
  174. package/dist/plugins/paths.js +18 -19
  175. package/dist/plugins/paths.js.map +1 -1
  176. package/dist/plugins/registry.js +97 -81
  177. package/dist/plugins/registry.js.map +1 -1
  178. package/dist/plugins/scaffold.js +62 -98
  179. package/dist/plugins/scaffold.js.map +1 -1
  180. package/dist/plugins/types.js +1 -1
  181. package/dist/processors/plan-rejection-abort.js +45 -44
  182. package/dist/processors/plan-rejection-abort.js.map +1 -1
  183. package/dist/providers/amazon-bedrock-gateway.js +134 -125
  184. package/dist/providers/amazon-bedrock-gateway.js.map +1 -1
  185. package/dist/providers/amazon-bedrock.js +68 -47
  186. package/dist/providers/amazon-bedrock.js.map +1 -1
  187. package/dist/providers/claude-max.js +153 -133
  188. package/dist/providers/claude-max.js.map +1 -1
  189. package/dist/providers/github-copilot.js +232 -230
  190. package/dist/providers/github-copilot.js.map +1 -1
  191. package/dist/providers/openai-codex.js +271 -260
  192. package/dist/providers/openai-codex.js.map +1 -1
  193. package/dist/providers/xai.js +57 -50
  194. package/dist/providers/xai.js.map +1 -1
  195. package/dist/schema.js +91 -89
  196. package/dist/schema.js.map +1 -1
  197. package/dist/theme-palette.js +18 -14
  198. package/dist/theme-palette.js.map +1 -1
  199. package/dist/tool-names.js +46 -37
  200. package/dist/tool-names.js.map +1 -1
  201. package/dist/tools/index.js +2 -8
  202. package/dist/tools/request-sandbox-access.js +71 -80
  203. package/dist/tools/request-sandbox-access.js.map +1 -1
  204. package/dist/tools/utils.js +26 -16
  205. package/dist/tools/utils.js.map +1 -1
  206. package/dist/tools/web-search.js +51 -55
  207. package/dist/tools/web-search.js.map +1 -1
  208. package/dist/utils/binaries.js +65 -61
  209. package/dist/utils/binaries.js.map +1 -1
  210. package/dist/utils/debug-log.js +51 -47
  211. package/dist/utils/debug-log.js.map +1 -1
  212. package/dist/utils/errors.js +157 -192
  213. package/dist/utils/errors.js.map +1 -1
  214. package/dist/utils/gateway-sync.js +49 -37
  215. package/dist/utils/gateway-sync.js.map +1 -1
  216. package/dist/utils/path-security.js +7 -6
  217. package/dist/utils/path-security.js.map +1 -1
  218. package/dist/utils/plan-diff.js +58 -39
  219. package/dist/utils/plan-diff.js.map +1 -1
  220. package/dist/utils/plans.js +92 -74
  221. package/dist/utils/plans.js.map +1 -1
  222. package/dist/utils/project.js +318 -256
  223. package/dist/utils/project.js.map +1 -1
  224. package/dist/utils/signals-pubsub.js +117 -99
  225. package/dist/utils/signals-pubsub.js.map +1 -1
  226. package/dist/utils/slash-command-loader.js +118 -154
  227. package/dist/utils/slash-command-loader.js.map +1 -1
  228. package/dist/utils/slash-command-processor.js +92 -83
  229. package/dist/utils/slash-command-processor.js.map +1 -1
  230. package/dist/utils/stdin-pipe.js +87 -63
  231. package/dist/utils/stdin-pipe.js.map +1 -1
  232. package/dist/utils/storage-factory.js +104 -84
  233. package/dist/utils/storage-factory.js.map +1 -1
  234. package/dist/utils/storage-maintenance.js +249 -211
  235. package/dist/utils/storage-maintenance.js.map +1 -1
  236. package/dist/utils/thread-lock.js +96 -92
  237. package/dist/utils/thread-lock.js.map +1 -1
  238. package/dist/utils/token-estimator.js +12 -12
  239. package/dist/utils/token-estimator.js.map +1 -1
  240. package/dist/utils/update-check.d.ts +1 -1
  241. package/dist/utils/update-check.js +341 -259
  242. package/dist/utils/update-check.js.map +1 -1
  243. package/dist/voice/stt-registry.js +131 -113
  244. package/dist/voice/stt-registry.js.map +1 -1
  245. package/package.json +11 -11
  246. package/dist/acp.js.map +0 -1
  247. package/dist/auth/index.js.map +0 -1
  248. package/dist/auth/types.js.map +0 -1
  249. package/dist/evals/index.js.map +0 -1
  250. package/dist/evals/scorers/index.js.map +0 -1
  251. package/dist/headless/index.js.map +0 -1
  252. package/dist/hooks/index.js.map +0 -1
  253. package/dist/lsp/index.js.map +0 -1
  254. package/dist/mcp/index.js.map +0 -1
  255. package/dist/mcp/types.js.map +0 -1
  256. package/dist/onboarding/index.js.map +0 -1
  257. package/dist/plugins/types.js.map +0 -1
  258. package/dist/tools/index.js.map +0 -1
package/dist/lsp/index.js CHANGED
@@ -1,9 +1,4 @@
1
1
  import { LSPClient } from "./client.js";
2
2
  import { getServersForFile } from "./server.js";
3
3
  import { lspManager } from "./manager.js";
4
- export {
5
- LSPClient,
6
- getServersForFile,
7
- lspManager
8
- };
9
- //# sourceMappingURL=index.js.map
4
+ export { LSPClient, getServersForFile, lspManager };
@@ -1,48 +1,44 @@
1
+ //#region src/lsp/language.ts
2
+ /**
3
+ * Maps file extensions to LSP language identifiers
4
+ */
1
5
  const LANGUAGE_EXTENSIONS = {
2
- // TypeScript/JavaScript
3
- ".ts": "typescript",
4
- ".tsx": "typescriptreact",
5
- ".js": "javascript",
6
- ".jsx": "javascriptreact",
7
- ".mjs": "javascript",
8
- ".cjs": "javascript",
9
- // Python
10
- ".py": "python",
11
- ".pyi": "python",
12
- // Go
13
- ".go": "go",
14
- // Rust
15
- ".rs": "rust",
16
- // C/C++
17
- ".c": "c",
18
- ".cpp": "cpp",
19
- ".cc": "cpp",
20
- ".cxx": "cpp",
21
- ".h": "c",
22
- ".hpp": "cpp",
23
- // Java
24
- ".java": "java",
25
- // JSON
26
- ".json": "json",
27
- ".jsonc": "jsonc",
28
- // YAML
29
- ".yaml": "yaml",
30
- ".yml": "yaml",
31
- // Markdown
32
- ".md": "markdown",
33
- // HTML/CSS
34
- ".html": "html",
35
- ".css": "css",
36
- ".scss": "scss",
37
- ".sass": "sass",
38
- ".less": "less"
6
+ ".ts": "typescript",
7
+ ".tsx": "typescriptreact",
8
+ ".js": "javascript",
9
+ ".jsx": "javascriptreact",
10
+ ".mjs": "javascript",
11
+ ".cjs": "javascript",
12
+ ".py": "python",
13
+ ".pyi": "python",
14
+ ".go": "go",
15
+ ".rs": "rust",
16
+ ".c": "c",
17
+ ".cpp": "cpp",
18
+ ".cc": "cpp",
19
+ ".cxx": "cpp",
20
+ ".h": "c",
21
+ ".hpp": "cpp",
22
+ ".java": "java",
23
+ ".json": "json",
24
+ ".jsonc": "jsonc",
25
+ ".yaml": "yaml",
26
+ ".yml": "yaml",
27
+ ".md": "markdown",
28
+ ".html": "html",
29
+ ".css": "css",
30
+ ".scss": "scss",
31
+ ".sass": "sass",
32
+ ".less": "less"
39
33
  };
34
+ /**
35
+ * Get LSP language ID for a file path
36
+ */
40
37
  function getLanguageId(filePath) {
41
- const ext = filePath.substring(filePath.lastIndexOf("."));
42
- return LANGUAGE_EXTENSIONS[ext];
38
+ const ext = filePath.substring(filePath.lastIndexOf("."));
39
+ return LANGUAGE_EXTENSIONS[ext];
43
40
  }
44
- export {
45
- LANGUAGE_EXTENSIONS,
46
- getLanguageId
47
- };
41
+ //#endregion
42
+ export { LANGUAGE_EXTENSIONS, getLanguageId };
43
+
48
44
  //# sourceMappingURL=language.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lsp/language.ts"],"sourcesContent":["/**\n * Maps file extensions to LSP language identifiers\n */\nexport const LANGUAGE_EXTENSIONS: Record<string, string> = {\n // TypeScript/JavaScript\n '.ts': 'typescript',\n '.tsx': 'typescriptreact',\n '.js': 'javascript',\n '.jsx': 'javascriptreact',\n '.mjs': 'javascript',\n '.cjs': 'javascript',\n\n // Python\n '.py': 'python',\n '.pyi': 'python',\n\n // Go\n '.go': 'go',\n\n // Rust\n '.rs': 'rust',\n\n // C/C++\n '.c': 'c',\n '.cpp': 'cpp',\n '.cc': 'cpp',\n '.cxx': 'cpp',\n '.h': 'c',\n '.hpp': 'cpp',\n\n // Java\n '.java': 'java',\n\n // JSON\n '.json': 'json',\n '.jsonc': 'jsonc',\n\n // YAML\n '.yaml': 'yaml',\n '.yml': 'yaml',\n\n // Markdown\n '.md': 'markdown',\n\n // HTML/CSS\n '.html': 'html',\n '.css': 'css',\n '.scss': 'scss',\n '.sass': 'sass',\n '.less': 'less',\n};\n\n/**\n * Get LSP language ID for a file path\n */\nexport function getLanguageId(filePath: string): string | undefined {\n const ext = filePath.substring(filePath.lastIndexOf('.'));\n return LANGUAGE_EXTENSIONS[ext];\n}\n"],"mappings":"AAGO,MAAM,sBAA8C;AAAA;AAAA,EAEzD,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA;AAAA,EAGR,OAAO;AAAA,EACP,QAAQ;AAAA;AAAA,EAGR,OAAO;AAAA;AAAA,EAGP,OAAO;AAAA;AAAA,EAGP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA;AAAA,EAGR,SAAS;AAAA;AAAA,EAGT,SAAS;AAAA,EACT,UAAU;AAAA;AAAA,EAGV,SAAS;AAAA,EACT,QAAQ;AAAA;AAAA,EAGR,OAAO;AAAA;AAAA,EAGP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;AAKO,SAAS,cAAc,UAAsC;AAClE,QAAM,MAAM,SAAS,UAAU,SAAS,YAAY,GAAG,CAAC;AACxD,SAAO,oBAAoB,GAAG;AAChC;","names":[]}
1
+ {"version":3,"file":"language.js","names":[],"sources":["../../src/lsp/language.ts"],"sourcesContent":["/**\n * Maps file extensions to LSP language identifiers\n */\nexport const LANGUAGE_EXTENSIONS: Record<string, string> = {\n // TypeScript/JavaScript\n '.ts': 'typescript',\n '.tsx': 'typescriptreact',\n '.js': 'javascript',\n '.jsx': 'javascriptreact',\n '.mjs': 'javascript',\n '.cjs': 'javascript',\n\n // Python\n '.py': 'python',\n '.pyi': 'python',\n\n // Go\n '.go': 'go',\n\n // Rust\n '.rs': 'rust',\n\n // C/C++\n '.c': 'c',\n '.cpp': 'cpp',\n '.cc': 'cpp',\n '.cxx': 'cpp',\n '.h': 'c',\n '.hpp': 'cpp',\n\n // Java\n '.java': 'java',\n\n // JSON\n '.json': 'json',\n '.jsonc': 'jsonc',\n\n // YAML\n '.yaml': 'yaml',\n '.yml': 'yaml',\n\n // Markdown\n '.md': 'markdown',\n\n // HTML/CSS\n '.html': 'html',\n '.css': 'css',\n '.scss': 'scss',\n '.sass': 'sass',\n '.less': 'less',\n};\n\n/**\n * Get LSP language ID for a file path\n */\nexport function getLanguageId(filePath: string): string | undefined {\n const ext = filePath.substring(filePath.lastIndexOf('.'));\n return LANGUAGE_EXTENSIONS[ext];\n}\n"],"mappings":";;;;AAGA,MAAa,sBAA8C;CAEzD,OAAO;CACP,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,QAAQ;CAGR,OAAO;CACP,QAAQ;CAGR,OAAO;CAGP,OAAO;CAGP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,MAAM;CACN,QAAQ;CAGR,SAAS;CAGT,SAAS;CACT,UAAU;CAGV,SAAS;CACT,QAAQ;CAGR,OAAO;CAGP,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACT,SAAS;AACX;;;;AAKA,SAAgB,cAAc,UAAsC;CAClE,MAAM,MAAM,SAAS,UAAU,SAAS,YAAY,GAAG,CAAC;CACxD,OAAO,oBAAoB;AAC7B"}
@@ -1,97 +1,82 @@
1
1
  import { LSPClient } from "./client.js";
2
2
  import { getServersForFile } from "./server.js";
3
- class LSPManager {
4
- clients = /* @__PURE__ */ new Map();
5
- initializationPromises = /* @__PURE__ */ new Map();
6
- /**
7
- * Get or create an LSP client for a file
8
- * Returns null if no LSP server is available for the file
9
- */
10
- async getClient(filePath, workspaceRoot) {
11
- const servers = getServersForFile(filePath, workspaceRoot);
12
- if (servers.length === 0) {
13
- return null;
14
- }
15
- const serverInfo = servers.find(
16
- (s) => s.languageIds.includes("typescript") || s.languageIds.includes("javascript") || s.languageIds.includes("python") || s.languageIds.includes("go")
17
- ) || servers[0];
18
- if (!serverInfo) {
19
- return null;
20
- }
21
- const key = `${serverInfo.name}:${workspaceRoot}`;
22
- if (this.clients.has(key)) {
23
- return this.clients.get(key);
24
- }
25
- if (this.initializationPromises.has(key)) {
26
- await this.initializationPromises.get(key);
27
- return this.clients.get(key) || null;
28
- }
29
- const initPromise = (async () => {
30
- const client = new LSPClient(serverInfo, workspaceRoot);
31
- await client.initialize();
32
- this.clients.set(key, client);
33
- })();
34
- this.initializationPromises.set(key, initPromise);
35
- try {
36
- await Promise.race([
37
- initPromise,
38
- new Promise(
39
- (_, reject) => setTimeout(() => reject(new Error("LSP client initialization timed out")), 15e3)
40
- )
41
- ]);
42
- return this.clients.get(key) || null;
43
- } catch {
44
- this.clients.delete(key);
45
- return null;
46
- } finally {
47
- this.initializationPromises.delete(key);
48
- }
49
- }
50
- /**
51
- * Shutdown a specific client
52
- */
53
- async shutdownClient(workspaceRoot, serverName) {
54
- const keysToRemove = [];
55
- for (const [key, client] of this.clients.entries()) {
56
- if (key.includes(workspaceRoot) && (!serverName || key.startsWith(serverName))) {
57
- await client.shutdown();
58
- keysToRemove.push(key);
59
- }
60
- }
61
- for (const key of keysToRemove) {
62
- this.clients.delete(key);
63
- }
64
- }
65
- /**
66
- * Shutdown all clients
67
- */
68
- async shutdownAll() {
69
- const shutdownPromises = Array.from(this.clients.values()).map((client) => client.shutdown());
70
- await Promise.all(shutdownPromises);
71
- this.clients.clear();
72
- this.initializationPromises.clear();
73
- }
74
- /**
75
- * Get the number of active clients
76
- */
77
- getActiveClientCount() {
78
- return this.clients.size;
79
- }
80
- /**
81
- * Close a document in all active clients
82
- * This is useful for tests that reuse the same file path
83
- */
84
- closeDocument(filePath) {
85
- for (const client of this.clients.values()) {
86
- try {
87
- client.notifyClose(filePath);
88
- } catch {
89
- }
90
- }
91
- }
92
- }
93
- const lspManager = new LSPManager();
94
- export {
95
- lspManager
3
+ //#region src/lsp/manager.ts
4
+ /**
5
+ * Singleton LSP client manager that keeps clients alive and reuses them
6
+ * across tool calls for better performance and accuracy
7
+ */
8
+ var LSPManager = class {
9
+ clients = /* @__PURE__ */ new Map();
10
+ initializationPromises = /* @__PURE__ */ new Map();
11
+ /**
12
+ * Get or create an LSP client for a file
13
+ * Returns null if no LSP server is available for the file
14
+ */
15
+ async getClient(filePath, workspaceRoot) {
16
+ const servers = getServersForFile(filePath, workspaceRoot);
17
+ if (servers.length === 0) return null;
18
+ const serverInfo = servers.find((s) => s.languageIds.includes("typescript") || s.languageIds.includes("javascript") || s.languageIds.includes("python") || s.languageIds.includes("go")) || servers[0];
19
+ if (!serverInfo) return null;
20
+ const key = `${serverInfo.name}:${workspaceRoot}`;
21
+ if (this.clients.has(key)) return this.clients.get(key);
22
+ if (this.initializationPromises.has(key)) {
23
+ await this.initializationPromises.get(key);
24
+ return this.clients.get(key) || null;
25
+ }
26
+ const initPromise = (async () => {
27
+ const client = new LSPClient(serverInfo, workspaceRoot);
28
+ await client.initialize();
29
+ this.clients.set(key, client);
30
+ })();
31
+ this.initializationPromises.set(key, initPromise);
32
+ try {
33
+ await Promise.race([initPromise, new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("LSP client initialization timed out")), 15e3))]);
34
+ return this.clients.get(key) || null;
35
+ } catch {
36
+ this.clients.delete(key);
37
+ return null;
38
+ } finally {
39
+ this.initializationPromises.delete(key);
40
+ }
41
+ }
42
+ /**
43
+ * Shutdown a specific client
44
+ */
45
+ async shutdownClient(workspaceRoot, serverName) {
46
+ const keysToRemove = [];
47
+ for (const [key, client] of this.clients.entries()) if (key.includes(workspaceRoot) && (!serverName || key.startsWith(serverName))) {
48
+ await client.shutdown();
49
+ keysToRemove.push(key);
50
+ }
51
+ for (const key of keysToRemove) this.clients.delete(key);
52
+ }
53
+ /**
54
+ * Shutdown all clients
55
+ */
56
+ async shutdownAll() {
57
+ const shutdownPromises = Array.from(this.clients.values()).map((client) => client.shutdown());
58
+ await Promise.all(shutdownPromises);
59
+ this.clients.clear();
60
+ this.initializationPromises.clear();
61
+ }
62
+ /**
63
+ * Get the number of active clients
64
+ */
65
+ getActiveClientCount() {
66
+ return this.clients.size;
67
+ }
68
+ /**
69
+ * Close a document in all active clients
70
+ * This is useful for tests that reuse the same file path
71
+ */
72
+ closeDocument(filePath) {
73
+ for (const client of this.clients.values()) try {
74
+ client.notifyClose(filePath);
75
+ } catch {}
76
+ }
96
77
  };
78
+ const lspManager = new LSPManager();
79
+ //#endregion
80
+ export { lspManager };
81
+
97
82
  //# sourceMappingURL=manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lsp/manager.ts"],"sourcesContent":["import { LSPClient } from './client.js';\nimport { getServersForFile } from './server.js';\n\n/**\n * Singleton LSP client manager that keeps clients alive and reuses them\n * across tool calls for better performance and accuracy\n */\nclass LSPManager {\n private clients: Map<string, LSPClient> = new Map();\n private initializationPromises: Map<string, Promise<void>> = new Map();\n\n /**\n * Get or create an LSP client for a file\n * Returns null if no LSP server is available for the file\n */\n async getClient(filePath: string, workspaceRoot: string): Promise<LSPClient | null> {\n const servers = getServersForFile(filePath, workspaceRoot);\n if (servers.length === 0) {\n return null;\n }\n\n // Use the first matching server (prioritize TypeScript/JavaScript)\n const serverInfo =\n servers.find(\n s =>\n s.languageIds.includes('typescript') ||\n s.languageIds.includes('javascript') ||\n s.languageIds.includes('python') ||\n s.languageIds.includes('go'),\n ) || servers[0];\n // Create a unique key for this server + workspace combination\n if (!serverInfo) {\n return null;\n }\n const key = `${serverInfo.name}:${workspaceRoot}`;\n\n // Return existing client if available\n if (this.clients.has(key)) {\n return this.clients.get(key)!;\n }\n\n // If initialization is in progress, wait for it\n if (this.initializationPromises.has(key)) {\n await this.initializationPromises.get(key);\n return this.clients.get(key) || null;\n }\n\n // Create and initialize new client with a timeout to prevent indefinite hangs\n // (e.g., npx resolution issues in pnpm-linked projects)\n const initPromise = (async () => {\n const client = new LSPClient(serverInfo, workspaceRoot);\n await client.initialize();\n this.clients.set(key, client);\n })();\n\n this.initializationPromises.set(key, initPromise);\n\n try {\n await Promise.race([\n initPromise,\n new Promise<void>((_, reject) =>\n setTimeout(() => reject(new Error('LSP client initialization timed out')), 15000),\n ),\n ]);\n return this.clients.get(key) || null;\n } catch {\n // If initialization timed out or failed, clean up\n this.clients.delete(key);\n return null;\n } finally {\n this.initializationPromises.delete(key);\n }\n }\n\n /**\n * Shutdown a specific client\n */\n async shutdownClient(workspaceRoot: string, serverName?: string): Promise<void> {\n const keysToRemove: string[] = [];\n\n for (const [key, client] of this.clients.entries()) {\n if (key.includes(workspaceRoot) && (!serverName || key.startsWith(serverName))) {\n await client.shutdown();\n keysToRemove.push(key);\n }\n }\n\n for (const key of keysToRemove) {\n this.clients.delete(key);\n }\n }\n\n /**\n * Shutdown all clients\n */\n async shutdownAll(): Promise<void> {\n const shutdownPromises = Array.from(this.clients.values()).map(client => client.shutdown());\n await Promise.all(shutdownPromises);\n this.clients.clear();\n this.initializationPromises.clear();\n }\n\n /**\n * Get the number of active clients\n */\n getActiveClientCount(): number {\n return this.clients.size;\n }\n\n /**\n * Close a document in all active clients\n * This is useful for tests that reuse the same file path\n */\n closeDocument(filePath: string): void {\n for (const client of this.clients.values()) {\n try {\n client.notifyClose(filePath);\n } catch {\n // Ignore errors if document wasn't open\n }\n }\n }\n}\n\n// Export singleton instance\nexport const lspManager = new LSPManager();\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAMlC,MAAM,WAAW;AAAA,EACP,UAAkC,oBAAI,IAAI;AAAA,EAC1C,yBAAqD,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrE,MAAM,UAAU,UAAkB,eAAkD;AAClF,UAAM,UAAU,kBAAkB,UAAU,aAAa;AACzD,QAAI,QAAQ,WAAW,GAAG;AACxB,aAAO;AAAA,IACT;AAGA,UAAM,aACJ,QAAQ;AAAA,MACN,OACE,EAAE,YAAY,SAAS,YAAY,KACnC,EAAE,YAAY,SAAS,YAAY,KACnC,EAAE,YAAY,SAAS,QAAQ,KAC/B,EAAE,YAAY,SAAS,IAAI;AAAA,IAC/B,KAAK,QAAQ,CAAC;AAEhB,QAAI,CAAC,YAAY;AACf,aAAO;AAAA,IACT;AACA,UAAM,MAAM,GAAG,WAAW,IAAI,IAAI,aAAa;AAG/C,QAAI,KAAK,QAAQ,IAAI,GAAG,GAAG;AACzB,aAAO,KAAK,QAAQ,IAAI,GAAG;AAAA,IAC7B;AAGA,QAAI,KAAK,uBAAuB,IAAI,GAAG,GAAG;AACxC,YAAM,KAAK,uBAAuB,IAAI,GAAG;AACzC,aAAO,KAAK,QAAQ,IAAI,GAAG,KAAK;AAAA,IAClC;AAIA,UAAM,eAAe,YAAY;AAC/B,YAAM,SAAS,IAAI,UAAU,YAAY,aAAa;AACtD,YAAM,OAAO,WAAW;AACxB,WAAK,QAAQ,IAAI,KAAK,MAAM;AAAA,IAC9B,GAAG;AAEH,SAAK,uBAAuB,IAAI,KAAK,WAAW;AAEhD,QAAI;AACF,YAAM,QAAQ,KAAK;AAAA,QACjB;AAAA,QACA,IAAI;AAAA,UAAc,CAAC,GAAG,WACpB,WAAW,MAAM,OAAO,IAAI,MAAM,qCAAqC,CAAC,GAAG,IAAK;AAAA,QAClF;AAAA,MACF,CAAC;AACD,aAAO,KAAK,QAAQ,IAAI,GAAG,KAAK;AAAA,IAClC,QAAQ;AAEN,WAAK,QAAQ,OAAO,GAAG;AACvB,aAAO;AAAA,IACT,UAAE;AACA,WAAK,uBAAuB,OAAO,GAAG;AAAA,IACxC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,eAAe,eAAuB,YAAoC;AAC9E,UAAM,eAAyB,CAAC;AAEhC,eAAW,CAAC,KAAK,MAAM,KAAK,KAAK,QAAQ,QAAQ,GAAG;AAClD,UAAI,IAAI,SAAS,aAAa,MAAM,CAAC,cAAc,IAAI,WAAW,UAAU,IAAI;AAC9E,cAAM,OAAO,SAAS;AACtB,qBAAa,KAAK,GAAG;AAAA,MACvB;AAAA,IACF;AAEA,eAAW,OAAO,cAAc;AAC9B,WAAK,QAAQ,OAAO,GAAG;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAA6B;AACjC,UAAM,mBAAmB,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC,EAAE,IAAI,YAAU,OAAO,SAAS,CAAC;AAC1F,UAAM,QAAQ,IAAI,gBAAgB;AAClC,SAAK,QAAQ,MAAM;AACnB,SAAK,uBAAuB,MAAM;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKA,uBAA+B;AAC7B,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc,UAAwB;AACpC,eAAW,UAAU,KAAK,QAAQ,OAAO,GAAG;AAC1C,UAAI;AACF,eAAO,YAAY,QAAQ;AAAA,MAC7B,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AACF;AAGO,MAAM,aAAa,IAAI,WAAW;","names":[]}
1
+ {"version":3,"file":"manager.js","names":[],"sources":["../../src/lsp/manager.ts"],"sourcesContent":["import { LSPClient } from './client.js';\nimport { getServersForFile } from './server.js';\n\n/**\n * Singleton LSP client manager that keeps clients alive and reuses them\n * across tool calls for better performance and accuracy\n */\nclass LSPManager {\n private clients: Map<string, LSPClient> = new Map();\n private initializationPromises: Map<string, Promise<void>> = new Map();\n\n /**\n * Get or create an LSP client for a file\n * Returns null if no LSP server is available for the file\n */\n async getClient(filePath: string, workspaceRoot: string): Promise<LSPClient | null> {\n const servers = getServersForFile(filePath, workspaceRoot);\n if (servers.length === 0) {\n return null;\n }\n\n // Use the first matching server (prioritize TypeScript/JavaScript)\n const serverInfo =\n servers.find(\n s =>\n s.languageIds.includes('typescript') ||\n s.languageIds.includes('javascript') ||\n s.languageIds.includes('python') ||\n s.languageIds.includes('go'),\n ) || servers[0];\n // Create a unique key for this server + workspace combination\n if (!serverInfo) {\n return null;\n }\n const key = `${serverInfo.name}:${workspaceRoot}`;\n\n // Return existing client if available\n if (this.clients.has(key)) {\n return this.clients.get(key)!;\n }\n\n // If initialization is in progress, wait for it\n if (this.initializationPromises.has(key)) {\n await this.initializationPromises.get(key);\n return this.clients.get(key) || null;\n }\n\n // Create and initialize new client with a timeout to prevent indefinite hangs\n // (e.g., npx resolution issues in pnpm-linked projects)\n const initPromise = (async () => {\n const client = new LSPClient(serverInfo, workspaceRoot);\n await client.initialize();\n this.clients.set(key, client);\n })();\n\n this.initializationPromises.set(key, initPromise);\n\n try {\n await Promise.race([\n initPromise,\n new Promise<void>((_, reject) =>\n setTimeout(() => reject(new Error('LSP client initialization timed out')), 15000),\n ),\n ]);\n return this.clients.get(key) || null;\n } catch {\n // If initialization timed out or failed, clean up\n this.clients.delete(key);\n return null;\n } finally {\n this.initializationPromises.delete(key);\n }\n }\n\n /**\n * Shutdown a specific client\n */\n async shutdownClient(workspaceRoot: string, serverName?: string): Promise<void> {\n const keysToRemove: string[] = [];\n\n for (const [key, client] of this.clients.entries()) {\n if (key.includes(workspaceRoot) && (!serverName || key.startsWith(serverName))) {\n await client.shutdown();\n keysToRemove.push(key);\n }\n }\n\n for (const key of keysToRemove) {\n this.clients.delete(key);\n }\n }\n\n /**\n * Shutdown all clients\n */\n async shutdownAll(): Promise<void> {\n const shutdownPromises = Array.from(this.clients.values()).map(client => client.shutdown());\n await Promise.all(shutdownPromises);\n this.clients.clear();\n this.initializationPromises.clear();\n }\n\n /**\n * Get the number of active clients\n */\n getActiveClientCount(): number {\n return this.clients.size;\n }\n\n /**\n * Close a document in all active clients\n * This is useful for tests that reuse the same file path\n */\n closeDocument(filePath: string): void {\n for (const client of this.clients.values()) {\n try {\n client.notifyClose(filePath);\n } catch {\n // Ignore errors if document wasn't open\n }\n }\n }\n}\n\n// Export singleton instance\nexport const lspManager = new LSPManager();\n"],"mappings":";;;;;;;AAOA,IAAM,aAAN,MAAiB;CACf,0BAA0C,IAAI,IAAI;CAClD,yCAA6D,IAAI,IAAI;;;;;CAMrE,MAAM,UAAU,UAAkB,eAAkD;EAClF,MAAM,UAAU,kBAAkB,UAAU,aAAa;EACzD,IAAI,QAAQ,WAAW,GACrB,OAAO;EAIT,MAAM,aACJ,QAAQ,MACN,MACE,EAAE,YAAY,SAAS,YAAY,KACnC,EAAE,YAAY,SAAS,YAAY,KACnC,EAAE,YAAY,SAAS,QAAQ,KAC/B,EAAE,YAAY,SAAS,IAAI,CAC/B,KAAK,QAAQ;EAEf,IAAI,CAAC,YACH,OAAO;EAET,MAAM,MAAM,GAAG,WAAW,KAAK,GAAG;EAGlC,IAAI,KAAK,QAAQ,IAAI,GAAG,GACtB,OAAO,KAAK,QAAQ,IAAI,GAAG;EAI7B,IAAI,KAAK,uBAAuB,IAAI,GAAG,GAAG;GACxC,MAAM,KAAK,uBAAuB,IAAI,GAAG;GACzC,OAAO,KAAK,QAAQ,IAAI,GAAG,KAAK;EAClC;EAIA,MAAM,eAAe,YAAY;GAC/B,MAAM,SAAS,IAAI,UAAU,YAAY,aAAa;GACtD,MAAM,OAAO,WAAW;GACxB,KAAK,QAAQ,IAAI,KAAK,MAAM;EAC9B,EAAA,CAAG;EAEH,KAAK,uBAAuB,IAAI,KAAK,WAAW;EAEhD,IAAI;GACF,MAAM,QAAQ,KAAK,CACjB,aACA,IAAI,SAAe,GAAG,WACpB,iBAAiB,uBAAO,IAAI,MAAM,qCAAqC,CAAC,GAAG,IAAK,CAClF,CACF,CAAC;GACD,OAAO,KAAK,QAAQ,IAAI,GAAG,KAAK;EAClC,QAAQ;GAEN,KAAK,QAAQ,OAAO,GAAG;GACvB,OAAO;EACT,UAAU;GACR,KAAK,uBAAuB,OAAO,GAAG;EACxC;CACF;;;;CAKA,MAAM,eAAe,eAAuB,YAAoC;EAC9E,MAAM,eAAyB,CAAC;EAEhC,KAAK,MAAM,CAAC,KAAK,WAAW,KAAK,QAAQ,QAAQ,GAC/C,IAAI,IAAI,SAAS,aAAa,MAAM,CAAC,cAAc,IAAI,WAAW,UAAU,IAAI;GAC9E,MAAM,OAAO,SAAS;GACtB,aAAa,KAAK,GAAG;EACvB;EAGF,KAAK,MAAM,OAAO,cAChB,KAAK,QAAQ,OAAO,GAAG;CAE3B;;;;CAKA,MAAM,cAA6B;EACjC,MAAM,mBAAmB,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAI,WAAU,OAAO,SAAS,CAAC;EAC1F,MAAM,QAAQ,IAAI,gBAAgB;EAClC,KAAK,QAAQ,MAAM;EACnB,KAAK,uBAAuB,MAAM;CACpC;;;;CAKA,uBAA+B;EAC7B,OAAO,KAAK,QAAQ;CACtB;;;;;CAMA,cAAc,UAAwB;EACpC,KAAK,MAAM,UAAU,KAAK,QAAQ,OAAO,GACvC,IAAI;GACF,OAAO,YAAY,QAAQ;EAC7B,QAAQ,CAER;CAEJ;AACF;AAGA,MAAa,aAAa,IAAI,WAAW"}
@@ -1,128 +1,159 @@
1
- import { spawn } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
- import { createRequire } from "node:module";
4
- import path, { join } from "node:path";
5
- import { pathToFileURL } from "node:url";
6
1
  import { getLanguageId } from "./language.js";
2
+ import { createRequire } from "module";
3
+ import { existsSync } from "fs";
4
+ import path, { join } from "path";
5
+ import { spawn } from "child_process";
6
+ import { pathToFileURL } from "url";
7
+ //#region src/lsp/server.ts
8
+ /**
9
+ * Find the nearest project root directory
10
+ */
7
11
  function findNearestRoot(cwd, markers) {
8
- let current = cwd;
9
- while (current !== "/") {
10
- for (const marker of markers) {
11
- if (existsSync(join(current, marker))) {
12
- return current;
13
- }
14
- }
15
- const parent = join(current, "..");
16
- if (parent === current) break;
17
- current = parent;
18
- }
19
- return null;
12
+ let current = cwd;
13
+ while (current !== "/") {
14
+ for (const marker of markers) if (existsSync(join(current, marker))) return current;
15
+ const parent = join(current, "..");
16
+ if (parent === current) break;
17
+ current = parent;
18
+ }
19
+ return null;
20
20
  }
21
+ /**
22
+ * Built-in LSP server definitions
23
+ */
21
24
  const BUILTIN_SERVERS = {
22
- typescript: {
23
- id: "typescript",
24
- name: "TypeScript Language Server",
25
- languageIds: ["typescript", "typescriptreact", "javascript", "javascriptreact"],
26
- root: (cwd) => findNearestRoot(cwd, ["tsconfig.json", "package.json"]),
27
- spawn: async (root) => {
28
- const requireFromRoot = createRequire(pathToFileURL(path.join(root, "package.json")));
29
- let tsserver;
30
- try {
31
- tsserver = requireFromRoot.resolve("typescript/lib/tsserver.js");
32
- } catch {
33
- tsserver = void 0;
34
- }
35
- if (!tsserver) {
36
- return void 0;
37
- }
38
- const localBin = join(root, "node_modules", ".bin", "typescript-language-server");
39
- const cwdBin = join(process.cwd(), "node_modules", ".bin", "typescript-language-server");
40
- let tslsBinary;
41
- if (existsSync(localBin)) {
42
- tslsBinary = localBin;
43
- } else if (existsSync(cwdBin)) {
44
- tslsBinary = cwdBin;
45
- } else {
46
- tslsBinary = "npx";
47
- }
48
- const args = tslsBinary === "npx" ? ["typescript-language-server", "--stdio"] : ["--stdio"];
49
- const proc = spawn(tslsBinary, args, {
50
- cwd: root,
51
- stdio: ["pipe", "pipe", "pipe"]
52
- });
53
- return {
54
- process: proc,
55
- initialization: {
56
- tsserver: {
57
- path: tsserver,
58
- logVerbosity: "off"
59
- }
60
- }
61
- };
62
- }
63
- },
64
- eslint: {
65
- id: "eslint",
66
- name: "ESLint Language Server",
67
- languageIds: ["typescript", "typescriptreact", "javascript", "javascriptreact"],
68
- root: (cwd) => findNearestRoot(cwd, ["package.json", ".eslintrc.js", ".eslintrc.json", ".eslintrc.yml", ".eslintrc.yaml"]),
69
- spawn: (root) => {
70
- const binaryPath = join(process.cwd(), "node_modules", ".bin", "eslint-lsp");
71
- return spawn(binaryPath, ["--stdio"], {
72
- cwd: root,
73
- stdio: ["pipe", "pipe", "pipe"]
74
- });
75
- }
76
- },
77
- python: {
78
- id: "python",
79
- name: "Python Language Server (Pyright)",
80
- languageIds: ["python"],
81
- root: (cwd) => findNearestRoot(cwd, ["pyproject.toml", "setup.py", "requirements.txt", ".git"]),
82
- spawn: (root) => {
83
- const localPath = join(process.cwd(), "node_modules", ".bin", "pyright-langserver");
84
- const binaryPath = existsSync(localPath) ? localPath : "pyright-langserver";
85
- return spawn(binaryPath, ["--stdio"], {
86
- cwd: root,
87
- stdio: ["pipe", "pipe", "pipe"]
88
- });
89
- }
90
- },
91
- go: {
92
- id: "go",
93
- name: "Go Language Server (gopls)",
94
- languageIds: ["go"],
95
- root: (cwd) => findNearestRoot(cwd, ["go.mod", ".git"]),
96
- spawn: (root) => {
97
- return spawn("gopls", ["serve"], {
98
- cwd: root,
99
- stdio: ["pipe", "pipe", "pipe"]
100
- });
101
- }
102
- },
103
- rust: {
104
- id: "rust",
105
- name: "Rust Language Server (rust-analyzer)",
106
- languageIds: ["rust"],
107
- root: (cwd) => findNearestRoot(cwd, ["Cargo.toml", ".git"]),
108
- spawn: (root) => {
109
- return spawn("rust-analyzer", ["--stdio"], {
110
- cwd: root,
111
- stdio: ["pipe", "pipe", "pipe"]
112
- });
113
- }
114
- }
25
+ typescript: {
26
+ id: "typescript",
27
+ name: "TypeScript Language Server",
28
+ languageIds: [
29
+ "typescript",
30
+ "typescriptreact",
31
+ "javascript",
32
+ "javascriptreact"
33
+ ],
34
+ root: (cwd) => findNearestRoot(cwd, ["tsconfig.json", "package.json"]),
35
+ spawn: async (root) => {
36
+ const requireFromRoot = createRequire(pathToFileURL(path.join(root, "package.json")));
37
+ let tsserver;
38
+ try {
39
+ tsserver = requireFromRoot.resolve("typescript/lib/tsserver.js");
40
+ } catch {
41
+ tsserver = void 0;
42
+ }
43
+ if (!tsserver) return;
44
+ const localBin = join(root, "node_modules", ".bin", "typescript-language-server");
45
+ const cwdBin = join(process.cwd(), "node_modules", ".bin", "typescript-language-server");
46
+ let tslsBinary;
47
+ if (existsSync(localBin)) tslsBinary = localBin;
48
+ else if (existsSync(cwdBin)) tslsBinary = cwdBin;
49
+ else tslsBinary = "npx";
50
+ return {
51
+ process: spawn(tslsBinary, tslsBinary === "npx" ? ["typescript-language-server", "--stdio"] : ["--stdio"], {
52
+ cwd: root,
53
+ stdio: [
54
+ "pipe",
55
+ "pipe",
56
+ "pipe"
57
+ ]
58
+ }),
59
+ initialization: { tsserver: {
60
+ path: tsserver,
61
+ logVerbosity: "off"
62
+ } }
63
+ };
64
+ }
65
+ },
66
+ eslint: {
67
+ id: "eslint",
68
+ name: "ESLint Language Server",
69
+ languageIds: [
70
+ "typescript",
71
+ "typescriptreact",
72
+ "javascript",
73
+ "javascriptreact"
74
+ ],
75
+ root: (cwd) => findNearestRoot(cwd, [
76
+ "package.json",
77
+ ".eslintrc.js",
78
+ ".eslintrc.json",
79
+ ".eslintrc.yml",
80
+ ".eslintrc.yaml"
81
+ ]),
82
+ spawn: (root) => {
83
+ return spawn(join(process.cwd(), "node_modules", ".bin", "eslint-lsp"), ["--stdio"], {
84
+ cwd: root,
85
+ stdio: [
86
+ "pipe",
87
+ "pipe",
88
+ "pipe"
89
+ ]
90
+ });
91
+ }
92
+ },
93
+ python: {
94
+ id: "python",
95
+ name: "Python Language Server (Pyright)",
96
+ languageIds: ["python"],
97
+ root: (cwd) => findNearestRoot(cwd, [
98
+ "pyproject.toml",
99
+ "setup.py",
100
+ "requirements.txt",
101
+ ".git"
102
+ ]),
103
+ spawn: (root) => {
104
+ const localPath = join(process.cwd(), "node_modules", ".bin", "pyright-langserver");
105
+ return spawn(existsSync(localPath) ? localPath : "pyright-langserver", ["--stdio"], {
106
+ cwd: root,
107
+ stdio: [
108
+ "pipe",
109
+ "pipe",
110
+ "pipe"
111
+ ]
112
+ });
113
+ }
114
+ },
115
+ go: {
116
+ id: "go",
117
+ name: "Go Language Server (gopls)",
118
+ languageIds: ["go"],
119
+ root: (cwd) => findNearestRoot(cwd, ["go.mod", ".git"]),
120
+ spawn: (root) => {
121
+ return spawn("gopls", ["serve"], {
122
+ cwd: root,
123
+ stdio: [
124
+ "pipe",
125
+ "pipe",
126
+ "pipe"
127
+ ]
128
+ });
129
+ }
130
+ },
131
+ rust: {
132
+ id: "rust",
133
+ name: "Rust Language Server (rust-analyzer)",
134
+ languageIds: ["rust"],
135
+ root: (cwd) => findNearestRoot(cwd, ["Cargo.toml", ".git"]),
136
+ spawn: (root) => {
137
+ return spawn("rust-analyzer", ["--stdio"], {
138
+ cwd: root,
139
+ stdio: [
140
+ "pipe",
141
+ "pipe",
142
+ "pipe"
143
+ ]
144
+ });
145
+ }
146
+ }
115
147
  };
148
+ /**
149
+ * Get all servers that can handle a file
150
+ */
116
151
  function getServersForFile(filePath, cwd) {
117
- const languageId = getLanguageId(filePath);
118
- if (!languageId) return [];
119
- return Object.values(BUILTIN_SERVERS).filter(
120
- (server) => server.languageIds.includes(languageId) && server.root(cwd) !== null
121
- );
152
+ const languageId = getLanguageId(filePath);
153
+ if (!languageId) return [];
154
+ return Object.values(BUILTIN_SERVERS).filter((server) => server.languageIds.includes(languageId) && server.root(cwd) !== null);
122
155
  }
123
- export {
124
- BUILTIN_SERVERS,
125
- findNearestRoot,
126
- getServersForFile
127
- };
156
+ //#endregion
157
+ export { BUILTIN_SERVERS, findNearestRoot, getServersForFile };
158
+
128
159
  //# sourceMappingURL=server.js.map