agent-ide 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. package/dist/application/index.d.ts +1 -12
  2. package/dist/application/index.d.ts.map +1 -1
  3. package/dist/application/index.js +0 -16
  4. package/dist/application/index.js.map +1 -1
  5. package/dist/application/services/cache-coordinator.service.d.ts.map +1 -1
  6. package/dist/application/services/cache-coordinator.service.js.map +1 -1
  7. package/dist/application/services/module-coordinator.service.d.ts +3 -8
  8. package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
  9. package/dist/application/services/module-coordinator.service.js +5 -139
  10. package/dist/application/services/module-coordinator.service.js.map +1 -1
  11. package/dist/application/types.d.ts +0 -63
  12. package/dist/application/types.d.ts.map +1 -1
  13. package/dist/application/types.js +1 -9
  14. package/dist/application/types.js.map +1 -1
  15. package/dist/core/call-hierarchy/call-hierarchy-analyzer.d.ts.map +1 -1
  16. package/dist/core/call-hierarchy/call-hierarchy-analyzer.js +3 -5
  17. package/dist/core/call-hierarchy/call-hierarchy-analyzer.js.map +1 -1
  18. package/dist/core/change-signature/call-site-updater.d.ts +108 -0
  19. package/dist/core/change-signature/call-site-updater.d.ts.map +1 -0
  20. package/dist/core/change-signature/call-site-updater.js +347 -0
  21. package/dist/core/change-signature/call-site-updater.js.map +1 -0
  22. package/dist/core/change-signature/change-signature-service.d.ts +11 -53
  23. package/dist/core/change-signature/change-signature-service.d.ts.map +1 -1
  24. package/dist/core/change-signature/change-signature-service.js +91 -475
  25. package/dist/core/change-signature/change-signature-service.js.map +1 -1
  26. package/dist/core/change-signature/index.d.ts +4 -0
  27. package/dist/core/change-signature/index.d.ts.map +1 -1
  28. package/dist/core/change-signature/index.js +5 -0
  29. package/dist/core/change-signature/index.js.map +1 -1
  30. package/dist/core/change-signature/signature-parser.d.ts +46 -4
  31. package/dist/core/change-signature/signature-parser.d.ts.map +1 -1
  32. package/dist/core/change-signature/signature-parser.js +180 -9
  33. package/dist/core/change-signature/signature-parser.js.map +1 -1
  34. package/dist/core/change-signature/signature-transformer.d.ts +20 -0
  35. package/dist/core/change-signature/signature-transformer.d.ts.map +1 -0
  36. package/dist/core/change-signature/signature-transformer.js +91 -0
  37. package/dist/core/change-signature/signature-transformer.js.map +1 -0
  38. package/dist/core/change-signature/signature-validator.d.ts +30 -0
  39. package/dist/core/change-signature/signature-validator.d.ts.map +1 -0
  40. package/dist/core/change-signature/signature-validator.js +152 -0
  41. package/dist/core/change-signature/signature-validator.js.map +1 -0
  42. package/dist/core/change-signature/utils.d.ts +19 -0
  43. package/dist/core/change-signature/utils.d.ts.map +1 -0
  44. package/dist/core/change-signature/utils.js +23 -0
  45. package/dist/core/change-signature/utils.js.map +1 -0
  46. package/dist/core/cycles/cycle-detector.d.ts.map +1 -1
  47. package/dist/core/cycles/cycle-detector.js +16 -8
  48. package/dist/core/cycles/cycle-detector.js.map +1 -1
  49. package/dist/core/cycles/index.d.ts +1 -1
  50. package/dist/core/cycles/index.d.ts.map +1 -1
  51. package/dist/core/cycles/index.js +1 -1
  52. package/dist/core/cycles/index.js.map +1 -1
  53. package/dist/core/cycles/types.d.ts +20 -4
  54. package/dist/core/cycles/types.d.ts.map +1 -1
  55. package/dist/core/cycles/types.js +22 -4
  56. package/dist/core/cycles/types.js.map +1 -1
  57. package/dist/core/deadcode/dead-code-detector.d.ts +22 -1
  58. package/dist/core/deadcode/dead-code-detector.d.ts.map +1 -1
  59. package/dist/core/deadcode/dead-code-detector.js +134 -61
  60. package/dist/core/deadcode/dead-code-detector.js.map +1 -1
  61. package/dist/core/deadcode/dead-code-remover.d.ts +11 -93
  62. package/dist/core/deadcode/dead-code-remover.d.ts.map +1 -1
  63. package/dist/core/deadcode/dead-code-remover.js +71 -690
  64. package/dist/core/deadcode/dead-code-remover.js.map +1 -1
  65. package/dist/core/deadcode/file-operations.d.ts +85 -0
  66. package/dist/core/deadcode/file-operations.d.ts.map +1 -0
  67. package/dist/core/deadcode/file-operations.js +263 -0
  68. package/dist/core/deadcode/file-operations.js.map +1 -0
  69. package/dist/core/deadcode/import-cleaner.d.ts +63 -0
  70. package/dist/core/deadcode/import-cleaner.d.ts.map +1 -0
  71. package/dist/core/deadcode/import-cleaner.js +229 -0
  72. package/dist/core/deadcode/import-cleaner.js.map +1 -0
  73. package/dist/core/deadcode/import-parser.d.ts +79 -0
  74. package/dist/core/deadcode/import-parser.d.ts.map +1 -0
  75. package/dist/core/deadcode/import-parser.js +229 -0
  76. package/dist/core/deadcode/import-parser.js.map +1 -0
  77. package/dist/core/deadcode/range-expander.d.ts +38 -0
  78. package/dist/core/deadcode/range-expander.d.ts.map +1 -0
  79. package/dist/core/deadcode/range-expander.js +175 -0
  80. package/dist/core/deadcode/range-expander.js.map +1 -0
  81. package/dist/core/deadcode/types.d.ts +2 -0
  82. package/dist/core/deadcode/types.d.ts.map +1 -1
  83. package/dist/core/deadcode/types.js.map +1 -1
  84. package/dist/core/find-references/index.d.ts +2 -2
  85. package/dist/core/find-references/index.d.ts.map +1 -1
  86. package/dist/core/find-references/index.js +1 -1
  87. package/dist/core/find-references/index.js.map +1 -1
  88. package/dist/core/impact/dependency-extractor.d.ts +25 -0
  89. package/dist/core/impact/dependency-extractor.d.ts.map +1 -0
  90. package/dist/core/impact/dependency-extractor.js +65 -0
  91. package/dist/core/impact/dependency-extractor.js.map +1 -0
  92. package/dist/core/impact/file-scanner.d.ts +52 -0
  93. package/dist/core/impact/file-scanner.d.ts.map +1 -0
  94. package/dist/core/impact/file-scanner.js +131 -0
  95. package/dist/core/impact/file-scanner.js.map +1 -0
  96. package/dist/core/impact/impact-analyzer.d.ts +3 -64
  97. package/dist/core/impact/impact-analyzer.d.ts.map +1 -1
  98. package/dist/core/impact/impact-analyzer.js +13 -312
  99. package/dist/core/impact/impact-analyzer.js.map +1 -1
  100. package/dist/core/impact/index.d.ts +3 -0
  101. package/dist/core/impact/index.d.ts.map +1 -1
  102. package/dist/core/impact/index.js +3 -0
  103. package/dist/core/impact/index.js.map +1 -1
  104. package/dist/core/impact/path-resolver.d.ts +35 -0
  105. package/dist/core/impact/path-resolver.d.ts.map +1 -0
  106. package/dist/core/impact/path-resolver.js +166 -0
  107. package/dist/core/impact/path-resolver.js.map +1 -0
  108. package/dist/core/move/file-scanner.d.ts +48 -0
  109. package/dist/core/move/file-scanner.d.ts.map +1 -0
  110. package/dist/core/move/file-scanner.js +137 -0
  111. package/dist/core/move/file-scanner.js.map +1 -0
  112. package/dist/core/move/import-resolver.d.ts +10 -0
  113. package/dist/core/move/import-resolver.d.ts.map +1 -1
  114. package/dist/core/move/import-resolver.js +31 -6
  115. package/dist/core/move/import-resolver.js.map +1 -1
  116. package/dist/core/move/index.d.ts +7 -3
  117. package/dist/core/move/index.d.ts.map +1 -1
  118. package/dist/core/move/index.js +7 -2
  119. package/dist/core/move/index.js.map +1 -1
  120. package/dist/core/move/move-service.d.ts +41 -52
  121. package/dist/core/move/move-service.d.ts.map +1 -1
  122. package/dist/core/move/move-service.js +189 -358
  123. package/dist/core/move/move-service.js.map +1 -1
  124. package/dist/core/move/path-calculator.d.ts +49 -0
  125. package/dist/core/move/path-calculator.d.ts.map +1 -0
  126. package/dist/core/move/path-calculator.js +158 -0
  127. package/dist/core/move/path-calculator.js.map +1 -0
  128. package/dist/core/move/path-parser.d.ts +33 -0
  129. package/dist/core/move/path-parser.d.ts.map +1 -0
  130. package/dist/core/move/path-parser.js +53 -0
  131. package/dist/core/move/path-parser.js.map +1 -0
  132. package/dist/core/move/path-utils.d.ts +70 -0
  133. package/dist/core/move/path-utils.d.ts.map +1 -0
  134. package/dist/core/move/path-utils.js +201 -0
  135. package/dist/core/move/path-utils.js.map +1 -0
  136. package/dist/core/move/types.d.ts +81 -18
  137. package/dist/core/move/types.d.ts.map +1 -1
  138. package/dist/core/move/types.js +73 -5
  139. package/dist/core/move/types.js.map +1 -1
  140. package/dist/core/move-member/change-applier.d.ts +23 -0
  141. package/dist/core/move-member/change-applier.d.ts.map +1 -0
  142. package/dist/core/move-member/change-applier.js +51 -0
  143. package/dist/core/move-member/change-applier.js.map +1 -0
  144. package/dist/core/move-member/file-change-preparer.d.ts +49 -0
  145. package/dist/core/move-member/file-change-preparer.d.ts.map +1 -0
  146. package/dist/core/move-member/file-change-preparer.js +340 -0
  147. package/dist/core/move-member/file-change-preparer.js.map +1 -0
  148. package/dist/core/move-member/index.d.ts +4 -1
  149. package/dist/core/move-member/index.d.ts.map +1 -1
  150. package/dist/core/move-member/index.js +3 -0
  151. package/dist/core/move-member/index.js.map +1 -1
  152. package/dist/core/move-member/member-extractor.d.ts +11 -0
  153. package/dist/core/move-member/member-extractor.d.ts.map +1 -1
  154. package/dist/core/move-member/member-extractor.js +116 -24
  155. package/dist/core/move-member/member-extractor.js.map +1 -1
  156. package/dist/core/move-member/move-member-service.d.ts +9 -78
  157. package/dist/core/move-member/move-member-service.d.ts.map +1 -1
  158. package/dist/core/move-member/move-member-service.js +86 -413
  159. package/dist/core/move-member/move-member-service.js.map +1 -1
  160. package/dist/core/move-member/reference-updater.d.ts +73 -0
  161. package/dist/core/move-member/reference-updater.d.ts.map +1 -0
  162. package/dist/core/move-member/reference-updater.js +286 -0
  163. package/dist/core/move-member/reference-updater.js.map +1 -0
  164. package/dist/core/move-member/types.d.ts +17 -2
  165. package/dist/core/move-member/types.d.ts.map +1 -1
  166. package/dist/core/move-member/types.js.map +1 -1
  167. package/dist/core/rename/reference-updater.d.ts +1 -35
  168. package/dist/core/rename/reference-updater.d.ts.map +1 -1
  169. package/dist/core/rename/reference-updater.js +8 -251
  170. package/dist/core/rename/reference-updater.js.map +1 -1
  171. package/dist/core/rename/rename-engine.d.ts +16 -22
  172. package/dist/core/rename/rename-engine.d.ts.map +1 -1
  173. package/dist/core/rename/rename-engine.js +59 -208
  174. package/dist/core/rename/rename-engine.js.map +1 -1
  175. package/dist/core/rename/scope-analyzer.d.ts.map +1 -1
  176. package/dist/core/shared/index.d.ts +1 -1
  177. package/dist/core/shared/index.d.ts.map +1 -1
  178. package/dist/core/shared/index.js +1 -1
  179. package/dist/core/shared/index.js.map +1 -1
  180. package/dist/core/shared/indexing/index-engine.d.ts +1 -1
  181. package/dist/core/shared/indexing/index-engine.d.ts.map +1 -1
  182. package/dist/core/shared/indexing/index-engine.js +1 -1
  183. package/dist/core/shared/indexing/index-engine.js.map +1 -1
  184. package/dist/core/shared/symbol-finder/call-site-parser.d.ts +71 -0
  185. package/dist/core/shared/symbol-finder/call-site-parser.d.ts.map +1 -0
  186. package/dist/core/shared/symbol-finder/call-site-parser.js +369 -0
  187. package/dist/core/shared/symbol-finder/call-site-parser.js.map +1 -0
  188. package/dist/core/shared/symbol-finder/index.d.ts +9 -0
  189. package/dist/core/shared/symbol-finder/index.d.ts.map +1 -0
  190. package/dist/core/shared/symbol-finder/index.js +12 -0
  191. package/dist/core/shared/symbol-finder/index.js.map +1 -0
  192. package/dist/core/shared/{symbol-finder.d.ts → symbol-finder/symbol-finder.d.ts} +27 -133
  193. package/dist/core/shared/symbol-finder/symbol-finder.d.ts.map +1 -0
  194. package/dist/core/shared/symbol-finder/symbol-finder.js +552 -0
  195. package/dist/core/shared/symbol-finder/symbol-finder.js.map +1 -0
  196. package/dist/core/shared/symbol-finder/text-matcher.d.ts +45 -0
  197. package/dist/core/shared/symbol-finder/text-matcher.d.ts.map +1 -0
  198. package/dist/core/shared/symbol-finder/text-matcher.js +195 -0
  199. package/dist/core/shared/symbol-finder/text-matcher.js.map +1 -0
  200. package/dist/core/shared/symbol-finder/types.d.ts +108 -0
  201. package/dist/core/shared/symbol-finder/types.d.ts.map +1 -0
  202. package/dist/core/shared/symbol-finder/types.js +71 -0
  203. package/dist/core/shared/symbol-finder/types.js.map +1 -0
  204. package/dist/core/snapshot/snapshot-generator.d.ts +16 -4
  205. package/dist/core/snapshot/snapshot-generator.d.ts.map +1 -1
  206. package/dist/core/snapshot/snapshot-generator.js +91 -18
  207. package/dist/core/snapshot/snapshot-generator.js.map +1 -1
  208. package/dist/infrastructure/cache/cache-manager.d.ts.map +1 -1
  209. package/dist/infrastructure/cache/cache-manager.js +4 -0
  210. package/dist/infrastructure/cache/cache-manager.js.map +1 -1
  211. package/dist/infrastructure/cache/index.d.ts +15 -9
  212. package/dist/infrastructure/cache/index.d.ts.map +1 -1
  213. package/dist/infrastructure/cache/index.js +5 -5
  214. package/dist/infrastructure/cache/index.js.map +1 -1
  215. package/dist/infrastructure/cache/memory-cache.d.ts.map +1 -1
  216. package/dist/infrastructure/cache/memory-cache.js.map +1 -1
  217. package/dist/infrastructure/cache/strategies.d.ts.map +1 -1
  218. package/dist/infrastructure/cache/strategies.js +2 -1
  219. package/dist/infrastructure/cache/strategies.js.map +1 -1
  220. package/dist/infrastructure/cache/types.d.ts +4 -4
  221. package/dist/infrastructure/cache/types.d.ts.map +1 -1
  222. package/dist/infrastructure/changeset/change-applicator.d.ts +95 -0
  223. package/dist/infrastructure/changeset/change-applicator.d.ts.map +1 -0
  224. package/dist/infrastructure/changeset/change-applicator.js +467 -0
  225. package/dist/infrastructure/changeset/change-applicator.js.map +1 -0
  226. package/dist/infrastructure/changeset/changeset-builder.d.ts +107 -0
  227. package/dist/infrastructure/changeset/changeset-builder.d.ts.map +1 -0
  228. package/dist/infrastructure/changeset/changeset-builder.js +188 -0
  229. package/dist/infrastructure/changeset/changeset-builder.js.map +1 -0
  230. package/dist/infrastructure/changeset/changeset-converter.d.ts +15 -0
  231. package/dist/infrastructure/changeset/changeset-converter.d.ts.map +1 -0
  232. package/dist/infrastructure/changeset/changeset-converter.js +370 -0
  233. package/dist/infrastructure/changeset/changeset-converter.js.map +1 -0
  234. package/dist/infrastructure/changeset/index.d.ts +10 -0
  235. package/dist/infrastructure/changeset/index.d.ts.map +1 -0
  236. package/dist/infrastructure/changeset/index.js +13 -0
  237. package/dist/infrastructure/changeset/index.js.map +1 -0
  238. package/dist/infrastructure/changeset/types.d.ts +147 -0
  239. package/dist/infrastructure/changeset/types.d.ts.map +1 -0
  240. package/dist/infrastructure/changeset/types.js +46 -0
  241. package/dist/infrastructure/changeset/types.js.map +1 -0
  242. package/dist/infrastructure/parser/base.d.ts.map +1 -1
  243. package/dist/infrastructure/parser/base.js +4 -3
  244. package/dist/infrastructure/parser/base.js.map +1 -1
  245. package/dist/infrastructure/parser/interface.d.ts +4 -2
  246. package/dist/infrastructure/parser/interface.d.ts.map +1 -1
  247. package/dist/infrastructure/parser/interface.js.map +1 -1
  248. package/dist/infrastructure/storage/file-system.d.ts.map +1 -1
  249. package/dist/infrastructure/storage/file-system.js +61 -54
  250. package/dist/infrastructure/storage/file-system.js.map +1 -1
  251. package/dist/interfaces/cli/cli.d.ts.map +1 -1
  252. package/dist/interfaces/cli/cli.js +1 -2
  253. package/dist/interfaces/cli/cli.js.map +1 -1
  254. package/dist/interfaces/cli/commands/change-signature.command.d.ts.map +1 -1
  255. package/dist/interfaces/cli/commands/change-signature.command.js +31 -107
  256. package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -1
  257. package/dist/interfaces/cli/commands/deadcode.command.js +51 -46
  258. package/dist/interfaces/cli/commands/deadcode.command.js.map +1 -1
  259. package/dist/interfaces/cli/commands/find-references.command.d.ts.map +1 -1
  260. package/dist/interfaces/cli/commands/find-references.command.js +18 -3
  261. package/dist/interfaces/cli/commands/find-references.command.js.map +1 -1
  262. package/dist/interfaces/cli/commands/index.d.ts +0 -1
  263. package/dist/interfaces/cli/commands/index.d.ts.map +1 -1
  264. package/dist/interfaces/cli/commands/index.js +0 -1
  265. package/dist/interfaces/cli/commands/index.js.map +1 -1
  266. package/dist/interfaces/cli/commands/move.command.d.ts +1 -0
  267. package/dist/interfaces/cli/commands/move.command.d.ts.map +1 -1
  268. package/dist/interfaces/cli/commands/move.command.js +170 -65
  269. package/dist/interfaces/cli/commands/move.command.js.map +1 -1
  270. package/dist/interfaces/cli/commands/rename.command.d.ts.map +1 -1
  271. package/dist/interfaces/cli/commands/rename.command.js +133 -59
  272. package/dist/interfaces/cli/commands/rename.command.js.map +1 -1
  273. package/dist/interfaces/cli/output-formatter.d.ts +2 -2
  274. package/dist/interfaces/cli/output-formatter.d.ts.map +1 -1
  275. package/dist/interfaces/cli/output-formatter.js.map +1 -1
  276. package/dist/plugins/javascript/declaration-analyzer.d.ts.map +1 -1
  277. package/dist/plugins/javascript/declaration-analyzer.js +9 -0
  278. package/dist/plugins/javascript/declaration-analyzer.js.map +1 -1
  279. package/dist/plugins/javascript/parser.d.ts +11 -10
  280. package/dist/plugins/javascript/parser.d.ts.map +1 -1
  281. package/dist/plugins/javascript/parser.js +57 -53
  282. package/dist/plugins/javascript/parser.js.map +1 -1
  283. package/dist/plugins/javascript/pattern-analyzer.d.ts.map +1 -1
  284. package/dist/plugins/javascript/pattern-analyzer.js +4 -3
  285. package/dist/plugins/javascript/pattern-analyzer.js.map +1 -1
  286. package/dist/plugins/javascript/reference-finder.d.ts +21 -0
  287. package/dist/plugins/javascript/reference-finder.d.ts.map +1 -1
  288. package/dist/plugins/javascript/reference-finder.js +119 -76
  289. package/dist/plugins/javascript/reference-finder.js.map +1 -1
  290. package/dist/plugins/javascript/types.d.ts +4 -7
  291. package/dist/plugins/javascript/types.d.ts.map +1 -1
  292. package/dist/plugins/javascript/types.js +9 -9
  293. package/dist/plugins/javascript/types.js.map +1 -1
  294. package/dist/plugins/shared/parser-helpers.js.map +1 -1
  295. package/dist/{shared → plugins/shared}/utils/array.d.ts +6 -1
  296. package/dist/plugins/shared/utils/array.d.ts.map +1 -0
  297. package/dist/plugins/shared/utils/array.js.map +1 -0
  298. package/dist/{shared → plugins/shared}/utils/async.d.ts +1 -1
  299. package/dist/plugins/shared/utils/async.d.ts.map +1 -0
  300. package/dist/{shared → plugins/shared}/utils/async.js +2 -0
  301. package/dist/plugins/shared/utils/async.js.map +1 -0
  302. package/dist/{shared → plugins/shared}/utils/index.d.ts +0 -20
  303. package/dist/plugins/shared/utils/index.d.ts.map +1 -0
  304. package/dist/{shared → plugins/shared}/utils/index.js +0 -20
  305. package/dist/plugins/shared/utils/index.js.map +1 -0
  306. package/dist/plugins/shared/utils/memory-monitor.d.ts.map +1 -0
  307. package/dist/plugins/shared/utils/memory-monitor.js.map +1 -0
  308. package/dist/{shared → plugins/shared}/utils/object.d.ts +6 -6
  309. package/dist/plugins/shared/utils/object.d.ts.map +1 -0
  310. package/dist/{shared → plugins/shared}/utils/object.js +21 -3
  311. package/dist/plugins/shared/utils/object.js.map +1 -0
  312. package/dist/plugins/shared/utils/path.d.ts.map +1 -0
  313. package/dist/plugins/shared/utils/path.js.map +1 -0
  314. package/dist/{shared → plugins/shared}/utils/string.d.ts +1 -1
  315. package/dist/plugins/shared/utils/string.d.ts.map +1 -0
  316. package/dist/{shared → plugins/shared}/utils/string.js +7 -4
  317. package/dist/plugins/shared/utils/string.js.map +1 -0
  318. package/dist/plugins/typescript/declaration-analyzer.d.ts +4 -4
  319. package/dist/plugins/typescript/declaration-analyzer.d.ts.map +1 -1
  320. package/dist/plugins/typescript/declaration-analyzer.js +13 -6
  321. package/dist/plugins/typescript/declaration-analyzer.js.map +1 -1
  322. package/dist/plugins/typescript/language-service.d.ts +1 -1
  323. package/dist/plugins/typescript/language-service.d.ts.map +1 -1
  324. package/dist/plugins/typescript/parser.d.ts +3 -2
  325. package/dist/plugins/typescript/parser.d.ts.map +1 -1
  326. package/dist/plugins/typescript/parser.js +18 -13
  327. package/dist/plugins/typescript/parser.js.map +1 -1
  328. package/dist/plugins/typescript/reference-finder.d.ts +3 -0
  329. package/dist/plugins/typescript/reference-finder.d.ts.map +1 -1
  330. package/dist/plugins/typescript/reference-finder.js +16 -4
  331. package/dist/plugins/typescript/reference-finder.js.map +1 -1
  332. package/dist/plugins/typescript/symbol-extractor.d.ts +4 -0
  333. package/dist/plugins/typescript/symbol-extractor.d.ts.map +1 -1
  334. package/dist/plugins/typescript/symbol-extractor.js +24 -6
  335. package/dist/plugins/typescript/symbol-extractor.js.map +1 -1
  336. package/dist/plugins/typescript/types.d.ts +0 -3
  337. package/dist/plugins/typescript/types.d.ts.map +1 -1
  338. package/dist/plugins/typescript/types.js +6 -9
  339. package/dist/plugins/typescript/types.js.map +1 -1
  340. package/dist/shared/errors/index.d.ts +1 -1
  341. package/dist/shared/errors/index.d.ts.map +1 -1
  342. package/dist/shared/errors/parser-error.js +5 -5
  343. package/dist/shared/errors/parser-error.js.map +1 -1
  344. package/dist/shared/errors/validation-error.d.ts +2 -2
  345. package/dist/shared/errors/validation-error.d.ts.map +1 -1
  346. package/dist/shared/errors/validation-error.js.map +1 -1
  347. package/dist/shared/types/ast.d.ts +4 -4
  348. package/dist/shared/types/ast.d.ts.map +1 -1
  349. package/dist/shared/types/ast.js.map +1 -1
  350. package/dist/shared/types/core.d.ts +1 -1
  351. package/dist/shared/types/core.d.ts.map +1 -1
  352. package/dist/shared/types/index.d.ts +1 -0
  353. package/dist/shared/types/index.d.ts.map +1 -1
  354. package/dist/shared/types/index.js +2 -0
  355. package/dist/shared/types/index.js.map +1 -1
  356. package/dist/shared/types/line-number.d.ts +22 -0
  357. package/dist/shared/types/line-number.d.ts.map +1 -0
  358. package/dist/shared/types/line-number.js +28 -0
  359. package/dist/shared/types/line-number.js.map +1 -0
  360. package/package.json +2 -2
  361. package/dist/application/services/workflow-engine.service.d.ts +0 -76
  362. package/dist/application/services/workflow-engine.service.d.ts.map +0 -1
  363. package/dist/application/services/workflow-engine.service.js +0 -405
  364. package/dist/application/services/workflow-engine.service.js.map +0 -1
  365. package/dist/application/workflows/analysis-workflow.d.ts +0 -239
  366. package/dist/application/workflows/analysis-workflow.d.ts.map +0 -1
  367. package/dist/application/workflows/analysis-workflow.js +0 -395
  368. package/dist/application/workflows/analysis-workflow.js.map +0 -1
  369. package/dist/application/workflows/base-workflow.d.ts +0 -108
  370. package/dist/application/workflows/base-workflow.d.ts.map +0 -1
  371. package/dist/application/workflows/base-workflow.js +0 -236
  372. package/dist/application/workflows/base-workflow.js.map +0 -1
  373. package/dist/application/workflows/index.d.ts +0 -115
  374. package/dist/application/workflows/index.d.ts.map +0 -1
  375. package/dist/application/workflows/index.js +0 -218
  376. package/dist/application/workflows/index.js.map +0 -1
  377. package/dist/application/workflows/refactor-workflow.d.ts +0 -107
  378. package/dist/application/workflows/refactor-workflow.d.ts.map +0 -1
  379. package/dist/application/workflows/refactor-workflow.js +0 -310
  380. package/dist/application/workflows/refactor-workflow.js.map +0 -1
  381. package/dist/core/shared/symbol-finder.d.ts.map +0 -1
  382. package/dist/core/shared/symbol-finder.js +0 -882
  383. package/dist/core/shared/symbol-finder.js.map +0 -1
  384. package/dist/interfaces/cli/commands/move-member.command.d.ts +0 -11
  385. package/dist/interfaces/cli/commands/move-member.command.d.ts.map +0 -1
  386. package/dist/interfaces/cli/commands/move-member.command.js +0 -211
  387. package/dist/interfaces/cli/commands/move-member.command.js.map +0 -1
  388. package/dist/plugins/javascript/code-analyzer.d.ts +0 -68
  389. package/dist/plugins/javascript/code-analyzer.d.ts.map +0 -1
  390. package/dist/plugins/javascript/code-analyzer.js +0 -302
  391. package/dist/plugins/javascript/code-analyzer.js.map +0 -1
  392. package/dist/plugins/javascript/index.d.ts +0 -12
  393. package/dist/plugins/javascript/index.d.ts.map +0 -1
  394. package/dist/plugins/javascript/index.js +0 -16
  395. package/dist/plugins/javascript/index.js.map +0 -1
  396. package/dist/plugins/typescript/index.d.ts +0 -14
  397. package/dist/plugins/typescript/index.d.ts.map +0 -1
  398. package/dist/plugins/typescript/index.js +0 -13
  399. package/dist/plugins/typescript/index.js.map +0 -1
  400. package/dist/shared/utils/array.d.ts.map +0 -1
  401. package/dist/shared/utils/array.js.map +0 -1
  402. package/dist/shared/utils/async.d.ts.map +0 -1
  403. package/dist/shared/utils/async.js.map +0 -1
  404. package/dist/shared/utils/index.d.ts.map +0 -1
  405. package/dist/shared/utils/index.js.map +0 -1
  406. package/dist/shared/utils/memory-monitor.d.ts.map +0 -1
  407. package/dist/shared/utils/memory-monitor.js.map +0 -1
  408. package/dist/shared/utils/object.d.ts.map +0 -1
  409. package/dist/shared/utils/object.js.map +0 -1
  410. package/dist/shared/utils/path.d.ts.map +0 -1
  411. package/dist/shared/utils/path.js.map +0 -1
  412. package/dist/shared/utils/string.d.ts.map +0 -1
  413. package/dist/shared/utils/string.js.map +0 -1
  414. /package/dist/{shared → plugins/shared}/utils/array.js +0 -0
  415. /package/dist/{shared → plugins/shared}/utils/memory-monitor.d.ts +0 -0
  416. /package/dist/{shared → plugins/shared}/utils/memory-monitor.js +0 -0
  417. /package/dist/{shared → plugins/shared}/utils/path.d.ts +0 -0
  418. /package/dist/{shared → plugins/shared}/utils/path.js +0 -0
@@ -3,9 +3,13 @@
3
3
  * 參數重構核心服務
4
4
  */
5
5
  import * as path from 'path';
6
+ import { createChangesetBuilder, ChangesetCommand, TextEditOperationType } from '../../infrastructure/changeset/index.js';
6
7
  import { SignatureParser } from './signature-parser.js';
7
- import { ChangeSignatureErrorCode, isAddParameterChange, isRemoveParameterChange, isReorderParametersChange, isChangeParameterTypeChange, isRenameParameterChange, isChangeDefaultValueChange, isToggleOptionalChange } from './types.js';
8
- import { SymbolFinder } from '../shared/symbol-finder.js';
8
+ import { SignatureValidator } from './signature-validator.js';
9
+ import { SignatureTransformer } from './signature-transformer.js';
10
+ import { CallSiteUpdater } from './call-site-updater.js';
11
+ import { ChangeSignatureErrorCode } from './types.js';
12
+ import { SymbolFinder } from '../shared/symbol-finder/index.js';
9
13
  /**
10
14
  * Change Signature Service
11
15
  */
@@ -14,11 +18,17 @@ export class ChangeSignatureService {
14
18
  fileSystem;
15
19
  signatureParser;
16
20
  symbolFinder;
21
+ validator;
22
+ transformer;
23
+ callSiteUpdater;
17
24
  constructor(parserRegistry, fileSystem) {
18
25
  this.parserRegistry = parserRegistry;
19
26
  this.fileSystem = fileSystem;
20
27
  this.signatureParser = new SignatureParser(parserRegistry, fileSystem);
21
28
  this.symbolFinder = new SymbolFinder(parserRegistry, fileSystem);
29
+ this.validator = new SignatureValidator();
30
+ this.transformer = new SignatureTransformer();
31
+ this.callSiteUpdater = new CallSiteUpdater(fileSystem);
22
32
  }
23
33
  /**
24
34
  * 執行 Change Signature
@@ -30,19 +40,19 @@ export class ChangeSignatureService {
30
40
  return this.createErrorResult(ChangeSignatureErrorCode.FunctionNotFound, `找不到函式: ${options.functionName}`);
31
41
  }
32
42
  // 2. 驗證變更
33
- const validationErrors = this.validateChanges(originalSignature, options.changes);
43
+ const validationErrors = this.validator.validateChanges(originalSignature, options.changes);
34
44
  if (validationErrors.length > 0) {
35
45
  return this.createErrorResult(validationErrors[0].code, validationErrors[0].message);
36
46
  }
37
47
  // 3. 計算新簽名
38
- const newSignature = this.applyChangesToSignature(originalSignature, options.changes);
48
+ const newSignature = this.transformer.applyChangesToSignature(originalSignature, options.changes);
39
49
  // 4. 取得所有呼叫點
40
50
  const projectFiles = options.targetFiles ?? await this.getProjectFiles(options.projectRoot);
41
51
  const callSites = await this.symbolFinder.findCallSites(options.functionName, projectFiles);
42
52
  // 5. 生成定義更新
43
53
  const definitionUpdate = await this.generateDefinitionUpdate(options.filePath, originalSignature, newSignature);
44
54
  // 6. 生成呼叫點更新
45
- const callSiteUpdates = await this.generateCallSiteUpdates(callSites, originalSignature, newSignature, options.changes);
55
+ const callSiteUpdates = await this.callSiteUpdater.generateCallSiteUpdates(callSites, originalSignature, newSignature, options.changes);
46
56
  // 7. 執行或預覽
47
57
  if (!options.preview) {
48
58
  await this.applyChanges(definitionUpdate, callSiteUpdates);
@@ -67,163 +77,75 @@ export class ChangeSignatureService {
67
77
  };
68
78
  }
69
79
  /**
70
- * 驗證變更
80
+ * 生成參數簽名變更的 Changeset
81
+ * 使用 preview 模式收集變更,轉換為統一的 Changeset 格式
82
+ *
83
+ * @param options - 變更選項(強制使用 preview 模式)
84
+ * @returns Changeset 物件
71
85
  */
72
- validateChanges(signature, changes) {
73
- const errors = [];
74
- const parameterNames = new Set(signature.parameters.map(p => p.name));
75
- const newParameterNames = new Set(parameterNames);
76
- for (const change of changes) {
77
- if (isAddParameterChange(change)) {
78
- if (newParameterNames.has(change.name)) {
79
- errors.push({
80
- code: ChangeSignatureErrorCode.DuplicateParameterName,
81
- message: `參數名稱重複: ${change.name}`,
82
- parameterName: change.name
83
- });
84
- }
85
- else {
86
- newParameterNames.add(change.name);
87
- }
88
- // 驗證新增參數必須有預設值
89
- if (!change.callSiteValue && !change.defaultValue) {
90
- errors.push({
91
- code: ChangeSignatureErrorCode.MissingDefaultValue,
92
- message: `參數 ${change.name} 缺少預設值,請使用 --default-value 或 --call-site-value 指定`,
93
- parameterName: change.name
94
- });
95
- }
96
- }
97
- if (isRemoveParameterChange(change)) {
98
- const targetName = this.resolveParameterName(signature, change.parameterNameOrIndex);
99
- if (!targetName || !parameterNames.has(targetName)) {
100
- errors.push({
101
- code: ChangeSignatureErrorCode.ParameterNotFound,
102
- message: `找不到參數: ${change.parameterNameOrIndex}`,
103
- parameterName: String(change.parameterNameOrIndex)
104
- });
105
- }
106
- else {
107
- newParameterNames.delete(targetName);
108
- }
109
- }
110
- if (isReorderParametersChange(change)) {
111
- for (const nameOrIndex of change.newOrder) {
112
- const targetName = this.resolveParameterName(signature, nameOrIndex);
113
- if (!targetName || !parameterNames.has(targetName)) {
114
- errors.push({
115
- code: ChangeSignatureErrorCode.ParameterNotFound,
116
- message: `找不到參數: ${nameOrIndex}`,
117
- parameterName: String(nameOrIndex)
118
- });
119
- }
120
- }
121
- if (change.newOrder.length !== signature.parameters.length) {
122
- errors.push({
123
- code: ChangeSignatureErrorCode.InvalidParameterOrder,
124
- message: '重新排序必須包含所有參數'
125
- });
126
- }
127
- // 驗證可選參數順序:可選參數必須在必選參數之後
128
- const optionalOrderError = this.validateOptionalParameterOrder(signature, change.newOrder);
129
- if (optionalOrderError) {
130
- errors.push(optionalOrderError);
131
- }
132
- }
133
- if (isChangeParameterTypeChange(change) || isRenameParameterChange(change) ||
134
- isChangeDefaultValueChange(change) || isToggleOptionalChange(change)) {
135
- const targetName = this.resolveParameterName(signature, change.parameterNameOrIndex);
136
- if (!targetName || !parameterNames.has(targetName)) {
137
- errors.push({
138
- code: ChangeSignatureErrorCode.ParameterNotFound,
139
- message: `找不到參數: ${change.parameterNameOrIndex}`,
140
- parameterName: String(change.parameterNameOrIndex)
141
- });
142
- }
86
+ async generateChangeset(options) {
87
+ const builder = createChangesetBuilder().forCommand(ChangesetCommand.ChangeSignature);
88
+ // 使用現有邏輯(preview 模式)收集變更
89
+ const result = await this.changeSignature({
90
+ ...options,
91
+ preview: true
92
+ });
93
+ if (!result.success) {
94
+ return builder
95
+ .addError(result.error ?? 'Change signature failed')
96
+ .withDescription(result.error ?? 'Change signature failed')
97
+ .build();
98
+ }
99
+ // 轉換 definitionUpdate
100
+ const { filePath, originalCode, newCode, location } = result.definitionUpdate;
101
+ // originalCode 和 newCode 都是完整的一行內容
102
+ // 因此 range 應該從行首(column 1)開始,到行尾結束
103
+ const lineNumber = location.range.start.line;
104
+ const originalLineLength = originalCode.length;
105
+ builder.addTextChange(filePath, [{
106
+ range: {
107
+ start: { line: lineNumber, column: 1 },
108
+ end: { line: lineNumber, column: originalLineLength + 1 }
109
+ },
110
+ newText: newCode,
111
+ description: `Update definition: ${originalCode.trim()} -> ${newCode.trim()}`
112
+ }], TextEditOperationType.Modify);
113
+ // 轉換 callSiteUpdates
114
+ // 按檔案分組,合併同一檔案的多個變更
115
+ const updatesByFile = new Map();
116
+ for (const update of result.callSiteUpdates) {
117
+ const existing = updatesByFile.get(update.filePath);
118
+ if (existing) {
119
+ existing.push(update);
143
120
  }
144
- if (isRenameParameterChange(change)) {
145
- if (newParameterNames.has(change.newName) && change.newName !== this.resolveParameterName(signature, change.parameterNameOrIndex)) {
146
- errors.push({
147
- code: ChangeSignatureErrorCode.DuplicateParameterName,
148
- message: `參數名稱重複: ${change.newName}`,
149
- parameterName: change.newName
150
- });
151
- }
121
+ else {
122
+ updatesByFile.set(update.filePath, [update]);
152
123
  }
153
124
  }
154
- return errors;
155
- }
156
- /**
157
- * 套用變更到簽名
158
- */
159
- applyChangesToSignature(signature, changes) {
160
- let parameters = [...signature.parameters];
161
- for (const change of changes) {
162
- if (isAddParameterChange(change)) {
163
- const newParam = {
164
- name: change.name,
165
- type: change.parameterType,
166
- defaultValue: change.defaultValue,
167
- optional: change.optional,
168
- rest: false,
169
- range: { start: { line: 0, column: 0, offset: 0 }, end: { line: 0, column: 0, offset: 0 } }
125
+ for (const [updateFilePath, updates] of updatesByFile) {
126
+ // 跳過與 definitionUpdate 同一檔案(避免重複)
127
+ // 已經在上面處理過了,呼叫點和定義可能在同一行
128
+ const edits = updates.map(update => {
129
+ // originalCode 和 newCode 都是完整的一行內容
130
+ // 因此 range 應該從行首(column 1)開始,到行尾結束
131
+ const lineStart = update.location.range.start.line;
132
+ const callOriginalLength = update.originalCode.length;
133
+ return {
134
+ range: {
135
+ start: { line: lineStart, column: 1 },
136
+ end: { line: lineStart, column: callOriginalLength + 1 }
137
+ },
138
+ newText: update.newCode,
139
+ description: `Update call: ${update.originalCode.trim()} -> ${update.newCode.trim()}`
170
140
  };
171
- if (change.position < 0 || change.position >= parameters.length) {
172
- parameters.push(newParam);
173
- }
174
- else {
175
- parameters.splice(change.position, 0, newParam);
176
- }
177
- }
178
- if (isRemoveParameterChange(change)) {
179
- const index = this.resolveParameterIndex(parameters, change.parameterNameOrIndex);
180
- if (index >= 0) {
181
- parameters.splice(index, 1);
182
- }
183
- }
184
- if (isReorderParametersChange(change)) {
185
- const newParams = [];
186
- for (const nameOrIndex of change.newOrder) {
187
- const index = this.resolveParameterIndex(parameters, nameOrIndex);
188
- if (index >= 0) {
189
- newParams.push(parameters[index]);
190
- }
191
- }
192
- parameters = newParams;
193
- }
194
- if (isChangeParameterTypeChange(change)) {
195
- const index = this.resolveParameterIndex(parameters, change.parameterNameOrIndex);
196
- if (index >= 0) {
197
- parameters[index] = { ...parameters[index], type: change.newType };
198
- }
199
- }
200
- if (isRenameParameterChange(change)) {
201
- const index = this.resolveParameterIndex(parameters, change.parameterNameOrIndex);
202
- if (index >= 0) {
203
- parameters[index] = { ...parameters[index], name: change.newName };
204
- }
205
- }
206
- if (isChangeDefaultValueChange(change)) {
207
- const index = this.resolveParameterIndex(parameters, change.parameterNameOrIndex);
208
- if (index >= 0) {
209
- parameters[index] = {
210
- ...parameters[index],
211
- defaultValue: change.newDefaultValue,
212
- optional: change.newDefaultValue !== undefined || parameters[index].optional
213
- };
214
- }
215
- }
216
- if (isToggleOptionalChange(change)) {
217
- const index = this.resolveParameterIndex(parameters, change.parameterNameOrIndex);
218
- if (index >= 0) {
219
- parameters[index] = { ...parameters[index], optional: change.optional };
220
- }
221
- }
141
+ });
142
+ builder.addTextChange(updateFilePath, edits, TextEditOperationType.Modify);
222
143
  }
223
- return {
224
- ...signature,
225
- parameters
226
- };
144
+ // 設定描述
145
+ const originalParams = result.originalSignature.parameters.map(p => p.name).join(', ');
146
+ const newParams = result.newSignature.parameters.map(p => p.name).join(', ');
147
+ builder.withDescription(`Changed signature of ${result.originalSignature.name}: (${originalParams}) -> (${newParams})`);
148
+ return builder.build();
227
149
  }
228
150
  /**
229
151
  * 生成定義更新
@@ -252,267 +174,6 @@ export class ChangeSignatureService {
252
174
  location: originalSignature.location
253
175
  };
254
176
  }
255
- /**
256
- * 生成呼叫點更新
257
- * 效能優化:按檔案分組後批次讀取,避免重複讀取同一檔案
258
- * 檔案讀取次數從 O(N) 降到 O(M),N = callSites 數量,M = 不重複檔案數
259
- * 支援多行呼叫點:正確處理跨多行的函式呼叫
260
- */
261
- async generateCallSiteUpdates(callSites, originalSignature, newSignature, changes) {
262
- const updates = [];
263
- // 建立參數映射
264
- const parameterMapping = this.createParameterMapping(originalSignature, newSignature, changes);
265
- // 按檔案分組 callSites,避免重複讀取同一檔案
266
- const callSitesByFile = new Map();
267
- for (const callSite of callSites) {
268
- const filePath = callSite.location.filePath;
269
- const existing = callSitesByFile.get(filePath);
270
- if (existing) {
271
- existing.push(callSite);
272
- }
273
- else {
274
- callSitesByFile.set(filePath, [callSite]);
275
- }
276
- }
277
- // 批次讀取所有不重複的檔案並處理
278
- for (const [filePath, fileCallSites] of callSitesByFile) {
279
- const content = await this.readFile(filePath);
280
- if (!content) {
281
- continue;
282
- }
283
- const lines = content.split('\n');
284
- // 處理該檔案的所有 callSites
285
- for (const callSite of fileCallSites) {
286
- const startLineIndex = callSite.location.range.start.line - 1;
287
- const endLineIndex = callSite.location.range.end.line - 1;
288
- const isMultiline = startLineIndex !== endLineIndex;
289
- // 建立新的參數列表
290
- const newArgs = this.mapCallSiteArguments(callSite, parameterMapping, changes, originalSignature);
291
- // 找到呼叫的括號位置
292
- const startLine = lines[startLineIndex];
293
- const funcNameIndex = startLine.indexOf(callSite.functionName);
294
- if (funcNameIndex < 0) {
295
- continue;
296
- }
297
- const openParenIndex = startLine.indexOf('(', funcNameIndex);
298
- if (isMultiline) {
299
- // 多行呼叫點:提取完整的原始程式碼並替換
300
- const originalCode = this.extractMultilineCode(lines, startLineIndex, endLineIndex);
301
- // 檢測原始呼叫的格式風格
302
- const originalStyle = this.detectCallStyle(lines, startLineIndex, endLineIndex);
303
- // 生成新的參數字串(保留原始風格)
304
- const newArgsString = this.formatArgsWithStyle(newArgs, originalStyle);
305
- // 生成新的程式碼
306
- const newCode = startLine.substring(0, openParenIndex + 1)
307
- + newArgsString
308
- + ')' + this.getTrailingContent(lines, endLineIndex, callSite.location.range.end.column - 1);
309
- if (newCode !== originalCode) {
310
- updates.push({
311
- filePath: callSite.location.filePath,
312
- originalCode,
313
- newCode,
314
- location: callSite.location
315
- });
316
- }
317
- }
318
- else {
319
- // 單行呼叫點:保持原有邏輯
320
- const closeParenIndex = this.findMatchingParen(startLine, openParenIndex);
321
- const newArgsString = newArgs.join(', ');
322
- const newLine = startLine.substring(0, openParenIndex + 1)
323
- + newArgsString
324
- + startLine.substring(closeParenIndex);
325
- if (newLine !== startLine) {
326
- updates.push({
327
- filePath: callSite.location.filePath,
328
- originalCode: startLine,
329
- newCode: newLine,
330
- location: callSite.location
331
- });
332
- }
333
- }
334
- }
335
- }
336
- return updates;
337
- }
338
- /**
339
- * 提取多行程式碼
340
- */
341
- extractMultilineCode(lines, startLine, endLine) {
342
- if (startLine === endLine) {
343
- return lines[startLine];
344
- }
345
- const result = [];
346
- for (let i = startLine; i <= endLine; i++) {
347
- result.push(lines[i]);
348
- }
349
- return result.join('\n');
350
- }
351
- /**
352
- * 檢測呼叫風格
353
- */
354
- detectCallStyle(lines, startLine, endLine) {
355
- const isMultiline = startLine !== endLine;
356
- if (!isMultiline) {
357
- return { multiline: false, indent: '', trailingComma: false };
358
- }
359
- // 檢測縮排(從第二行取得)
360
- const secondLine = lines[startLine + 1] || '';
361
- const indentMatch = secondLine.match(/^(\s*)/);
362
- const indent = indentMatch ? indentMatch[1] : ' ';
363
- // 檢測是否有尾隨逗號
364
- const lastArgLine = lines[endLine - 1] || lines[endLine];
365
- const trailingComma = lastArgLine.trimEnd().endsWith(',');
366
- return { multiline: true, indent, trailingComma };
367
- }
368
- /**
369
- * 根據風格格式化參數
370
- */
371
- formatArgsWithStyle(args, style) {
372
- if (!style.multiline || args.length === 0) {
373
- return args.join(', ');
374
- }
375
- // 多行格式
376
- const formattedArgs = args.map(arg => `${style.indent}${arg}`);
377
- const separator = style.trailingComma ? ',\n' : ',\n';
378
- return '\n' + formattedArgs.join(separator) + (style.trailingComma ? ',' : '') + '\n';
379
- }
380
- /**
381
- * 取得結束行的尾隨內容(右括號之後的部分)
382
- */
383
- getTrailingContent(lines, endLine, closeParenColumn) {
384
- const line = lines[endLine];
385
- // 找到右括號後的內容
386
- return line.substring(closeParenColumn + 1);
387
- }
388
- /**
389
- * 建立參數映射
390
- */
391
- createParameterMapping(originalSignature, newSignature, changes) {
392
- const mapping = new Map();
393
- // 初始化:原始索引 -> 新索引
394
- let currentParams = originalSignature.parameters.map((p, i) => ({ name: p.name, originalIndex: i }));
395
- // 處理每個變更
396
- for (const change of changes) {
397
- if (isRemoveParameterChange(change)) {
398
- const index = this.resolveParameterIndex(currentParams.map(p => ({ name: p.name })), change.parameterNameOrIndex);
399
- if (index >= 0) {
400
- currentParams.splice(index, 1);
401
- }
402
- }
403
- if (isReorderParametersChange(change)) {
404
- const newOrder = [];
405
- for (const nameOrIndex of change.newOrder) {
406
- const index = this.resolveParameterIndex(currentParams.map(p => ({ name: p.name })), nameOrIndex);
407
- if (index >= 0) {
408
- newOrder.push(currentParams[index]);
409
- }
410
- }
411
- currentParams = newOrder;
412
- }
413
- if (isAddParameterChange(change)) {
414
- const newParam = { name: change.name, originalIndex: -1, value: change.callSiteValue || change.defaultValue };
415
- if (change.position < 0 || change.position >= currentParams.length) {
416
- currentParams.push(newParam);
417
- }
418
- else {
419
- currentParams.splice(change.position, 0, newParam);
420
- }
421
- }
422
- }
423
- // 建立最終映射
424
- for (let newIndex = 0; newIndex < currentParams.length; newIndex++) {
425
- const param = currentParams[newIndex];
426
- if (param.originalIndex >= 0) {
427
- mapping.set(param.originalIndex, { newIndex });
428
- }
429
- else if ('value' in param) {
430
- // 新增的參數,設定預設值
431
- mapping.set(-1 - newIndex, { newIndex, value: param.value });
432
- }
433
- }
434
- return mapping;
435
- }
436
- /**
437
- * 映射呼叫點參數
438
- * 處理省略的可選參數:當可選參數被省略時,重排後需要插入 undefined
439
- */
440
- mapCallSiteArguments(callSite, parameterMapping, changes, originalSignature) {
441
- const result = [];
442
- // 找出新參數的數量
443
- let maxNewIndex = -1;
444
- for (const { newIndex } of parameterMapping.values()) {
445
- maxNewIndex = Math.max(maxNewIndex, newIndex);
446
- }
447
- // 初始化結果陣列
448
- for (let i = 0; i <= maxNewIndex; i++) {
449
- result.push('');
450
- }
451
- // 映射原始參數
452
- for (const [originalIndex, { newIndex }] of parameterMapping.entries()) {
453
- if (originalIndex >= 0) {
454
- if (originalIndex < callSite.arguments.length) {
455
- // 呼叫點有提供此參數
456
- result[newIndex] = callSite.arguments[originalIndex].value;
457
- }
458
- else {
459
- // 呼叫點省略了此可選參數
460
- // 檢查這個位置是否需要填入 undefined(當後面有其他參數時)
461
- const param = originalSignature.parameters[originalIndex];
462
- if (param && (param.optional || param.defaultValue)) {
463
- // 標記為需要填入 undefined(如果後面有非空參數)
464
- result[newIndex] = '\0OMITTED\0';
465
- }
466
- }
467
- }
468
- }
469
- // 填入新增參數的值
470
- const addedPositions = new Set();
471
- for (const change of changes) {
472
- if (isAddParameterChange(change)) {
473
- // 使用 callSiteValue 或 defaultValue(驗證階段已確保至少有一個值)
474
- const value = change.callSiteValue || change.defaultValue;
475
- const position = change.position < 0 ? result.length - 1 : Math.min(change.position, result.length - 1);
476
- if (position >= 0 && position < result.length && !result[position]) {
477
- result[position] = value;
478
- addedPositions.add(position);
479
- }
480
- }
481
- }
482
- // 處理省略的可選參數:
483
- // 如果省略的參數後面有非空參數,則需要填入 undefined
484
- // 否則可以完全省略
485
- const processedResult = [];
486
- let lastNonEmptyIndex = -1;
487
- // 找到最後一個非空參數的索引
488
- for (let i = result.length - 1; i >= 0; i--) {
489
- if (result[i] !== '' && result[i] !== '\0OMITTED\0') {
490
- lastNonEmptyIndex = i;
491
- break;
492
- }
493
- }
494
- // 建立最終結果
495
- for (let i = 0; i <= lastNonEmptyIndex; i++) {
496
- if (result[i] === '\0OMITTED\0') {
497
- // 省略的可選參數,但後面有其他參數,需要填入 undefined
498
- processedResult.push('undefined');
499
- }
500
- else if (result[i] === '') {
501
- // 空值,檢查是否是新增的位置
502
- if (addedPositions.has(i)) {
503
- processedResult.push('undefined');
504
- }
505
- else {
506
- // 不應該出現的情況,填入 undefined 以避免語法錯誤
507
- processedResult.push('undefined');
508
- }
509
- }
510
- else {
511
- processedResult.push(result[i]);
512
- }
513
- }
514
- return processedResult;
515
- }
516
177
  /**
517
178
  * 執行變更
518
179
  */
@@ -595,61 +256,6 @@ export class ChangeSignatureService {
595
256
  }
596
257
  return line.length;
597
258
  }
598
- /**
599
- * 解析參數名稱
600
- */
601
- resolveParameterName(signature, nameOrIndex) {
602
- if (typeof nameOrIndex === 'number') {
603
- return signature.parameters[nameOrIndex]?.name;
604
- }
605
- return signature.parameters.find(p => p.name === nameOrIndex)?.name;
606
- }
607
- /**
608
- * 解析參數索引
609
- */
610
- resolveParameterIndex(parameters, nameOrIndex) {
611
- if (typeof nameOrIndex === 'number') {
612
- return nameOrIndex >= 0 && nameOrIndex < parameters.length ? nameOrIndex : -1;
613
- }
614
- return parameters.findIndex(p => p.name === nameOrIndex);
615
- }
616
- /**
617
- * 驗證可選參數順序
618
- * TypeScript 規則:可選參數必須在所有必選參數之後
619
- * 例外:有預設值的參數視為可選,rest 參數必須在最後
620
- */
621
- validateOptionalParameterOrder(signature, newOrder) {
622
- // 根據新順序建立參數列表
623
- const reorderedParams = [];
624
- for (const nameOrIndex of newOrder) {
625
- const index = this.resolveParameterIndex(signature.parameters, nameOrIndex);
626
- if (index >= 0) {
627
- reorderedParams.push(signature.parameters[index]);
628
- }
629
- }
630
- // 檢查可選參數是否在必選參數之前
631
- let foundOptional = false;
632
- let firstOptionalParam = null;
633
- for (const param of reorderedParams) {
634
- const isOptional = param.optional || param.defaultValue !== undefined;
635
- const isRest = param.rest;
636
- if (isOptional && !isRest) {
637
- foundOptional = true;
638
- if (!firstOptionalParam) {
639
- firstOptionalParam = param;
640
- }
641
- }
642
- else if (!isOptional && !isRest && foundOptional) {
643
- // 找到必選參數在可選參數之後
644
- return {
645
- code: ChangeSignatureErrorCode.OptionalBeforeRequired,
646
- message: `可選參數 '${firstOptionalParam.name}' 不能位於必選參數 '${param.name}' 之前`,
647
- parameterName: param.name
648
- };
649
- }
650
- }
651
- return null;
652
- }
653
259
  /**
654
260
  * 取得專案檔案
655
261
  */
@@ -707,12 +313,22 @@ export class ChangeSignatureService {
707
313
  * 建立錯誤結果
708
314
  */
709
315
  createErrorResult(code, message) {
316
+ // 錯誤情況下必須提供佔位簽名資訊
317
+ const emptyRange = { start: { line: 0, column: 0, offset: 0 }, end: { line: 0, column: 0, offset: 0 } };
318
+ const emptyLocation = { filePath: '', range: emptyRange };
319
+ const emptySignature = {
320
+ name: '',
321
+ parameters: [],
322
+ location: emptyLocation,
323
+ isMethod: false,
324
+ modifiers: []
325
+ };
710
326
  return {
711
327
  success: false,
712
328
  error: message,
713
- originalSignature: null,
714
- newSignature: null,
715
- definitionUpdate: null,
329
+ originalSignature: emptySignature,
330
+ newSignature: emptySignature,
331
+ definitionUpdate: { filePath: '', originalCode: '', newCode: '', location: emptyLocation },
716
332
  callSiteUpdates: [],
717
333
  executed: false,
718
334
  stats: {