pi-agent-ide 0.1.0 → 0.1.1

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 (511) hide show
  1. package/README.md +31 -9
  2. package/docs/architecture.md +18 -6
  3. package/docs/configuration.md +70 -40
  4. package/docs/development.md +14 -2
  5. package/docs/extensions.md +132 -150
  6. package/docs/generated/tool-catalog/c.md +9 -0
  7. package/docs/generated/tool-catalog/cmake.md +9 -0
  8. package/docs/generated/tool-catalog/cpp.md +9 -0
  9. package/docs/generated/tool-catalog/csharp.md +9 -0
  10. package/docs/generated/tool-catalog/css.md +10 -0
  11. package/docs/generated/tool-catalog/dockerfile.md +9 -0
  12. package/docs/generated/tool-catalog/go.md +10 -0
  13. package/docs/generated/tool-catalog/html.md +9 -0
  14. package/docs/generated/tool-catalog/index.md +30 -0
  15. package/docs/generated/tool-catalog/java.md +9 -0
  16. package/docs/generated/tool-catalog/javascript.md +10 -0
  17. package/docs/generated/tool-catalog/json.md +10 -0
  18. package/docs/generated/tool-catalog/kotlin.md +9 -0
  19. package/docs/generated/tool-catalog/lua.md +9 -0
  20. package/docs/generated/tool-catalog/markdown.md +9 -0
  21. package/docs/generated/tool-catalog/php.md +9 -0
  22. package/docs/generated/tool-catalog/python.md +10 -0
  23. package/docs/generated/tool-catalog/ruby.md +9 -0
  24. package/docs/generated/tool-catalog/rust.md +9 -0
  25. package/docs/generated/tool-catalog/shell.md +9 -0
  26. package/docs/generated/tool-catalog/sql.md +9 -0
  27. package/docs/generated/tool-catalog/swift.md +9 -0
  28. package/docs/generated/tool-catalog/terraform.md +9 -0
  29. package/docs/generated/tool-catalog/toml.md +9 -0
  30. package/docs/generated/tool-catalog/typescript.md +10 -0
  31. package/docs/generated/tool-catalog/xml.md +9 -0
  32. package/docs/generated/tool-catalog/yaml.md +9 -0
  33. package/node_modules/pi-agent-doctor/package.json +26 -0
  34. package/node_modules/pi-agent-doctor/src/catalog.ts +55 -0
  35. package/node_modules/pi-agent-doctor/src/connect-plugin.ts +53 -0
  36. package/node_modules/pi-agent-doctor/src/executable.ts +47 -0
  37. package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +121 -0
  38. package/node_modules/pi-agent-filesystem/index.ts +42 -44
  39. package/node_modules/pi-agent-filesystem/package.json +11 -11
  40. package/node_modules/pi-agent-filesystem/src/resolver.ts +112 -135
  41. package/node_modules/pi-agent-filesystem-image/index.ts +5 -6
  42. package/node_modules/pi-agent-filesystem-image/package.json +8 -8
  43. package/node_modules/pi-agent-filesystem-pdf/index.ts +5 -6
  44. package/node_modules/pi-agent-filesystem-pdf/package.json +5 -5
  45. package/node_modules/pi-agent-filesystem-text/index.ts +11 -12
  46. package/node_modules/pi-agent-filesystem-text/package.json +8 -8
  47. package/node_modules/pi-agent-ide-ast/index.ts +1 -1
  48. package/node_modules/pi-agent-ide-ast/package.json +13 -12
  49. package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
  50. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +292 -322
  51. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +591 -656
  52. package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
  53. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +105 -0
  54. package/node_modules/pi-agent-ide-ast/src/extension.ts +67 -64
  55. package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
  56. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +168 -185
  57. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +30 -36
  58. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +118 -129
  59. package/node_modules/pi-agent-ide-changes/index.ts +53 -51
  60. package/node_modules/pi-agent-ide-changes/package.json +12 -11
  61. package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +68 -78
  62. package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
  63. package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
  64. package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
  65. package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +258 -276
  66. package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
  67. package/node_modules/pi-agent-ide-changes/src/doctor-plugin.ts +29 -0
  68. package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
  69. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
  70. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +93 -93
  71. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +124 -126
  72. package/node_modules/pi-agent-ide-formatter/index.ts +22 -23
  73. package/node_modules/pi-agent-ide-formatter/package.json +5 -2
  74. package/node_modules/pi-agent-ide-formatter/src/catalog.ts +247 -0
  75. package/node_modules/pi-agent-ide-formatter/src/doctor-plugin.ts +104 -0
  76. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +38 -40
  77. package/node_modules/pi-agent-ide-formatter/src/registry.ts +45 -21
  78. package/node_modules/pi-agent-ide-languages/index.ts +24 -0
  79. package/node_modules/pi-agent-ide-languages/package.json +16 -0
  80. package/node_modules/pi-agent-ide-languages/src/languages.ts +84 -0
  81. package/node_modules/pi-agent-ide-lint/index.ts +164 -198
  82. package/node_modules/pi-agent-ide-lint/package.json +8 -7
  83. package/node_modules/pi-agent-ide-lint/src/catalog.ts +283 -0
  84. package/node_modules/pi-agent-ide-lint/src/command-linter.ts +50 -152
  85. package/node_modules/pi-agent-ide-lint/src/diagnostics.ts +180 -0
  86. package/node_modules/pi-agent-ide-lint/src/doctor-plugin.ts +104 -0
  87. package/node_modules/pi-agent-ide-lint/src/registry.ts +43 -21
  88. package/node_modules/pi-agent-ide-lsp/index.ts +187 -208
  89. package/node_modules/pi-agent-ide-lsp/package.json +12 -11
  90. package/node_modules/pi-agent-ide-lsp/src/catalog.ts +248 -0
  91. package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
  92. package/node_modules/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -0
  93. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +361 -385
  94. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +420 -458
  95. package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +128 -137
  96. package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
  97. package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
  98. package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +48 -56
  99. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +369 -411
  100. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
  101. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +153 -70
  102. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
  103. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +117 -127
  104. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
  105. package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +74 -57
  106. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
  107. package/node_modules/pi-agent-image/package.json +2 -2
  108. package/node_modules/pi-agent-image/src/image-converter.ts +210 -249
  109. package/node_modules/pi-agent-image/src/index.ts +4 -4
  110. package/node_modules/pi-agent-pdf/package.json +2 -2
  111. package/node_modules/pi-agent-pdf/src/index.ts +1 -5
  112. package/node_modules/pi-agent-pdf/src/pdf-converter.ts +130 -153
  113. package/node_modules/pi-agent-read/index.ts +1 -1
  114. package/node_modules/pi-agent-read/package.json +9 -9
  115. package/node_modules/pi-agent-read/src/api/connect-plugin.ts +38 -51
  116. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +26 -32
  117. package/node_modules/pi-agent-read/src/api/rendering.ts +3 -4
  118. package/node_modules/pi-agent-read/src/api/tools/read.ts +124 -132
  119. package/node_modules/pi-agent-read/src/core/extension.ts +28 -29
  120. package/node_modules/pi-agent-read/src/core/read-core.ts +281 -330
  121. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +153 -156
  122. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +294 -316
  123. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +146 -155
  124. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
  125. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +644 -693
  126. package/node_modules/pi-agent-resource/package.json +1 -1
  127. package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +50 -62
  128. package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +27 -33
  129. package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +16 -20
  130. package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +52 -57
  131. package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +115 -134
  132. package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +38 -39
  133. package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +117 -107
  134. package/node_modules/pi-agent-resource/src/content.ts +5 -9
  135. package/node_modules/pi-agent-resource/src/index.ts +51 -40
  136. package/node_modules/pi-agent-resource/src/resolver.ts +11 -13
  137. package/node_modules/pi-agent-resource/src/resource.ts +17 -24
  138. package/node_modules/pi-agent-resource/src/validation.ts +106 -92
  139. package/node_modules/pi-agent-search/package.json +7 -7
  140. package/node_modules/pi-agent-search/src/api/connect-plugin.ts +37 -47
  141. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +26 -30
  142. package/node_modules/pi-agent-search/src/api/search.ts +61 -67
  143. package/node_modules/pi-agent-search/src/core/extension.ts +112 -92
  144. package/node_modules/pi-agent-search/src/core/search-core.ts +330 -359
  145. package/node_modules/pi-agent-search-semantic/index.ts +75 -83
  146. package/node_modules/pi-agent-search-semantic/package.json +5 -5
  147. package/node_modules/pi-agent-search-text/index.ts +40 -38
  148. package/node_modules/pi-agent-search-text/package.json +10 -9
  149. package/node_modules/pi-agent-search-text/src/doctor-plugin.ts +29 -0
  150. package/node_modules/pi-agent-search-text/src/file-search.ts +90 -86
  151. package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +17 -19
  152. package/node_modules/pi-agent-search-text/src/resolvers.ts +152 -157
  153. package/node_modules/pi-agent-search-text/src/ripgrep.ts +16 -0
  154. package/node_modules/pi-agent-search-text/src/search-backend.ts +215 -249
  155. package/node_modules/pi-agent-search-text/src/search-query.ts +85 -108
  156. package/node_modules/pi-agent-search-text/src/search-renderer.ts +310 -334
  157. package/node_modules/pi-agent-search-text/src/search-result.ts +151 -157
  158. package/node_modules/pi-agent-search-text/src/search-session.ts +255 -261
  159. package/node_modules/pi-agent-search-web/index.ts +65 -57
  160. package/node_modules/pi-agent-search-web/package.json +8 -7
  161. package/node_modules/pi-agent-search-web/src/config.ts +470 -409
  162. package/node_modules/pi-agent-search-web/src/doctor-plugin.ts +40 -0
  163. package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +56 -60
  164. package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +60 -68
  165. package/node_modules/pi-agent-search-web/src/providers/request.ts +359 -362
  166. package/node_modules/pi-agent-search-web/src/providers/response.ts +296 -345
  167. package/node_modules/pi-agent-search-web/src/search-format.ts +15 -20
  168. package/node_modules/pi-agent-search-web/src/search.ts +289 -347
  169. package/node_modules/pi-agent-search-web/src/types.ts +99 -111
  170. package/node_modules/pi-agent-text/package.json +2 -2
  171. package/node_modules/pi-agent-text/src/index.ts +30 -22
  172. package/node_modules/pi-agent-text/src/presented-text.ts +15 -17
  173. package/node_modules/pi-agent-text/src/source-line.ts +33 -36
  174. package/node_modules/pi-agent-text/src/text-anchor.ts +120 -117
  175. package/node_modules/pi-agent-text/src/text-converter.ts +71 -84
  176. package/node_modules/pi-agent-text/src/text-document.ts +99 -110
  177. package/node_modules/pi-agent-text-anchor-constant/index.ts +18 -20
  178. package/node_modules/pi-agent-text-anchor-constant/package.json +5 -5
  179. package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +29 -36
  180. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +34 -36
  181. package/node_modules/pi-agent-text-anchor-line-hash/package.json +11 -11
  182. package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +75 -85
  183. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +35 -42
  184. package/node_modules/pi-agent-text-editor/index.ts +7 -9
  185. package/node_modules/pi-agent-text-editor/package.json +10 -10
  186. package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +16 -18
  187. package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
  188. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
  189. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
  190. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
  191. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
  192. package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
  193. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +19 -19
  194. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +117 -132
  195. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +155 -141
  196. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +93 -103
  197. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
  198. package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +84 -95
  199. package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +9 -9
  200. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
  201. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +41 -47
  202. package/node_modules/pi-agent-text-editor/src/core/extension.ts +115 -120
  203. package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +273 -311
  204. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
  205. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +232 -289
  206. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +534 -580
  207. package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
  208. package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
  209. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +282 -336
  210. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +181 -214
  211. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
  212. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
  213. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
  214. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +367 -372
  215. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +82 -88
  216. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +1837 -2035
  217. package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +19 -22
  218. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +629 -631
  219. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +982 -1031
  220. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
  221. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
  222. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -2
  223. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
  224. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +9 -11
  225. package/node_modules/pi-agent-text-editor/src/tools/extension.ts +7 -8
  226. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +69 -77
  227. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +109 -95
  228. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +69 -61
  229. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +52 -39
  230. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +121 -115
  231. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +71 -54
  232. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +24 -17
  233. package/node_modules/pi-agent-text-editor-argument-order/index.ts +16 -19
  234. package/node_modules/pi-agent-text-editor-argument-order/package.json +4 -4
  235. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
  236. package/node_modules/pi-agent-text-editor-overwrite/index.ts +297 -323
  237. package/node_modules/pi-agent-text-editor-overwrite/package.json +4 -4
  238. package/node_modules/pi-agent-text-editor-renderer/index.ts +11 -12
  239. package/node_modules/pi-agent-text-editor-renderer/package.json +7 -7
  240. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
  241. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +203 -219
  242. package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
  243. package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
  244. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
  245. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +170 -182
  246. package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +330 -340
  247. package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +115 -118
  248. package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +3 -4
  249. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +582 -629
  250. package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +144 -167
  251. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +317 -333
  252. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  253. package/node_modules/pi-agent-tool-call-interception/package.json +1 -1
  254. package/node_modules/pi-agent-tool-call-interception/src/index.ts +334 -354
  255. package/node_modules/pi-agent-web/index.ts +24 -25
  256. package/node_modules/pi-agent-web/package.json +10 -10
  257. package/node_modules/pi-agent-web/src/resolver.ts +133 -155
  258. package/node_modules/pi-agent-web-html/index.ts +5 -6
  259. package/node_modules/pi-agent-web-html/package.json +6 -6
  260. package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +58 -76
  261. package/node_modules/pi-agent-web-html/src/html-converter.ts +62 -75
  262. package/node_modules/pi-agent-web-image/index.ts +5 -6
  263. package/node_modules/pi-agent-web-image/package.json +5 -5
  264. package/node_modules/pi-agent-web-pdf/index.ts +5 -6
  265. package/node_modules/pi-agent-web-pdf/package.json +5 -5
  266. package/node_modules/pi-agent-web-text/index.ts +5 -6
  267. package/node_modules/pi-agent-web-text/package.json +5 -5
  268. package/package.json +72 -52
  269. package/src/api/code-view.ts +17 -17
  270. package/src/api/connect-doctor-plugin.ts +1 -0
  271. package/src/api/connect-plugin.ts +38 -48
  272. package/src/api/doctor.ts +1 -0
  273. package/src/api/plugin-protocol.ts +30 -38
  274. package/src/api/read.ts +6 -1
  275. package/src/api/resource.ts +3 -1
  276. package/src/api/search.ts +5 -1
  277. package/src/api/text-editor.ts +4 -1
  278. package/src/api/text.ts +3 -1
  279. package/src/api/tool-catalog.ts +1 -0
  280. package/src/api/tool-config.ts +365 -0
  281. package/src/api/toolchain.ts +18 -18
  282. package/src/code-view/diagnostic-view.ts +59 -58
  283. package/src/code-view/reference.ts +64 -82
  284. package/src/code-view/source-view.ts +159 -180
  285. package/src/composite/builtin-extensions.ts +39 -35
  286. package/src/composite/config.ts +75 -69
  287. package/src/composite/selection.ts +54 -52
  288. package/src/core/extension.ts +32 -36
  289. package/src/core/ide-core.ts +76 -93
  290. package/src/doctor/config-writer.ts +115 -0
  291. package/src/doctor/core.ts +174 -0
  292. package/src/doctor/discovery.ts +215 -0
  293. package/src/doctor/extension.ts +108 -0
  294. package/src/doctor/index.ts +1 -0
  295. package/src/doctor/inventory.ts +91 -0
  296. package/src/doctor/run.ts +196 -0
  297. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +42 -44
  298. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +11 -11
  299. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +5 -6
  300. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +8 -8
  301. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +5 -6
  302. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +5 -5
  303. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +11 -12
  304. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +8 -8
  305. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +112 -135
  306. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +24 -25
  307. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +10 -10
  308. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +5 -6
  309. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +6 -6
  310. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +58 -76
  311. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +62 -75
  312. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +5 -6
  313. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +5 -5
  314. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +5 -6
  315. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +5 -5
  316. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +5 -6
  317. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +5 -5
  318. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +133 -155
  319. package/src/extensions/pi-agent-read/index.ts +1 -1
  320. package/src/extensions/pi-agent-read/package.json +9 -9
  321. package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +38 -51
  322. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +26 -32
  323. package/src/extensions/pi-agent-read/src/api/rendering.ts +3 -4
  324. package/src/extensions/pi-agent-read/src/api/tools/read.ts +124 -132
  325. package/src/extensions/pi-agent-read/src/core/extension.ts +28 -29
  326. package/src/extensions/pi-agent-read/src/core/read-core.ts +281 -330
  327. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +153 -156
  328. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +294 -316
  329. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +146 -155
  330. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
  331. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +644 -693
  332. package/src/extensions/pi-agent-search/package.json +7 -7
  333. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +75 -83
  334. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +5 -5
  335. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +40 -38
  336. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +10 -9
  337. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/doctor-plugin.ts +29 -0
  338. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +90 -86
  339. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +17 -19
  340. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +152 -157
  341. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/ripgrep.ts +16 -0
  342. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +215 -249
  343. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +85 -108
  344. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +310 -334
  345. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +151 -157
  346. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +255 -261
  347. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +65 -57
  348. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +8 -7
  349. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +470 -409
  350. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/doctor-plugin.ts +40 -0
  351. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +56 -60
  352. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +60 -68
  353. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +359 -362
  354. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +296 -345
  355. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +15 -20
  356. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +289 -347
  357. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +99 -111
  358. package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +37 -47
  359. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +26 -30
  360. package/src/extensions/pi-agent-search/src/api/search.ts +61 -67
  361. package/src/extensions/pi-agent-search/src/core/extension.ts +112 -92
  362. package/src/extensions/pi-agent-search/src/core/search-core.ts +330 -359
  363. package/src/extensions/pi-agent-text-editor/index.ts +7 -9
  364. package/src/extensions/pi-agent-text-editor/package.json +10 -10
  365. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +18 -20
  366. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +5 -5
  367. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +29 -36
  368. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +34 -36
  369. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +11 -11
  370. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +75 -85
  371. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +35 -42
  372. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +16 -19
  373. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +4 -4
  374. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
  375. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +297 -323
  376. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +4 -4
  377. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +11 -12
  378. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +7 -7
  379. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
  380. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +203 -219
  381. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
  382. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
  383. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
  384. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +170 -182
  385. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +330 -340
  386. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +115 -118
  387. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +3 -4
  388. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +582 -629
  389. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +144 -167
  390. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +317 -333
  391. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  392. package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +16 -18
  393. package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
  394. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
  395. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
  396. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
  397. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
  398. package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
  399. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +19 -19
  400. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +117 -132
  401. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +155 -141
  402. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +93 -103
  403. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
  404. package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +84 -95
  405. package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +9 -9
  406. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
  407. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +41 -47
  408. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +115 -120
  409. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +273 -311
  410. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
  411. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +232 -289
  412. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +534 -580
  413. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
  414. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
  415. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +282 -336
  416. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +181 -214
  417. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
  418. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
  419. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
  420. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +367 -372
  421. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +82 -88
  422. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +1837 -2035
  423. package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +19 -22
  424. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +629 -631
  425. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +982 -1031
  426. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
  427. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
  428. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -2
  429. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
  430. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +9 -11
  431. package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +7 -8
  432. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +69 -77
  433. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +109 -95
  434. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +69 -61
  435. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +52 -39
  436. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +121 -115
  437. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +71 -54
  438. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +24 -17
  439. package/src/pi-agent-ide.ts +10 -10
  440. package/src/plugins/pi-agent-ide-ast/index.ts +1 -1
  441. package/src/plugins/pi-agent-ide-ast/package.json +13 -12
  442. package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
  443. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +292 -322
  444. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +591 -656
  445. package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
  446. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +105 -0
  447. package/src/plugins/pi-agent-ide-ast/src/extension.ts +67 -64
  448. package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
  449. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +168 -185
  450. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +30 -36
  451. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +118 -129
  452. package/src/plugins/pi-agent-ide-changes/index.ts +53 -51
  453. package/src/plugins/pi-agent-ide-changes/package.json +12 -11
  454. package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +68 -78
  455. package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
  456. package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
  457. package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
  458. package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +258 -276
  459. package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
  460. package/src/plugins/pi-agent-ide-changes/src/doctor-plugin.ts +29 -0
  461. package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
  462. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
  463. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +93 -93
  464. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +124 -126
  465. package/src/plugins/pi-agent-ide-formatter/index.ts +22 -23
  466. package/src/plugins/pi-agent-ide-formatter/package.json +5 -2
  467. package/src/plugins/pi-agent-ide-formatter/src/catalog.ts +247 -0
  468. package/src/plugins/pi-agent-ide-formatter/src/doctor-plugin.ts +104 -0
  469. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +38 -40
  470. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +45 -21
  471. package/src/plugins/pi-agent-ide-languages/index.ts +24 -0
  472. package/src/plugins/pi-agent-ide-languages/package.json +16 -0
  473. package/src/plugins/pi-agent-ide-languages/src/languages.ts +84 -0
  474. package/src/plugins/pi-agent-ide-lint/index.ts +164 -198
  475. package/src/plugins/pi-agent-ide-lint/package.json +8 -7
  476. package/src/plugins/pi-agent-ide-lint/src/catalog.ts +283 -0
  477. package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +50 -152
  478. package/src/plugins/pi-agent-ide-lint/src/diagnostics.ts +180 -0
  479. package/src/plugins/pi-agent-ide-lint/src/doctor-plugin.ts +104 -0
  480. package/src/plugins/pi-agent-ide-lint/src/registry.ts +43 -21
  481. package/src/plugins/pi-agent-ide-lsp/index.ts +187 -208
  482. package/src/plugins/pi-agent-ide-lsp/package.json +12 -11
  483. package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +248 -0
  484. package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
  485. package/src/plugins/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -0
  486. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +361 -385
  487. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +420 -458
  488. package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +128 -137
  489. package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
  490. package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
  491. package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +48 -56
  492. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +369 -411
  493. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
  494. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +153 -70
  495. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
  496. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +117 -127
  497. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
  498. package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +74 -57
  499. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
  500. package/src/post-edit/gate.ts +114 -122
  501. package/src/toolchain/diagnostic.ts +3 -4
  502. package/src/toolchain/gate.ts +278 -295
  503. package/src/toolchain/registry.ts +143 -165
  504. package/src/toolchain/types.ts +126 -103
  505. package/src/utils/required-value.ts +8 -0
  506. package/node_modules/pi-agent-ide-formatter/src/types.ts +0 -10
  507. package/node_modules/pi-agent-ide-lint/src/command-runner.ts +0 -51
  508. package/node_modules/pi-agent-ide-lint/src/types.ts +0 -10
  509. package/src/plugins/pi-agent-ide-formatter/src/types.ts +0 -10
  510. package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +0 -51
  511. package/src/plugins/pi-agent-ide-lint/src/types.ts +0 -10
@@ -1,11 +1,12 @@
1
+ import { requiredValue } from "../../../../utils/required-value.js";
1
2
  import path from "node:path";
2
3
 
3
4
  import {
4
- formatSourceViewResults,
5
- renderSourceViewLine,
6
- type SourceMappedTextContent,
7
- type SourceViewBlock,
8
- type SourceViewLine,
5
+ formatSourceViewResults,
6
+ renderSourceViewLine,
7
+ type SourceMappedTextContent,
8
+ type SourceViewBlock,
9
+ type SourceViewLine,
9
10
  } from "pi-agent-ide/api/code-view";
10
11
 
11
12
  import { collectFiles } from "./collect-files.js";
@@ -15,615 +16,554 @@ import { readTextFile } from "./read-text.js";
15
16
  import type * as WTS from "web-tree-sitter";
16
17
 
17
18
  const SUPPORTED_EXTENSIONS = new Set([
18
- ".ts",
19
- ".tsx",
20
- ".js",
21
- ".jsx",
22
- ".mjs",
23
- ".cjs",
24
- ".py",
25
- ".rs",
26
- ".c",
27
- ".cpp",
28
- ".cxx",
29
- ".h",
30
- ".hpp",
31
- ".json",
32
- ".jsonc",
33
- ".yaml",
34
- ".yml",
35
- ".toml",
19
+ ".ts",
20
+ ".tsx",
21
+ ".js",
22
+ ".jsx",
23
+ ".mjs",
24
+ ".cjs",
25
+ ".py",
26
+ ".rs",
27
+ ".c",
28
+ ".cpp",
29
+ ".cxx",
30
+ ".h",
31
+ ".hpp",
32
+ ".json",
33
+ ".jsonc",
34
+ ".yaml",
35
+ ".yml",
36
+ ".toml",
36
37
  ]);
37
38
 
38
39
  const DATA_EXTENSIONS = new Set([".json", ".jsonc", ".yaml", ".yml", ".toml"]);
39
40
 
40
41
  const DECLARATION_TYPES = new Set([
41
- "class_declaration",
42
- "class_definition",
43
- "class_specifier",
44
- "enum_declaration",
45
- "enum_definition",
46
- "enum_item",
47
- "enum_specifier",
48
- "export_statement",
49
- "function_declaration",
50
- "function_definition",
51
- "function_item",
52
- "impl_item",
53
- "interface_declaration",
54
- "lexical_declaration",
55
- "namespace_definition",
56
- "mod_item",
57
- "public_field_definition",
58
- "method_definition",
59
- "method_signature",
60
- "property_signature",
61
- "field_declaration",
62
- "struct_item",
63
- "struct_specifier",
64
- "trait_item",
65
- "type_alias_declaration",
66
- "type_item",
67
- "variable_declaration",
68
- "assignment",
42
+ "class_declaration",
43
+ "class_definition",
44
+ "class_specifier",
45
+ "enum_declaration",
46
+ "enum_definition",
47
+ "enum_item",
48
+ "enum_specifier",
49
+ "export_statement",
50
+ "function_declaration",
51
+ "function_definition",
52
+ "function_item",
53
+ "impl_item",
54
+ "interface_declaration",
55
+ "lexical_declaration",
56
+ "namespace_definition",
57
+ "mod_item",
58
+ "public_field_definition",
59
+ "method_definition",
60
+ "method_signature",
61
+ "property_signature",
62
+ "field_declaration",
63
+ "struct_item",
64
+ "struct_specifier",
65
+ "trait_item",
66
+ "type_alias_declaration",
67
+ "type_item",
68
+ "variable_declaration",
69
+ "assignment",
69
70
  ]);
70
71
 
71
72
  const ROOT_TYPES = new Set(["module", "program", "source_file"]);
72
73
 
73
74
  const IMPORT_TYPES = new Set([
74
- "import_declaration",
75
- "import_from_statement",
76
- "import_statement",
77
- "use_declaration",
75
+ "import_declaration",
76
+ "import_from_statement",
77
+ "import_statement",
78
+ "use_declaration",
78
79
  ]);
79
80
 
80
81
  const FUNCTION_TYPES = new Set([
81
- "arrow_function",
82
- "function_declaration",
83
- "function_definition",
84
- "function_item",
85
- "function_expression",
86
- "method_definition",
82
+ "arrow_function",
83
+ "function_declaration",
84
+ "function_definition",
85
+ "function_item",
86
+ "function_expression",
87
+ "method_definition",
87
88
  ]);
88
89
 
89
- const INITIALIZER_TYPES = new Set([
90
- "public_field_definition",
91
- "variable_declarator",
92
- "assignment",
93
- ]);
90
+ const INITIALIZER_TYPES = new Set(["public_field_definition", "variable_declarator", "assignment"]);
94
91
 
95
92
  const NAME_TYPES = new Set([
96
- "field_identifier",
97
- "identifier",
98
- "property_identifier",
99
- "shorthand_property_identifier_pattern",
100
- "type_identifier",
93
+ "field_identifier",
94
+ "identifier",
95
+ "property_identifier",
96
+ "shorthand_property_identifier_pattern",
97
+ "type_identifier",
101
98
  ]);
102
99
 
103
- interface Replacement
104
- {
105
- readonly start: number;
106
- readonly end: number;
107
- readonly text: string;
108
- readonly lineSourceLines?: readonly (number | undefined)[];
100
+ interface Replacement {
101
+ readonly start: number;
102
+ readonly end: number;
103
+ readonly text: string;
104
+ readonly lineSourceLines?: readonly (number | undefined)[];
109
105
  }
110
106
 
111
- interface ProjectedLine
112
- {
113
- readonly content: string;
114
- readonly sourceLine?: number;
107
+ interface ProjectedLine {
108
+ readonly content: string;
109
+ readonly sourceLine?: number;
115
110
  }
116
111
 
117
- export function isSupportedOutlinePath(filePath: string): boolean
118
- {
119
- return SUPPORTED_EXTENSIONS.has(path.extname(filePath).toLowerCase());
112
+ export function isSupportedOutlinePath(filePath: string): boolean {
113
+ return SUPPORTED_EXTENSIONS.has(path.extname(filePath).toLowerCase());
120
114
  }
121
115
 
122
116
  const PEEK_FORMAT_OPTIONS = {
123
- failureLabel: "PEEK_FAILED",
124
- emptyReason: "no entries to peek.",
125
- recovery: ["Call peek with { peers: [{ path: \"path/to/file.ts\" }, ...] }."],
117
+ failureLabel: "PEEK_FAILED",
118
+ emptyReason: "no entries to peek.",
119
+ recovery: ['Call peek with { peers: [{ path: "path/to/file.ts" }, ...] }.'],
126
120
  } as const;
127
121
 
128
122
  const AST_OUTLINE_FORMAT_OPTIONS = {
129
- failureLabel: "AST_OUTLINE_FAILED",
130
- emptyReason: "no AST outline was produced.",
123
+ failureLabel: "AST_OUTLINE_FAILED",
124
+ emptyReason: "no AST outline was produced.",
131
125
  } as const;
132
126
 
133
- export function formatAstOutline(block: SourceViewBlock): SourceMappedTextContent
134
- {
135
- return formatSourceViewResults([block], AST_OUTLINE_FORMAT_OPTIONS);
127
+ export function formatAstOutline(block: SourceViewBlock): SourceMappedTextContent {
128
+ return formatSourceViewResults([block], AST_OUTLINE_FORMAT_OPTIONS);
136
129
  }
137
130
 
138
- export class AstOutlineManager
139
- {
140
- private readonly fallbackScopeManager = new AstScopeManager();
141
-
142
- public async readFileOutline(filePath: string, cwd: string): Promise<SourceViewBlock>
143
- {
144
- const absolutePath = resolvePath(filePath, cwd);
145
- const displayPath = path.relative(cwd, absolutePath) || absolutePath;
146
-
147
- if (!isSupportedOutlinePath(absolutePath))
148
- {
149
- throw new Error(`AST outline is not supported for ${displayPath}.`);
150
- }
151
-
152
- const snapshot = await readTextFile(absolutePath);
153
- const tree = await parseDocument(absolutePath, cwd, snapshot.lines);
154
-
155
- if (!tree)
156
- {
157
- throw new Error(`No AST parser is available for ${displayPath}.`);
158
- }
159
-
160
- return await this.createSourceViewBlock(
161
- tree.rootNode,
162
- absolutePath,
163
- displayPath,
164
- cwd,
165
- snapshot.lines,
166
- snapshot.content,
167
- path.extname(absolutePath).toLowerCase(),
168
- );
169
- }
131
+ export class AstOutlineManager {
132
+ private readonly fallbackScopeManager = new AstScopeManager();
170
133
 
171
- public async formatFile(filePath: string, cwd: string): Promise<SourceMappedTextContent>
172
- {
173
- const absolutePath = resolvePath(filePath, cwd);
174
- const displayPath = path.relative(cwd, absolutePath) || absolutePath;
175
-
176
- if (!isSupportedOutlinePath(absolutePath))
177
- {
178
- const snapshot = await readTextFile(absolutePath);
179
- return formatSourceViewResults(
180
- [formatUnsupportedSourceBlock(absolutePath, displayPath, snapshot.lines)],
181
- PEEK_FORMAT_OPTIONS,
182
- );
183
- }
184
-
185
- try
186
- {
187
- return formatSourceViewResults([await this.readFileOutline(absolutePath, cwd)], PEEK_FORMAT_OPTIONS);
188
- }
189
- catch (error)
190
- {
191
- const message = error instanceof Error ? error.message : String(error);
192
- return formatSourceViewResults([failedSourceViewBlock(displayPath, message)], PEEK_FORMAT_OPTIONS);
193
- }
194
- }
134
+ public async readFileOutline(filePath: string, cwd: string): Promise<SourceViewBlock> {
135
+ const absolutePath = resolvePath(filePath, cwd);
136
+ const displayPath = path.relative(cwd, absolutePath) || absolutePath;
195
137
 
196
- public async formatSymbol(symbol: string, cwd: string): Promise<SourceMappedTextContent>
197
- {
198
- const files = await collectFiles(cwd);
199
- const supportedFiles = files
200
- .filter((filePath) => isSupportedOutlinePath(filePath))
201
- .sort();
202
-
203
- for (const filePath of supportedFiles)
204
- {
205
- let snapshot;
206
-
207
- try
208
- {
209
- snapshot = await readTextFile(filePath);
210
- }
211
- catch
212
- {
213
- continue;
214
- }
215
-
216
- let tree;
217
-
218
- try
219
- {
220
- tree = await parseDocument(filePath, cwd, snapshot.lines);
221
- }
222
- catch
223
- {
224
- continue;
225
- }
226
-
227
- if (!tree)
228
- {
229
- continue;
230
- }
231
-
232
- const match = findSymbol(tree.rootNode, symbol);
233
-
234
- if (!match)
235
- {
236
- continue;
237
- }
238
-
239
- const displayPath = path.relative(cwd, filePath) || filePath;
240
- const block = await this.createSourceViewBlock(
241
- match,
242
- filePath,
243
- displayPath,
244
- cwd,
245
- snapshot.lines,
246
- snapshot.content,
247
- path.extname(filePath).toLowerCase(),
248
- symbol,
249
- [`defined in: ${displayPath}:${match.startPosition.row + 1}`],
250
- );
251
- return formatSourceViewResults([block], PEEK_FORMAT_OPTIONS);
252
- }
253
-
254
- return formatSourceViewResults(
255
- [failedSourceViewBlock("", `symbol not found: ${symbol}`, "PEEK_NOT_FOUND")],
256
- PEEK_FORMAT_OPTIONS,
257
- );
138
+ if (!isSupportedOutlinePath(absolutePath)) {
139
+ throw new Error(`AST outline is not supported for ${displayPath}.`);
258
140
  }
259
141
 
260
- private async createSourceViewBlock(
261
- node: WTS.Node,
262
- filePath: string,
263
- displayPath: string,
264
- cwd: string,
265
- sourceLines: readonly string[],
266
- source: string,
267
- extension: string,
268
- heading?: string,
269
- details?: readonly string[],
270
- ): Promise<SourceViewBlock>
271
- {
272
- const projectedLines = renderNodeLines(node, source, extension);
273
- const scopes = await getOutlineScopes(this.fallbackScopeManager, filePath, cwd, sourceLines);
274
- const markersByLine = buildScopeMarkers(scopes);
275
- const renderedLines = projectedLines.map((line) =>
276
- {
277
- const sourceLineNumber = line.sourceLine;
278
- const sourceContent = sourceLineNumber === undefined ? undefined : sourceLines[sourceLineNumber - 1] ?? "";
279
- const markers = sourceLineNumber === undefined ? undefined : markersByLine.get(sourceLineNumber);
280
- const suffix = markers?.map((marker) => ` <!-- ${marker} -->`).join("") ?? "";
281
-
282
- return renderSourceViewLine({
283
- content: line.content,
284
- ...(sourceLineNumber === undefined || sourceContent === undefined
285
- ? {}
286
- : {
287
- sourceLine: {
288
- source: filePath,
289
- lineNumber: sourceLineNumber,
290
- content: sourceContent,
291
- },
292
- }),
293
- ...(suffix.length === 0 ? {} : { suffix }),
294
- } satisfies SourceViewLine);
295
- });
142
+ const snapshot = await readTextFile(absolutePath);
143
+ const tree = await parseDocument(absolutePath, cwd, snapshot.lines);
296
144
 
297
- return {
298
- path: displayPath,
299
- ...(heading === undefined ? {} : { heading }),
300
- ...(details === undefined ? {} : { details }),
301
- startLine: node.startPosition.row + 1,
302
- endLine: node.endPosition.row + 1,
303
- totalLines: sourceLines.length,
304
- renderedLines,
305
- };
145
+ if (!tree) {
146
+ throw new Error(`No AST parser is available for ${displayPath}.`);
306
147
  }
307
- }
308
148
 
309
- function formatUnsupportedSourceBlock(
310
- sourcePath: string,
149
+ return await this.createSourceViewBlock(
150
+ tree.rootNode,
151
+ absolutePath,
152
+ displayPath,
153
+ cwd,
154
+ snapshot.lines,
155
+ snapshot.content,
156
+ path.extname(absolutePath).toLowerCase(),
157
+ );
158
+ }
159
+
160
+ public async formatFile(filePath: string, cwd: string): Promise<SourceMappedTextContent> {
161
+ const absolutePath = resolvePath(filePath, cwd);
162
+ const displayPath = path.relative(cwd, absolutePath) || absolutePath;
163
+
164
+ if (!isSupportedOutlinePath(absolutePath)) {
165
+ const snapshot = await readTextFile(absolutePath);
166
+ return formatSourceViewResults(
167
+ [formatUnsupportedSourceBlock(absolutePath, displayPath, snapshot.lines)],
168
+ PEEK_FORMAT_OPTIONS,
169
+ );
170
+ }
171
+
172
+ try {
173
+ return formatSourceViewResults(
174
+ [await this.readFileOutline(absolutePath, cwd)],
175
+ PEEK_FORMAT_OPTIONS,
176
+ );
177
+ } catch (error) {
178
+ const message = error instanceof Error ? error.message : String(error);
179
+ return formatSourceViewResults(
180
+ [failedSourceViewBlock(displayPath, message)],
181
+ PEEK_FORMAT_OPTIONS,
182
+ );
183
+ }
184
+ }
185
+
186
+ public async formatSymbol(symbol: string, cwd: string): Promise<SourceMappedTextContent> {
187
+ const files = await collectFiles(cwd);
188
+ const supportedFiles = files.filter((filePath) => isSupportedOutlinePath(filePath)).sort();
189
+
190
+ for (const filePath of supportedFiles) {
191
+ let snapshot;
192
+
193
+ try {
194
+ snapshot = await readTextFile(filePath);
195
+ } catch {
196
+ continue;
197
+ }
198
+
199
+ let tree;
200
+
201
+ try {
202
+ tree = await parseDocument(filePath, cwd, snapshot.lines);
203
+ } catch {
204
+ continue;
205
+ }
206
+
207
+ if (!tree) {
208
+ continue;
209
+ }
210
+
211
+ const match = findSymbol(tree.rootNode, symbol);
212
+
213
+ if (!match) {
214
+ continue;
215
+ }
216
+
217
+ const displayPath = path.relative(cwd, filePath) || filePath;
218
+ const block = await this.createSourceViewBlock(
219
+ match,
220
+ filePath,
221
+ displayPath,
222
+ cwd,
223
+ snapshot.lines,
224
+ snapshot.content,
225
+ path.extname(filePath).toLowerCase(),
226
+ symbol,
227
+ [`defined in: ${displayPath}:${match.startPosition.row + 1}`],
228
+ );
229
+ return formatSourceViewResults([block], PEEK_FORMAT_OPTIONS);
230
+ }
231
+
232
+ return formatSourceViewResults(
233
+ [failedSourceViewBlock("", `symbol not found: ${symbol}`, "PEEK_NOT_FOUND")],
234
+ PEEK_FORMAT_OPTIONS,
235
+ );
236
+ }
237
+
238
+ private async createSourceViewBlock(
239
+ node: WTS.Node,
240
+ filePath: string,
311
241
  displayPath: string,
242
+ cwd: string,
312
243
  sourceLines: readonly string[],
313
- ): SourceViewBlock
314
- {
315
- return {
316
- path: displayPath,
317
- startLine: sourceLines.length > 0 ? 1 : 0,
318
- endLine: sourceLines.length,
319
- totalLines: sourceLines.length,
320
- renderedLines: sourceLines.map((content, index) =>
321
- renderSourceViewLine({
322
- content,
323
- sourceLine: {
324
- source: sourcePath,
325
- lineNumber: index + 1,
326
- content,
327
- },
328
- })
329
- ),
330
- };
331
- }
244
+ source: string,
245
+ extension: string,
246
+ heading?: string,
247
+ details?: readonly string[],
248
+ ): Promise<SourceViewBlock> {
249
+ const projectedLines = renderNodeLines(node, source, extension);
250
+ const scopes = await getOutlineScopes(this.fallbackScopeManager, filePath, cwd, sourceLines);
251
+ const markersByLine = buildScopeMarkers(scopes);
252
+ const renderedLines = projectedLines.map((line) => {
253
+ const sourceLineNumber = line.sourceLine;
254
+ const sourceContent =
255
+ sourceLineNumber === undefined ? undefined : (sourceLines[sourceLineNumber - 1] ?? "");
256
+ const markers =
257
+ sourceLineNumber === undefined ? undefined : markersByLine.get(sourceLineNumber);
258
+ const suffix = markers?.map((marker) => ` <!-- ${marker} -->`).join("") ?? "";
259
+
260
+ return renderSourceViewLine({
261
+ content: line.content,
262
+ ...(!(sourceLineNumber === undefined || sourceContent === undefined) && {
263
+ sourceLine: {
264
+ source: filePath,
265
+ lineNumber: sourceLineNumber,
266
+ content: sourceContent,
267
+ },
268
+ }),
269
+ ...(suffix.length > 0 && { suffix }),
270
+ } satisfies SourceViewLine);
271
+ });
332
272
 
333
- function failedSourceViewBlock(path: string, error: string, code = "PEEK_FAILED"): SourceViewBlock
334
- {
335
273
  return {
336
- path,
337
- startLine: 0,
338
- endLine: 0,
339
- totalLines: 0,
340
- renderedLines: [],
341
- status: "failed",
342
- error,
343
- code,
274
+ path: displayPath,
275
+ ...(heading !== undefined && { heading }),
276
+ ...(details !== undefined && { details }),
277
+ startLine: node.startPosition.row + 1,
278
+ endLine: node.endPosition.row + 1,
279
+ totalLines: sourceLines.length,
280
+ renderedLines,
344
281
  };
282
+ }
345
283
  }
346
284
 
347
- function getOutlineScopes(
348
- fallback: AstScopeManager,
349
- filePath: string,
350
- cwd: string,
351
- lines: readonly string[],
352
- ): Promise<ScopeEntry[]>
353
- {
354
- return fallback.getDocumentScopes(filePath, cwd, lines);
285
+ function formatUnsupportedSourceBlock(
286
+ sourcePath: string,
287
+ displayPath: string,
288
+ sourceLines: readonly string[],
289
+ ): SourceViewBlock {
290
+ return {
291
+ path: displayPath,
292
+ startLine: sourceLines.length > 0 ? 1 : 0,
293
+ endLine: sourceLines.length,
294
+ totalLines: sourceLines.length,
295
+ renderedLines: sourceLines.map((content, index) =>
296
+ renderSourceViewLine({
297
+ content,
298
+ sourceLine: {
299
+ source: sourcePath,
300
+ lineNumber: index + 1,
301
+ content,
302
+ },
303
+ }),
304
+ ),
305
+ };
355
306
  }
356
307
 
357
- function buildScopeMarkers(scopes: readonly ScopeEntry[]): Map<number, string[]>
358
- {
359
- const markers = new Map<number, string[]>();
308
+ function failedSourceViewBlock(path: string, error: string, code = "PEEK_FAILED"): SourceViewBlock {
309
+ return {
310
+ path,
311
+ startLine: 0,
312
+ endLine: 0,
313
+ totalLines: 0,
314
+ renderedLines: [],
315
+ status: "failed",
316
+ error,
317
+ code,
318
+ };
319
+ }
360
320
 
361
- for (const scope of scopes)
362
- {
363
- const begin = markers.get(scope.startLine) ?? [];
364
- begin.push(scope.beginAnchor.value);
365
- markers.set(scope.startLine, begin);
321
+ function getOutlineScopes(
322
+ fallback: AstScopeManager,
323
+ filePath: string,
324
+ cwd: string,
325
+ lines: readonly string[],
326
+ ): Promise<ScopeEntry[]> {
327
+ return fallback.getDocumentScopes(filePath, cwd, lines);
328
+ }
366
329
 
367
- const end = markers.get(scope.endLine) ?? [];
368
- end.push(scope.endScopeAnchor.value);
369
- markers.set(scope.endLine, end);
370
- }
330
+ function buildScopeMarkers(scopes: readonly ScopeEntry[]): Map<number, string[]> {
331
+ const markers = new Map<number, string[]>();
371
332
 
372
- return markers;
373
- }
333
+ for (const scope of scopes) {
334
+ const begin = markers.get(scope.startLine) ?? [];
335
+ begin.push(scope.beginAnchor.value);
336
+ markers.set(scope.startLine, begin);
374
337
 
375
- function resolvePath(filePath: string, cwd: string): string
376
- {
377
- if (filePath.startsWith("file://"))
378
- {
379
- return decodeURIComponent(filePath.slice("file://".length));
380
- }
338
+ const end = markers.get(scope.endLine) ?? [];
339
+ end.push(scope.endScopeAnchor.value);
340
+ markers.set(scope.endLine, end);
341
+ }
381
342
 
382
- return path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
343
+ return markers;
383
344
  }
384
345
 
385
- function findSymbol(root: WTS.Node, symbol: string): WTS.Node | undefined
386
- {
387
- let result: WTS.Node | undefined;
388
-
389
- const visit = (node: WTS.Node): void =>
390
- {
391
- if (result)
392
- {
393
- return;
394
- }
395
-
396
- if (DECLARATION_TYPES.has(node.type) && getNodeName(node) === symbol)
397
- {
398
- result = unwrapDeclaration(node);
399
- return;
400
- }
401
-
402
- for (const child of node.namedChildren)
403
- {
404
- visit(child);
405
- }
406
- };
346
+ function resolvePath(filePath: string, cwd: string): string {
347
+ if (filePath.startsWith("file://")) {
348
+ return decodeURIComponent(filePath.slice("file://".length));
349
+ }
407
350
 
408
- visit(root);
409
- return result;
351
+ return path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
410
352
  }
411
353
 
412
- function getNodeName(node: WTS.Node): string | undefined
413
- {
414
- const nameField = node.childForFieldName("name");
354
+ function findSymbol(root: WTS.Node, symbol: string): WTS.Node | undefined {
355
+ let result: WTS.Node | undefined;
415
356
 
416
- if (nameField && NAME_TYPES.has(nameField.type))
417
- {
418
- return nameField.text;
357
+ const visit = (node: WTS.Node): void => {
358
+ if (result) {
359
+ return;
419
360
  }
420
361
 
421
- for (const child of node.namedChildren)
422
- {
423
- if (NAME_TYPES.has(child.type))
424
- {
425
- return child.text;
426
- }
362
+ if (DECLARATION_TYPES.has(node.type) && getNodeName(node) === symbol) {
363
+ result = unwrapDeclaration(node);
364
+ return;
427
365
  }
428
366
 
429
- if (node.type === "lexical_declaration" || node.type === "variable_declaration")
430
- {
431
- const declarator = node.namedChildren.find((child) => child.type === "variable_declarator");
432
- const name = declarator?.childForFieldName("name");
433
- return name?.text;
367
+ for (const child of node.namedChildren) {
368
+ visit(child);
434
369
  }
370
+ };
435
371
 
436
- if (node.type === "function_definition")
437
- {
438
- const declarator = node.childForFieldName("declarator");
439
- return declarator ? findNestedName(declarator) : undefined;
440
- }
441
-
442
- return undefined;
372
+ visit(root);
373
+ return result;
443
374
  }
444
375
 
445
- function findNestedName(node: WTS.Node): string | undefined
446
- {
447
- if (NAME_TYPES.has(node.type))
448
- {
449
- return node.text;
450
- }
376
+ function getNodeName(node: WTS.Node): string | undefined {
377
+ const nameField = node.childForFieldName("name");
451
378
 
452
- for (const child of node.namedChildren)
453
- {
454
- const name = findNestedName(child);
379
+ if (nameField && NAME_TYPES.has(nameField.type)) {
380
+ return nameField.text;
381
+ }
455
382
 
456
- if (name)
457
- {
458
- return name;
459
- }
383
+ for (const child of node.namedChildren) {
384
+ if (NAME_TYPES.has(child.type)) {
385
+ return child.text;
460
386
  }
387
+ }
461
388
 
462
- return undefined;
463
- }
389
+ if (node.type === "lexical_declaration" || node.type === "variable_declaration") {
390
+ const declarator = node.namedChildren.find((child) => child.type === "variable_declarator");
391
+ const name = declarator?.childForFieldName("name");
392
+ return name?.text;
393
+ }
464
394
 
465
- function unwrapDeclaration(node: WTS.Node): WTS.Node
466
- {
467
- const parent = node.parent;
468
-
469
- if (
470
- parent
471
- && (parent.type === "export_statement" || parent.type === "decorated_definition"
472
- || parent.type === "template_declaration")
473
- )
474
- {
475
- return parent;
476
- }
395
+ if (node.type === "function_definition") {
396
+ const declarator = node.childForFieldName("declarator");
397
+ return declarator ? findNestedName(declarator) : undefined;
398
+ }
477
399
 
478
- return node;
400
+ return undefined;
479
401
  }
480
402
 
481
- interface MappedCharacter
482
- {
483
- readonly char: string;
484
- readonly sourceLine?: number;
485
- }
403
+ function findNestedName(node: WTS.Node): string | undefined {
404
+ if (NAME_TYPES.has(node.type)) {
405
+ return node.text;
406
+ }
486
407
 
487
- function renderNodeLines(node: WTS.Node, source: string, extension: string): ProjectedLine[]
488
- {
489
- const replacements: Replacement[] = [];
408
+ for (const child of node.namedChildren) {
409
+ const name = findNestedName(child);
490
410
 
491
- if (DATA_EXTENSIONS.has(extension))
492
- {
493
- collectDataReplacements(node, extension, replacements);
494
- }
495
- else
496
- {
497
- collectReplacements(node, extension, replacements);
411
+ if (name) {
412
+ return name;
498
413
  }
414
+ }
499
415
 
500
- const start = lineStartAt(source, node.startIndex);
501
- const end = lineEndAt(source, node.endIndex);
502
- const relevant = replacements
503
- .filter((replacement) => replacement.start >= start && replacement.end <= end)
504
- .sort((a, b) => b.start - a.start);
505
- const mapped = mapSourceRange(source, start, end);
506
-
507
- for (const replacement of relevant)
508
- {
509
- const relativeStart = replacement.start - start;
510
- const relativeEnd = replacement.end - start;
511
- const inserted = mapReplacement(replacement);
512
- mapped.splice(relativeStart, relativeEnd - relativeStart, ...inserted);
513
- }
416
+ return undefined;
417
+ }
514
418
 
515
- while (mapped.length > 0 && /\s/u.test(mapped.at(-1)!.char))
516
- {
517
- mapped.pop();
518
- }
419
+ function unwrapDeclaration(node: WTS.Node): WTS.Node {
420
+ const parent = node.parent;
519
421
 
520
- const lines: MappedCharacter[][] = [[]];
521
-
522
- for (const item of mapped)
523
- {
524
- if (item.char === "\n")
525
- {
526
- lines.push([]);
527
- }
528
- else
529
- {
530
- lines.at(-1)!.push(item);
531
- }
532
- }
422
+ if (
423
+ parent &&
424
+ (parent.type === "export_statement" ||
425
+ parent.type === "decorated_definition" ||
426
+ parent.type === "template_declaration")
427
+ ) {
428
+ return parent;
429
+ }
533
430
 
534
- return lines.map((line) =>
535
- {
536
- const sourceLines = [
537
- ...new Set(line.flatMap((item) => item.sourceLine === undefined ? [] : [item.sourceLine])),
538
- ];
539
- return {
540
- content: line.map((item) => item.char).join(""),
541
- ...(sourceLines.length === 1 ? { sourceLine: sourceLines[0] } : {}),
542
- };
543
- });
431
+ return node;
432
+ }
433
+
434
+ interface MappedCharacter {
435
+ readonly char: string;
436
+ readonly sourceLine?: number;
437
+ }
438
+
439
+ function renderNodeLines(node: WTS.Node, source: string, extension: string): ProjectedLine[] {
440
+ const replacements: Replacement[] = [];
441
+
442
+ if (DATA_EXTENSIONS.has(extension)) {
443
+ collectDataReplacements(node, extension, replacements);
444
+ } else {
445
+ collectReplacements(node, extension, replacements);
446
+ }
447
+
448
+ const start = lineStartAt(source, node.startIndex);
449
+ const end = lineEndAt(source, node.endIndex);
450
+ const relevant = replacements
451
+ .filter((replacement) => replacement.start >= start && replacement.end <= end)
452
+ .sort((a, b) => b.start - a.start);
453
+ const mapped = mapSourceRange(source, start, end);
454
+
455
+ for (const replacement of relevant) {
456
+ const relativeStart = replacement.start - start;
457
+ const relativeEnd = replacement.end - start;
458
+ const inserted = mapReplacement(replacement);
459
+ mapped.splice(relativeStart, relativeEnd - relativeStart, ...inserted);
460
+ }
461
+
462
+ while (mapped.length > 0 && /\s/u.test(requiredValue(mapped.at(-1)).char)) {
463
+ mapped.pop();
464
+ }
465
+
466
+ const lines: MappedCharacter[][] = [[]];
467
+
468
+ for (const item of mapped) {
469
+ if (item.char === "\n") {
470
+ lines.push([]);
471
+ } else {
472
+ requiredValue(lines.at(-1)).push(item);
473
+ }
474
+ }
475
+
476
+ return lines.map((line) => {
477
+ const sourceLines = [
478
+ ...new Set(line.flatMap((item) => (item.sourceLine === undefined ? [] : [item.sourceLine]))),
479
+ ];
480
+ return {
481
+ content: line.map((item) => item.char).join(""),
482
+ ...(sourceLines.length === 1 && { sourceLine: sourceLines[0] }),
483
+ };
484
+ });
544
485
  }
545
486
 
546
- function lineStartAt(source: string, index: number): number
547
- {
548
- const newline = source.lastIndexOf("\n", Math.max(0, index - 1));
549
- return newline + 1;
487
+ function lineStartAt(source: string, index: number): number {
488
+ const newline = source.lastIndexOf("\n", Math.max(0, index - 1));
489
+ return newline + 1;
550
490
  }
551
491
 
552
- function lineEndAt(source: string, index: number): number
553
- {
554
- const newline = source.indexOf("\n", index);
555
- return newline === -1 ? source.length : newline;
492
+ function lineEndAt(source: string, index: number): number {
493
+ const newline = source.indexOf("\n", index);
494
+ return newline === -1 ? source.length : newline;
556
495
  }
557
496
 
558
- function mapSourceRange(source: string, start: number, end: number): MappedCharacter[]
559
- {
560
- let sourceLine = source.slice(0, start).split("\n").length;
561
- const mapped: MappedCharacter[] = [];
497
+ function mapSourceRange(source: string, start: number, end: number): MappedCharacter[] {
498
+ let sourceLine = source.slice(0, start).split("\n").length;
499
+ const mapped: MappedCharacter[] = [];
562
500
 
563
- for (const char of source.slice(start, end))
564
- {
565
- mapped.push({ char, sourceLine });
501
+ for (const char of source.slice(start, end)) {
502
+ mapped.push({ char, sourceLine });
566
503
 
567
- if (char === "\n")
568
- {
569
- sourceLine += 1;
570
- }
504
+ if (char === "\n") {
505
+ sourceLine += 1;
571
506
  }
507
+ }
572
508
 
573
- return mapped;
509
+ return mapped;
574
510
  }
575
511
 
576
- function mapReplacement(replacement: Replacement): MappedCharacter[]
577
- {
578
- const lineSources = replacement.lineSourceLines ?? [];
579
- let lineIndex = 0;
512
+ function mapReplacement(replacement: Replacement): MappedCharacter[] {
513
+ const lineSources = replacement.lineSourceLines ?? [];
514
+ let lineIndex = 0;
580
515
 
581
- const mapped: MappedCharacter[] = [];
516
+ const mapped: MappedCharacter[] = [];
582
517
 
583
- for (let index = 0; index < replacement.text.length; index += 1)
584
- {
585
- const char = replacement.text[index]!;
586
- const sourceLine = lineSources[lineIndex];
587
- mapped.push(sourceLine === undefined ? { char } : { char, sourceLine });
518
+ for (let index = 0; index < replacement.text.length; index += 1) {
519
+ const char = requiredValue(replacement.text[index]);
520
+ const sourceLine = lineSources[lineIndex];
521
+ mapped.push(sourceLine === undefined ? { char } : { char, sourceLine });
588
522
 
589
- if (char === "\n")
590
- {
591
- lineIndex += 1;
592
- }
523
+ if (char === "\n") {
524
+ lineIndex += 1;
593
525
  }
526
+ }
594
527
 
595
- return mapped;
528
+ return mapped;
596
529
  }
597
530
 
598
- function collectDataReplacements(node: WTS.Node, extension: string, replacements: Replacement[]): void
599
- {
600
- for (const child of node.namedChildren)
601
- {
602
- if (isDataScalar(child, extension))
603
- {
604
- if (!isDataKey(child))
605
- {
606
- replacements.push({
607
- start: child.startIndex,
608
- end: child.endIndex,
609
- text: "…",
610
- lineSourceLines: [child.startPosition.row + 1],
611
- });
612
- }
613
-
614
- continue;
615
- }
616
-
617
- collectDataReplacements(child, extension, replacements);
531
+ function collectDataReplacements(
532
+ node: WTS.Node,
533
+ extension: string,
534
+ replacements: Replacement[],
535
+ ): void {
536
+ for (const child of node.namedChildren) {
537
+ if (isDataScalar(child, extension)) {
538
+ if (!isDataKey(child)) {
539
+ replacements.push({
540
+ start: child.startIndex,
541
+ end: child.endIndex,
542
+ text: "…",
543
+ lineSourceLines: [child.startPosition.row + 1],
544
+ });
545
+ }
546
+
547
+ continue;
618
548
  }
549
+
550
+ collectDataReplacements(child, extension, replacements);
551
+ }
619
552
  }
620
553
 
621
- function isDataScalar(node: WTS.Node, extension: string): boolean
622
- {
623
- const scalarTypes = extension === ".json" || extension === ".jsonc"
624
- ? ["string", "number", "true", "false", "null"]
625
- : extension === ".yaml" || extension === ".yml"
626
- ? ["string_scalar", "integer_scalar", "float_scalar", "boolean_scalar", "null_scalar", "block_scalar"]
554
+ function isDataScalar(node: WTS.Node, extension: string): boolean {
555
+ const scalarTypes =
556
+ extension === ".json" || extension === ".jsonc"
557
+ ? ["string", "number", "true", "false", "null"]
558
+ : extension === ".yaml" || extension === ".yml"
559
+ ? [
560
+ "string_scalar",
561
+ "integer_scalar",
562
+ "float_scalar",
563
+ "boolean_scalar",
564
+ "null_scalar",
565
+ "block_scalar",
566
+ ]
627
567
  : [
628
568
  "string",
629
569
  "integer",
@@ -634,180 +574,175 @@ function isDataScalar(node: WTS.Node, extension: string): boolean
634
574
  "local_date_time",
635
575
  "local_date",
636
576
  "local_time",
637
- ];
577
+ ];
638
578
 
639
- return scalarTypes.includes(node.type);
579
+ return scalarTypes.includes(node.type);
640
580
  }
641
581
 
642
- function isDataKey(node: WTS.Node): boolean
643
- {
644
- let ancestor = node.parent;
582
+ function isDataKey(node: WTS.Node): boolean {
583
+ let ancestor = node.parent;
645
584
 
646
- while (ancestor && !ancestor.type.endsWith("pair") && ancestor.type !== "pair" && ancestor.type !== "table")
647
- {
648
- ancestor = ancestor.parent;
649
- }
585
+ while (
586
+ ancestor &&
587
+ !ancestor.type.endsWith("pair") &&
588
+ ancestor.type !== "pair" &&
589
+ ancestor.type !== "table"
590
+ ) {
591
+ ancestor = ancestor.parent;
592
+ }
650
593
 
651
- const key = ancestor?.namedChildren[0];
652
- return key !== undefined && key.startIndex <= node.startIndex && key.endIndex >= node.endIndex;
594
+ const key = ancestor?.namedChildren[0];
595
+ return key !== undefined && key.startIndex <= node.startIndex && key.endIndex >= node.endIndex;
653
596
  }
654
597
 
655
598
  function collectReplacements(
656
- node: WTS.Node,
657
- extension: string,
658
- replacements: Replacement[],
659
- topLevel = false,
660
- ): void
661
- {
662
- if (topLevel && !isTopLevelInterfaceNode(node))
663
- {
664
- replacements.push({
665
- start: node.startIndex,
666
- end: node.endIndex,
667
- text: "…",
668
- lineSourceLines: [node.startPosition.row + 1],
669
- });
670
- return;
671
- }
672
-
673
- if (FUNCTION_TYPES.has(node.type))
674
- {
675
- const body = findBody(node);
676
-
677
- if (body)
678
- {
679
- const placeholder = renderBodyPlaceholder(body, extension);
680
- replacements.push({
681
- start: body.startIndex,
682
- end: body.endIndex,
683
- text: placeholder.text,
684
- lineSourceLines: placeholder.lineSourceLines,
685
- });
686
- return;
687
- }
688
- }
689
-
690
- if (INITIALIZER_TYPES.has(node.type))
691
- {
692
- const value = node.childForFieldName("value");
693
-
694
- if (value && !FUNCTION_TYPES.has(value.type))
695
- {
696
- replacements.push({
697
- start: value.startIndex,
698
- end: value.endIndex,
699
- text: "…",
700
- lineSourceLines: [value.startPosition.row + 1],
701
- });
702
- return;
703
- }
704
- }
705
-
706
- for (const child of node.namedChildren)
707
- {
708
- collectReplacements(child, extension, replacements, ROOT_TYPES.has(node.type));
709
- }
599
+ node: WTS.Node,
600
+ extension: string,
601
+ replacements: Replacement[],
602
+ topLevel = false,
603
+ ): void {
604
+ if (topLevel && !isTopLevelInterfaceNode(node)) {
605
+ replacements.push({
606
+ start: node.startIndex,
607
+ end: node.endIndex,
608
+ text: "…",
609
+ lineSourceLines: [node.startPosition.row + 1],
610
+ });
611
+ return;
612
+ }
613
+
614
+ if (FUNCTION_TYPES.has(node.type)) {
615
+ const body = findBody(node);
616
+
617
+ if (body) {
618
+ const placeholder = renderBodyPlaceholder(body, extension);
619
+ replacements.push({
620
+ start: body.startIndex,
621
+ end: body.endIndex,
622
+ text: placeholder.text,
623
+ lineSourceLines: placeholder.lineSourceLines,
624
+ });
625
+ return;
626
+ }
627
+ }
628
+
629
+ if (INITIALIZER_TYPES.has(node.type)) {
630
+ const value = node.childForFieldName("value");
631
+
632
+ if (value && !FUNCTION_TYPES.has(value.type)) {
633
+ replacements.push({
634
+ start: value.startIndex,
635
+ end: value.endIndex,
636
+ text: "…",
637
+ lineSourceLines: [value.startPosition.row + 1],
638
+ });
639
+ return;
640
+ }
641
+ }
642
+
643
+ for (const child of node.namedChildren) {
644
+ collectReplacements(child, extension, replacements, ROOT_TYPES.has(node.type));
645
+ }
710
646
  }
711
647
 
712
- function isTopLevelInterfaceNode(node: WTS.Node): boolean
713
- {
714
- return DECLARATION_TYPES.has(node.type)
715
- || IMPORT_TYPES.has(node.type)
716
- || node.type === "comment"
717
- || node.type.startsWith("preproc");
648
+ function isTopLevelInterfaceNode(node: WTS.Node): boolean {
649
+ return (
650
+ DECLARATION_TYPES.has(node.type) ||
651
+ IMPORT_TYPES.has(node.type) ||
652
+ node.type === "comment" ||
653
+ node.type.startsWith("preproc")
654
+ );
718
655
  }
719
656
 
720
- function findBody(node: WTS.Node): WTS.Node | undefined
721
- {
722
- const fieldBody = node.childForFieldName("body");
657
+ function findBody(node: WTS.Node): WTS.Node | undefined {
658
+ const fieldBody = node.childForFieldName("body");
723
659
 
724
- if (fieldBody)
725
- {
726
- return fieldBody;
727
- }
660
+ if (fieldBody) {
661
+ return fieldBody;
662
+ }
728
663
 
729
- return node.namedChildren.find((child) =>
730
- child.type === "block" || child.type === "compound_statement" || child.type === "statement_block"
731
- );
664
+ return node.namedChildren.find(
665
+ (child) =>
666
+ child.type === "block" ||
667
+ child.type === "compound_statement" ||
668
+ child.type === "statement_block",
669
+ );
732
670
  }
733
671
 
734
- interface BodyPlaceholder
735
- {
736
- readonly text: string;
737
- readonly lineSourceLines: readonly (number | undefined)[];
672
+ interface BodyPlaceholder {
673
+ readonly text: string;
674
+ readonly lineSourceLines: readonly (number | undefined)[];
738
675
  }
739
676
 
740
- function renderBodyPlaceholder(body: WTS.Node, extension: string): BodyPlaceholder
741
- {
742
- const startLine = body.startPosition.row + 1;
743
- const endLine = body.endPosition.row + 1;
677
+ function renderBodyPlaceholder(body: WTS.Node, extension: string): BodyPlaceholder {
678
+ const startLine = body.startPosition.row + 1;
679
+ const endLine = body.endPosition.row + 1;
744
680
 
745
- if (extension === ".py")
746
- {
747
- return { text: "...", lineSourceLines: [startLine] };
748
- }
681
+ if (extension === ".py") {
682
+ return { text: "...", lineSourceLines: [startLine] };
683
+ }
749
684
 
750
- const bodyLines = body.text.split("\n");
751
- const firstLine = bodyLines[0] ?? "";
752
- const lastLine = bodyLines.at(-1) ?? "";
753
- const openIndex = firstLine.indexOf("{");
754
- const closeIndex = lastLine.lastIndexOf("}");
685
+ const bodyLines = body.text.split("\n");
686
+ const firstLine = bodyLines[0] ?? "";
687
+ const lastLine = bodyLines.at(-1) ?? "";
688
+ const openIndex = firstLine.indexOf("{");
689
+ const closeIndex = lastLine.lastIndexOf("}");
755
690
 
756
- if (openIndex === -1 || closeIndex === -1)
757
- {
758
- return { text: "…", lineSourceLines: [startLine] };
759
- }
691
+ if (openIndex === -1 || closeIndex === -1) {
692
+ return { text: "…", lineSourceLines: [startLine] };
693
+ }
760
694
 
761
- if (bodyLines.length === 1)
762
- {
763
- const inner = firstLine.slice(openIndex + 1, closeIndex);
695
+ if (bodyLines.length === 1) {
696
+ const inner = firstLine.slice(openIndex + 1, closeIndex);
764
697
 
765
- if (inner.trim() === "")
766
- {
767
- return { text: body.text, lineSourceLines: [startLine] };
768
- }
769
-
770
- return {
771
- text: firstLine.slice(0, openIndex + 1) + maskSegment(inner) + firstLine.slice(closeIndex),
772
- lineSourceLines: [startLine],
773
- };
774
- }
775
-
776
- const afterOpen = firstLine.slice(openIndex + 1);
777
- const beforeClose = lastLine.slice(0, closeIndex);
778
- const interiorHasContent = bodyLines.slice(1, -1).some((line) => line.trim() !== "");
779
- const firstHasContent = afterOpen.trim() !== "";
780
- const lastHasContent = beforeClose.trim() !== "";
781
-
782
- if (!interiorHasContent && !firstHasContent && !lastHasContent)
783
- {
784
- return {
785
- text: body.text,
786
- lineSourceLines: bodyLines.map((_, index) => startLine + index),
787
- };
698
+ if (inner.trim() === "") {
699
+ return { text: body.text, lineSourceLines: [startLine] };
788
700
  }
789
701
 
790
- const output: string[] = [];
791
- const lineSourceLines: (number | undefined)[] = [];
792
- output.push(firstHasContent ? firstLine.slice(0, openIndex + 1) + maskSegment(afterOpen) : firstLine);
793
- lineSourceLines.push(startLine);
794
-
795
- if (!firstHasContent && interiorHasContent)
796
- {
797
- const indentation = bodyLines.slice(1, -1).find((line) => line.trim() !== "")?.match(/^\s*/u)?.[0] ?? "";
798
- output.push(`${indentation}…`);
799
- lineSourceLines.push(undefined);
800
- }
702
+ return {
703
+ text: firstLine.slice(0, openIndex + 1) + maskSegment(inner) + firstLine.slice(closeIndex),
704
+ lineSourceLines: [startLine],
705
+ };
706
+ }
801
707
 
802
- output.push(lastHasContent ? maskSegment(beforeClose) + lastLine.slice(closeIndex) : lastLine);
803
- lineSourceLines.push(endLine);
708
+ const afterOpen = firstLine.slice(openIndex + 1);
709
+ const beforeClose = lastLine.slice(0, closeIndex);
710
+ const isInteriorHasContent = bodyLines.slice(1, -1).some((line) => line.trim() !== "");
711
+ const isFirstHasContent = afterOpen.trim() !== "";
712
+ const isLastHasContent = beforeClose.trim() !== "";
804
713
 
805
- return { text: output.join("\n"), lineSourceLines };
714
+ if (!isInteriorHasContent && !isFirstHasContent && !isLastHasContent) {
715
+ return {
716
+ text: body.text,
717
+ lineSourceLines: bodyLines.map((_, index) => startLine + index),
718
+ };
719
+ }
720
+
721
+ const output: string[] = [];
722
+ const lineSourceLines: (number | undefined)[] = [];
723
+ output.push(
724
+ isFirstHasContent ? firstLine.slice(0, openIndex + 1) + maskSegment(afterOpen) : firstLine,
725
+ );
726
+ lineSourceLines.push(startLine);
727
+
728
+ if (!isFirstHasContent && isInteriorHasContent) {
729
+ const indentation =
730
+ bodyLines
731
+ .slice(1, -1)
732
+ .find((line) => line.trim() !== "")
733
+ ?.match(/^\s*/u)?.[0] ?? "";
734
+ output.push(`${indentation}…`);
735
+ lineSourceLines.push(undefined);
736
+ }
737
+
738
+ output.push(isLastHasContent ? maskSegment(beforeClose) + lastLine.slice(closeIndex) : lastLine);
739
+ lineSourceLines.push(endLine);
740
+
741
+ return { text: output.join("\n"), lineSourceLines };
806
742
  }
807
743
 
808
- function maskSegment(segment: string): string
809
- {
810
- const leading = /^\s*/u.exec(segment)?.[0] ?? "";
811
- const trailing = /\s*$/u.exec(segment)?.[0] ?? "";
812
- return `${leading}…${trailing}`;
744
+ function maskSegment(segment: string): string {
745
+ const leading = /^\s*/u.exec(segment)?.[0] ?? "";
746
+ const trailing = /\s*$/u.exec(segment)?.[0] ?? "";
747
+ return `${leading}…${trailing}`;
813
748
  }