agent-ide 0.3.3 → 0.4.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 (452) hide show
  1. package/README.md +11 -10
  2. package/dist/application/services/module-coordinator.service.d.ts +1 -21
  3. package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
  4. package/dist/application/services/module-coordinator.service.js +10 -149
  5. package/dist/application/services/module-coordinator.service.js.map +1 -1
  6. package/dist/core/{transform/symbol/change-signature → change-signature}/change-signature-service.d.ts +2 -2
  7. package/dist/core/change-signature/change-signature-service.d.ts.map +1 -0
  8. package/dist/core/{transform/symbol/change-signature → change-signature}/change-signature-service.js +1 -1
  9. package/dist/core/change-signature/change-signature-service.js.map +1 -0
  10. package/dist/core/change-signature/index.d.ts.map +1 -0
  11. package/dist/core/change-signature/index.js.map +1 -0
  12. package/dist/core/{transform/symbol/change-signature → change-signature}/signature-parser.d.ts +2 -2
  13. package/dist/core/change-signature/signature-parser.d.ts.map +1 -0
  14. package/dist/core/change-signature/signature-parser.js.map +1 -0
  15. package/dist/core/{transform/symbol/change-signature → change-signature}/types.d.ts +1 -1
  16. package/dist/core/change-signature/types.d.ts.map +1 -0
  17. package/dist/core/change-signature/types.js.map +1 -0
  18. package/dist/core/indexing/index-engine.d.ts.map +1 -1
  19. package/dist/core/indexing/index-engine.js +1 -2
  20. package/dist/core/indexing/index-engine.js.map +1 -1
  21. package/dist/core/indexing/index.d.ts +1 -9
  22. package/dist/core/indexing/index.d.ts.map +1 -1
  23. package/dist/core/indexing/index.js +2 -12
  24. package/dist/core/indexing/index.js.map +1 -1
  25. package/dist/core/indexing/types.d.ts +12 -0
  26. package/dist/core/indexing/types.d.ts.map +1 -1
  27. package/dist/core/indexing/types.js +12 -0
  28. package/dist/core/indexing/types.js.map +1 -1
  29. package/dist/core/{transform/location/move-file → move-file}/import-resolver.d.ts +1 -1
  30. package/dist/core/move-file/import-resolver.d.ts.map +1 -0
  31. package/dist/core/{transform/location/move-file → move-file}/import-resolver.js +2 -2
  32. package/dist/core/move-file/import-resolver.js.map +1 -0
  33. package/dist/core/move-file/index.d.ts.map +1 -0
  34. package/dist/core/move-file/index.js.map +1 -0
  35. package/dist/core/{transform/location/move-file → move-file}/move-service.d.ts +3 -3
  36. package/dist/core/move-file/move-service.d.ts.map +1 -0
  37. package/dist/core/{transform/location/move-file → move-file}/move-service.js +1 -1
  38. package/dist/core/move-file/move-service.js.map +1 -0
  39. package/dist/core/{transform/location/move-file → move-file}/types.d.ts +1 -1
  40. package/dist/core/move-file/types.d.ts.map +1 -0
  41. package/dist/core/move-file/types.js.map +1 -0
  42. package/dist/core/move-member/index.d.ts.map +1 -0
  43. package/dist/core/move-member/index.js.map +1 -0
  44. package/dist/core/{transform/location/move-member → move-member}/member-extractor.d.ts +2 -2
  45. package/dist/core/move-member/member-extractor.d.ts.map +1 -0
  46. package/dist/core/move-member/member-extractor.js.map +1 -0
  47. package/dist/core/{transform/location/move-member → move-member}/move-member-service.d.ts +2 -2
  48. package/dist/core/move-member/move-member-service.d.ts.map +1 -0
  49. package/dist/core/{transform/location/move-member → move-member}/move-member-service.js +1 -1
  50. package/dist/core/move-member/move-member-service.js.map +1 -0
  51. package/dist/core/{transform/location/move-member → move-member}/types.d.ts +1 -1
  52. package/dist/core/move-member/types.d.ts.map +1 -0
  53. package/dist/core/move-member/types.js.map +1 -0
  54. package/dist/core/rename/index.d.ts.map +1 -0
  55. package/dist/core/rename/index.js.map +1 -0
  56. package/dist/core/{transform/symbol/rename → rename}/reference-updater.d.ts +5 -3
  57. package/dist/core/rename/reference-updater.d.ts.map +1 -0
  58. package/dist/core/{transform/symbol/rename → rename}/reference-updater.js +9 -6
  59. package/dist/core/rename/reference-updater.js.map +1 -0
  60. package/dist/core/{transform/symbol/rename → rename}/rename-engine.d.ts +5 -3
  61. package/dist/core/rename/rename-engine.d.ts.map +1 -0
  62. package/dist/core/{transform/symbol/rename → rename}/rename-engine.js +11 -8
  63. package/dist/core/rename/rename-engine.js.map +1 -0
  64. package/dist/core/{transform/symbol/rename → rename}/scope-analyzer.d.ts +3 -3
  65. package/dist/core/rename/scope-analyzer.d.ts.map +1 -0
  66. package/dist/core/{transform/symbol/rename → rename}/scope-analyzer.js +2 -2
  67. package/dist/core/rename/scope-analyzer.js.map +1 -0
  68. package/dist/core/{transform/symbol/rename → rename}/types.d.ts +2 -2
  69. package/dist/core/rename/types.d.ts.map +1 -0
  70. package/dist/core/rename/types.js.map +1 -0
  71. package/dist/core/shared/call-hierarchy-analyzer.d.ts +102 -0
  72. package/dist/core/shared/call-hierarchy-analyzer.d.ts.map +1 -0
  73. package/dist/core/shared/call-hierarchy-analyzer.js +328 -0
  74. package/dist/core/shared/call-hierarchy-analyzer.js.map +1 -0
  75. package/dist/core/shared/index.d.ts +7 -0
  76. package/dist/core/shared/index.d.ts.map +1 -0
  77. package/dist/core/shared/index.js +7 -0
  78. package/dist/core/shared/index.js.map +1 -0
  79. package/dist/core/{transform/shared → shared}/symbol-finder.d.ts +4 -4
  80. package/dist/core/shared/symbol-finder.d.ts.map +1 -0
  81. package/dist/core/shared/symbol-finder.js.map +1 -0
  82. package/dist/infrastructure/formatters/diff-generator.d.ts.map +1 -1
  83. package/dist/infrastructure/formatters/diff-generator.js +11 -1
  84. package/dist/infrastructure/formatters/diff-generator.js.map +1 -1
  85. package/dist/infrastructure/formatters/index.d.ts +1 -1
  86. package/dist/infrastructure/formatters/index.d.ts.map +1 -1
  87. package/dist/infrastructure/formatters/index.js.map +1 -1
  88. package/dist/infrastructure/formatters/query-formatter.d.ts +20 -0
  89. package/dist/infrastructure/formatters/query-formatter.d.ts.map +1 -1
  90. package/dist/infrastructure/formatters/query-formatter.js +145 -14
  91. package/dist/infrastructure/formatters/query-formatter.js.map +1 -1
  92. package/dist/infrastructure/formatters/query-types.d.ts +99 -26
  93. package/dist/infrastructure/formatters/query-types.d.ts.map +1 -1
  94. package/dist/infrastructure/formatters/query-types.js +2 -3
  95. package/dist/infrastructure/formatters/query-types.js.map +1 -1
  96. package/dist/infrastructure/formatters/types.d.ts +10 -0
  97. package/dist/infrastructure/formatters/types.d.ts.map +1 -1
  98. package/dist/infrastructure/parser/base.d.ts +0 -32
  99. package/dist/infrastructure/parser/base.d.ts.map +1 -1
  100. package/dist/infrastructure/parser/base.js +0 -64
  101. package/dist/infrastructure/parser/base.js.map +1 -1
  102. package/dist/infrastructure/parser/index.d.ts +0 -2
  103. package/dist/infrastructure/parser/index.d.ts.map +1 -1
  104. package/dist/infrastructure/parser/index.js +1 -2
  105. package/dist/infrastructure/parser/index.js.map +1 -1
  106. package/dist/infrastructure/parser/interface.d.ts +1 -58
  107. package/dist/infrastructure/parser/interface.d.ts.map +1 -1
  108. package/dist/infrastructure/parser/interface.js +1 -11
  109. package/dist/infrastructure/parser/interface.js.map +1 -1
  110. package/dist/infrastructure/storage/index.d.ts +0 -2
  111. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  112. package/dist/infrastructure/storage/index.js +0 -2
  113. package/dist/infrastructure/storage/index.js.map +1 -1
  114. package/dist/interfaces/cli/cli.d.ts.map +1 -1
  115. package/dist/interfaces/cli/cli.js +11 -17
  116. package/dist/interfaces/cli/cli.js.map +1 -1
  117. package/dist/interfaces/cli/commands/call-hierarchy.command.d.ts +11 -0
  118. package/dist/interfaces/cli/commands/call-hierarchy.command.d.ts.map +1 -0
  119. package/dist/interfaces/cli/commands/call-hierarchy.command.js +161 -0
  120. package/dist/interfaces/cli/commands/call-hierarchy.command.js.map +1 -0
  121. package/dist/interfaces/cli/commands/change-signature.command.js +8 -17
  122. package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -1
  123. package/dist/interfaces/cli/commands/cycles.command.d.ts +11 -0
  124. package/dist/interfaces/cli/commands/cycles.command.d.ts.map +1 -0
  125. package/dist/interfaces/cli/commands/cycles.command.js +87 -0
  126. package/dist/interfaces/cli/commands/cycles.command.js.map +1 -0
  127. package/dist/interfaces/cli/commands/find-references.command.d.ts +11 -0
  128. package/dist/interfaces/cli/commands/find-references.command.d.ts.map +1 -0
  129. package/dist/interfaces/cli/commands/find-references.command.js +122 -0
  130. package/dist/interfaces/cli/commands/find-references.command.js.map +1 -0
  131. package/dist/interfaces/cli/commands/impact.command.d.ts +11 -0
  132. package/dist/interfaces/cli/commands/impact.command.d.ts.map +1 -0
  133. package/dist/interfaces/cli/commands/impact.command.js +98 -0
  134. package/dist/interfaces/cli/commands/impact.command.js.map +1 -0
  135. package/dist/interfaces/cli/commands/index.d.ts +4 -6
  136. package/dist/interfaces/cli/commands/index.d.ts.map +1 -1
  137. package/dist/interfaces/cli/commands/index.js +6 -6
  138. package/dist/interfaces/cli/commands/index.js.map +1 -1
  139. package/dist/interfaces/cli/commands/move-member.command.js +7 -16
  140. package/dist/interfaces/cli/commands/move-member.command.js.map +1 -1
  141. package/dist/interfaces/cli/commands/move.command.js +21 -29
  142. package/dist/interfaces/cli/commands/move.command.js.map +1 -1
  143. package/dist/interfaces/cli/commands/rename.command.js +105 -119
  144. package/dist/interfaces/cli/commands/rename.command.js.map +1 -1
  145. package/dist/interfaces/cli/unified-output-handler.d.ts +3 -1
  146. package/dist/interfaces/cli/unified-output-handler.d.ts.map +1 -1
  147. package/dist/interfaces/cli/unified-output-handler.js +11 -2
  148. package/dist/interfaces/cli/unified-output-handler.js.map +1 -1
  149. package/dist/plugins/python/index.d.ts +0 -8
  150. package/dist/plugins/python/index.d.ts.map +1 -1
  151. package/dist/plugins/python/index.js +0 -9
  152. package/dist/plugins/python/index.js.map +1 -1
  153. package/dist/plugins/python/parser.d.ts +8 -41
  154. package/dist/plugins/python/parser.d.ts.map +1 -1
  155. package/dist/plugins/python/parser.js +30 -92
  156. package/dist/plugins/python/parser.js.map +1 -1
  157. package/dist/plugins/swift/parser.d.ts +4 -0
  158. package/dist/plugins/swift/parser.d.ts.map +1 -1
  159. package/dist/plugins/swift/parser.js +22 -4
  160. package/dist/plugins/swift/parser.js.map +1 -1
  161. package/dist/plugins/typescript/parser.d.ts +4 -37
  162. package/dist/plugins/typescript/parser.d.ts.map +1 -1
  163. package/dist/plugins/typescript/parser.js +17 -328
  164. package/dist/plugins/typescript/parser.js.map +1 -1
  165. package/dist/shared/types/symbol.d.ts +2 -1
  166. package/dist/shared/types/symbol.d.ts.map +1 -1
  167. package/dist/shared/types/symbol.js +1 -0
  168. package/dist/shared/types/symbol.js.map +1 -1
  169. package/package.json +8 -6
  170. package/dist/core/indexing/file-watcher.d.ts +0 -112
  171. package/dist/core/indexing/file-watcher.d.ts.map +0 -1
  172. package/dist/core/indexing/file-watcher.js +0 -284
  173. package/dist/core/indexing/file-watcher.js.map +0 -1
  174. package/dist/core/search/engines/text-engine.d.ts +0 -55
  175. package/dist/core/search/engines/text-engine.d.ts.map +0 -1
  176. package/dist/core/search/engines/text-engine.js +0 -377
  177. package/dist/core/search/engines/text-engine.js.map +0 -1
  178. package/dist/core/search/index.d.ts +0 -10
  179. package/dist/core/search/index.d.ts.map +0 -1
  180. package/dist/core/search/index.js +0 -11
  181. package/dist/core/search/index.js.map +0 -1
  182. package/dist/core/search/service.d.ts +0 -106
  183. package/dist/core/search/service.d.ts.map +0 -1
  184. package/dist/core/search/service.js +0 -384
  185. package/dist/core/search/service.js.map +0 -1
  186. package/dist/core/search/types.d.ts +0 -357
  187. package/dist/core/search/types.d.ts.map +0 -1
  188. package/dist/core/search/types.js +0 -47
  189. package/dist/core/search/types.js.map +0 -1
  190. package/dist/core/transform/index.d.ts +0 -10
  191. package/dist/core/transform/index.d.ts.map +0 -1
  192. package/dist/core/transform/index.js +0 -21
  193. package/dist/core/transform/index.js.map +0 -1
  194. package/dist/core/transform/location/index.d.ts +0 -8
  195. package/dist/core/transform/location/index.d.ts.map +0 -1
  196. package/dist/core/transform/location/index.js +0 -9
  197. package/dist/core/transform/location/index.js.map +0 -1
  198. package/dist/core/transform/location/move-file/import-resolver.d.ts.map +0 -1
  199. package/dist/core/transform/location/move-file/import-resolver.js.map +0 -1
  200. package/dist/core/transform/location/move-file/index.d.ts.map +0 -1
  201. package/dist/core/transform/location/move-file/index.js.map +0 -1
  202. package/dist/core/transform/location/move-file/move-service.d.ts.map +0 -1
  203. package/dist/core/transform/location/move-file/move-service.js.map +0 -1
  204. package/dist/core/transform/location/move-file/types.d.ts.map +0 -1
  205. package/dist/core/transform/location/move-file/types.js.map +0 -1
  206. package/dist/core/transform/location/move-member/index.d.ts.map +0 -1
  207. package/dist/core/transform/location/move-member/index.js.map +0 -1
  208. package/dist/core/transform/location/move-member/member-extractor.d.ts.map +0 -1
  209. package/dist/core/transform/location/move-member/member-extractor.js.map +0 -1
  210. package/dist/core/transform/location/move-member/move-member-service.d.ts.map +0 -1
  211. package/dist/core/transform/location/move-member/move-member-service.js.map +0 -1
  212. package/dist/core/transform/location/move-member/types.d.ts.map +0 -1
  213. package/dist/core/transform/location/move-member/types.js.map +0 -1
  214. package/dist/core/transform/location/shift/file-generator.d.ts +0 -45
  215. package/dist/core/transform/location/shift/file-generator.d.ts.map +0 -1
  216. package/dist/core/transform/location/shift/file-generator.js +0 -94
  217. package/dist/core/transform/location/shift/file-generator.js.map +0 -1
  218. package/dist/core/transform/location/shift/index.d.ts +0 -11
  219. package/dist/core/transform/location/shift/index.d.ts.map +0 -1
  220. package/dist/core/transform/location/shift/index.js +0 -13
  221. package/dist/core/transform/location/shift/index.js.map +0 -1
  222. package/dist/core/transform/location/shift/line-extractor.d.ts +0 -55
  223. package/dist/core/transform/location/shift/line-extractor.d.ts.map +0 -1
  224. package/dist/core/transform/location/shift/line-extractor.js +0 -123
  225. package/dist/core/transform/location/shift/line-extractor.js.map +0 -1
  226. package/dist/core/transform/location/shift/shift-service.d.ts +0 -57
  227. package/dist/core/transform/location/shift/shift-service.d.ts.map +0 -1
  228. package/dist/core/transform/location/shift/shift-service.js +0 -199
  229. package/dist/core/transform/location/shift/shift-service.js.map +0 -1
  230. package/dist/core/transform/location/shift/types.d.ts +0 -195
  231. package/dist/core/transform/location/shift/types.d.ts.map +0 -1
  232. package/dist/core/transform/location/shift/types.js +0 -89
  233. package/dist/core/transform/location/shift/types.js.map +0 -1
  234. package/dist/core/transform/shared/code-editor.d.ts +0 -70
  235. package/dist/core/transform/shared/code-editor.d.ts.map +0 -1
  236. package/dist/core/transform/shared/code-editor.js +0 -206
  237. package/dist/core/transform/shared/code-editor.js.map +0 -1
  238. package/dist/core/transform/shared/index.d.ts +0 -7
  239. package/dist/core/transform/shared/index.d.ts.map +0 -1
  240. package/dist/core/transform/shared/index.js +0 -7
  241. package/dist/core/transform/shared/index.js.map +0 -1
  242. package/dist/core/transform/shared/symbol-finder.d.ts.map +0 -1
  243. package/dist/core/transform/shared/symbol-finder.js.map +0 -1
  244. package/dist/core/transform/structure/extract/extract-function.d.ts +0 -197
  245. package/dist/core/transform/structure/extract/extract-function.d.ts.map +0 -1
  246. package/dist/core/transform/structure/extract/extract-function.js +0 -730
  247. package/dist/core/transform/structure/extract/extract-function.js.map +0 -1
  248. package/dist/core/transform/structure/extract/index.d.ts +0 -7
  249. package/dist/core/transform/structure/extract/index.d.ts.map +0 -1
  250. package/dist/core/transform/structure/extract/index.js +0 -9
  251. package/dist/core/transform/structure/extract/index.js.map +0 -1
  252. package/dist/core/transform/structure/extract/swift-extractor.d.ts +0 -98
  253. package/dist/core/transform/structure/extract/swift-extractor.d.ts.map +0 -1
  254. package/dist/core/transform/structure/extract/swift-extractor.js +0 -283
  255. package/dist/core/transform/structure/extract/swift-extractor.js.map +0 -1
  256. package/dist/core/transform/structure/index.d.ts +0 -8
  257. package/dist/core/transform/structure/index.d.ts.map +0 -1
  258. package/dist/core/transform/structure/index.js +0 -8
  259. package/dist/core/transform/structure/index.js.map +0 -1
  260. package/dist/core/transform/structure/inline/index.d.ts +0 -6
  261. package/dist/core/transform/structure/inline/index.d.ts.map +0 -1
  262. package/dist/core/transform/structure/inline/index.js +0 -6
  263. package/dist/core/transform/structure/inline/index.js.map +0 -1
  264. package/dist/core/transform/structure/inline/inline-function.d.ts +0 -175
  265. package/dist/core/transform/structure/inline/inline-function.d.ts.map +0 -1
  266. package/dist/core/transform/structure/inline/inline-function.js +0 -436
  267. package/dist/core/transform/structure/inline/inline-function.js.map +0 -1
  268. package/dist/core/transform/structure/patterns/design-patterns.d.ts +0 -178
  269. package/dist/core/transform/structure/patterns/design-patterns.d.ts.map +0 -1
  270. package/dist/core/transform/structure/patterns/design-patterns.js +0 -656
  271. package/dist/core/transform/structure/patterns/design-patterns.js.map +0 -1
  272. package/dist/core/transform/structure/patterns/index.d.ts +0 -6
  273. package/dist/core/transform/structure/patterns/index.d.ts.map +0 -1
  274. package/dist/core/transform/structure/patterns/index.js +0 -6
  275. package/dist/core/transform/structure/patterns/index.js.map +0 -1
  276. package/dist/core/transform/symbol/change-signature/change-signature-service.d.ts.map +0 -1
  277. package/dist/core/transform/symbol/change-signature/change-signature-service.js.map +0 -1
  278. package/dist/core/transform/symbol/change-signature/index.d.ts.map +0 -1
  279. package/dist/core/transform/symbol/change-signature/index.js.map +0 -1
  280. package/dist/core/transform/symbol/change-signature/signature-parser.d.ts.map +0 -1
  281. package/dist/core/transform/symbol/change-signature/signature-parser.js.map +0 -1
  282. package/dist/core/transform/symbol/change-signature/types.d.ts.map +0 -1
  283. package/dist/core/transform/symbol/change-signature/types.js.map +0 -1
  284. package/dist/core/transform/symbol/index.d.ts +0 -7
  285. package/dist/core/transform/symbol/index.d.ts.map +0 -1
  286. package/dist/core/transform/symbol/index.js +0 -7
  287. package/dist/core/transform/symbol/index.js.map +0 -1
  288. package/dist/core/transform/symbol/rename/index.d.ts.map +0 -1
  289. package/dist/core/transform/symbol/rename/index.js.map +0 -1
  290. package/dist/core/transform/symbol/rename/reference-updater.d.ts.map +0 -1
  291. package/dist/core/transform/symbol/rename/reference-updater.js.map +0 -1
  292. package/dist/core/transform/symbol/rename/rename-engine.d.ts.map +0 -1
  293. package/dist/core/transform/symbol/rename/rename-engine.js.map +0 -1
  294. package/dist/core/transform/symbol/rename/scope-analyzer.d.ts.map +0 -1
  295. package/dist/core/transform/symbol/rename/scope-analyzer.js.map +0 -1
  296. package/dist/core/transform/symbol/rename/types.d.ts.map +0 -1
  297. package/dist/core/transform/symbol/rename/types.js.map +0 -1
  298. package/dist/core/transform/types.d.ts +0 -185
  299. package/dist/core/transform/types.d.ts.map +0 -1
  300. package/dist/core/transform/types.js +0 -150
  301. package/dist/core/transform/types.js.map +0 -1
  302. package/dist/infrastructure/parser/factory.d.ts +0 -141
  303. package/dist/infrastructure/parser/factory.d.ts.map +0 -1
  304. package/dist/infrastructure/parser/factory.js +0 -306
  305. package/dist/infrastructure/parser/factory.js.map +0 -1
  306. package/dist/infrastructure/storage/file-watcher.d.ts +0 -84
  307. package/dist/infrastructure/storage/file-watcher.d.ts.map +0 -1
  308. package/dist/infrastructure/storage/file-watcher.js +0 -249
  309. package/dist/infrastructure/storage/file-watcher.js.map +0 -1
  310. package/dist/infrastructure/storage/path-utils.d.ts +0 -96
  311. package/dist/infrastructure/storage/path-utils.d.ts.map +0 -1
  312. package/dist/infrastructure/storage/path-utils.js +0 -272
  313. package/dist/infrastructure/storage/path-utils.js.map +0 -1
  314. package/dist/interfaces/cli/commands/analyze.command.d.ts +0 -11
  315. package/dist/interfaces/cli/commands/analyze.command.d.ts.map +0 -1
  316. package/dist/interfaces/cli/commands/analyze.command.js +0 -460
  317. package/dist/interfaces/cli/commands/analyze.command.js.map +0 -1
  318. package/dist/interfaces/cli/commands/deps.command.d.ts +0 -11
  319. package/dist/interfaces/cli/commands/deps.command.d.ts.map +0 -1
  320. package/dist/interfaces/cli/commands/deps.command.js +0 -143
  321. package/dist/interfaces/cli/commands/deps.command.js.map +0 -1
  322. package/dist/interfaces/cli/commands/extract.command.d.ts +0 -11
  323. package/dist/interfaces/cli/commands/extract.command.d.ts.map +0 -1
  324. package/dist/interfaces/cli/commands/extract.command.js +0 -314
  325. package/dist/interfaces/cli/commands/extract.command.js.map +0 -1
  326. package/dist/interfaces/cli/commands/inline.command.d.ts +0 -11
  327. package/dist/interfaces/cli/commands/inline.command.d.ts.map +0 -1
  328. package/dist/interfaces/cli/commands/inline.command.js +0 -208
  329. package/dist/interfaces/cli/commands/inline.command.js.map +0 -1
  330. package/dist/interfaces/cli/commands/refactor.command.d.ts +0 -11
  331. package/dist/interfaces/cli/commands/refactor.command.d.ts.map +0 -1
  332. package/dist/interfaces/cli/commands/refactor.command.js +0 -414
  333. package/dist/interfaces/cli/commands/refactor.command.js.map +0 -1
  334. package/dist/interfaces/cli/commands/search.command.d.ts +0 -11
  335. package/dist/interfaces/cli/commands/search.command.d.ts.map +0 -1
  336. package/dist/interfaces/cli/commands/search.command.js +0 -409
  337. package/dist/interfaces/cli/commands/search.command.js.map +0 -1
  338. package/dist/interfaces/cli/commands/shift.command.d.ts +0 -11
  339. package/dist/interfaces/cli/commands/shift.command.d.ts.map +0 -1
  340. package/dist/interfaces/cli/commands/shift.command.js +0 -143
  341. package/dist/interfaces/cli/commands/shift.command.js.map +0 -1
  342. package/dist/plugins/python/analyzers/complexity-analyzer.d.ts +0 -50
  343. package/dist/plugins/python/analyzers/complexity-analyzer.d.ts.map +0 -1
  344. package/dist/plugins/python/analyzers/complexity-analyzer.js +0 -172
  345. package/dist/plugins/python/analyzers/complexity-analyzer.js.map +0 -1
  346. package/dist/plugins/python/analyzers/duplication-detector.d.ts +0 -39
  347. package/dist/plugins/python/analyzers/duplication-detector.d.ts.map +0 -1
  348. package/dist/plugins/python/analyzers/duplication-detector.js +0 -146
  349. package/dist/plugins/python/analyzers/duplication-detector.js.map +0 -1
  350. package/dist/plugins/python/analyzers/error-handling-checker.d.ts +0 -28
  351. package/dist/plugins/python/analyzers/error-handling-checker.d.ts.map +0 -1
  352. package/dist/plugins/python/analyzers/error-handling-checker.js +0 -143
  353. package/dist/plugins/python/analyzers/error-handling-checker.js.map +0 -1
  354. package/dist/plugins/python/analyzers/naming-checker.d.ts +0 -56
  355. package/dist/plugins/python/analyzers/naming-checker.d.ts.map +0 -1
  356. package/dist/plugins/python/analyzers/naming-checker.js +0 -220
  357. package/dist/plugins/python/analyzers/naming-checker.js.map +0 -1
  358. package/dist/plugins/python/analyzers/pattern-detector.d.ts +0 -44
  359. package/dist/plugins/python/analyzers/pattern-detector.d.ts.map +0 -1
  360. package/dist/plugins/python/analyzers/pattern-detector.js +0 -222
  361. package/dist/plugins/python/analyzers/pattern-detector.js.map +0 -1
  362. package/dist/plugins/python/analyzers/security-checker.d.ts +0 -56
  363. package/dist/plugins/python/analyzers/security-checker.d.ts.map +0 -1
  364. package/dist/plugins/python/analyzers/security-checker.js +0 -279
  365. package/dist/plugins/python/analyzers/security-checker.js.map +0 -1
  366. package/dist/plugins/python/analyzers/type-safety-checker.d.ts +0 -44
  367. package/dist/plugins/python/analyzers/type-safety-checker.d.ts.map +0 -1
  368. package/dist/plugins/python/analyzers/type-safety-checker.js +0 -177
  369. package/dist/plugins/python/analyzers/type-safety-checker.js.map +0 -1
  370. package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts +0 -37
  371. package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts.map +0 -1
  372. package/dist/plugins/python/analyzers/unused-symbol-detector.js +0 -141
  373. package/dist/plugins/python/analyzers/unused-symbol-detector.js.map +0 -1
  374. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts +0 -41
  375. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts.map +0 -1
  376. package/dist/plugins/swift/analyzers/complexity-analyzer.js +0 -206
  377. package/dist/plugins/swift/analyzers/complexity-analyzer.js.map +0 -1
  378. package/dist/plugins/swift/analyzers/duplication-detector.d.ts +0 -89
  379. package/dist/plugins/swift/analyzers/duplication-detector.d.ts.map +0 -1
  380. package/dist/plugins/swift/analyzers/duplication-detector.js +0 -271
  381. package/dist/plugins/swift/analyzers/duplication-detector.js.map +0 -1
  382. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts +0 -34
  383. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts.map +0 -1
  384. package/dist/plugins/swift/analyzers/error-handling-checker.js +0 -135
  385. package/dist/plugins/swift/analyzers/error-handling-checker.js.map +0 -1
  386. package/dist/plugins/swift/analyzers/naming-checker.d.ts +0 -47
  387. package/dist/plugins/swift/analyzers/naming-checker.d.ts.map +0 -1
  388. package/dist/plugins/swift/analyzers/naming-checker.js +0 -161
  389. package/dist/plugins/swift/analyzers/naming-checker.js.map +0 -1
  390. package/dist/plugins/swift/analyzers/pattern-detector.d.ts +0 -78
  391. package/dist/plugins/swift/analyzers/pattern-detector.d.ts.map +0 -1
  392. package/dist/plugins/swift/analyzers/pattern-detector.js +0 -247
  393. package/dist/plugins/swift/analyzers/pattern-detector.js.map +0 -1
  394. package/dist/plugins/swift/analyzers/security-checker.d.ts +0 -38
  395. package/dist/plugins/swift/analyzers/security-checker.d.ts.map +0 -1
  396. package/dist/plugins/swift/analyzers/security-checker.js +0 -135
  397. package/dist/plugins/swift/analyzers/security-checker.js.map +0 -1
  398. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts +0 -41
  399. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts.map +0 -1
  400. package/dist/plugins/swift/analyzers/type-safety-checker.js +0 -121
  401. package/dist/plugins/swift/analyzers/type-safety-checker.js.map +0 -1
  402. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts +0 -38
  403. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts.map +0 -1
  404. package/dist/plugins/swift/analyzers/unused-symbol-detector.js +0 -211
  405. package/dist/plugins/swift/analyzers/unused-symbol-detector.js.map +0 -1
  406. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts +0 -39
  407. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts.map +0 -1
  408. package/dist/plugins/typescript/analyzers/complexity-analyzer.js +0 -196
  409. package/dist/plugins/typescript/analyzers/complexity-analyzer.js.map +0 -1
  410. package/dist/plugins/typescript/analyzers/duplication-detector.d.ts +0 -181
  411. package/dist/plugins/typescript/analyzers/duplication-detector.d.ts.map +0 -1
  412. package/dist/plugins/typescript/analyzers/duplication-detector.js +0 -695
  413. package/dist/plugins/typescript/analyzers/duplication-detector.js.map +0 -1
  414. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts +0 -26
  415. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts.map +0 -1
  416. package/dist/plugins/typescript/analyzers/error-handling-checker.js +0 -84
  417. package/dist/plugins/typescript/analyzers/error-handling-checker.js.map +0 -1
  418. package/dist/plugins/typescript/analyzers/naming-checker.d.ts +0 -30
  419. package/dist/plugins/typescript/analyzers/naming-checker.d.ts.map +0 -1
  420. package/dist/plugins/typescript/analyzers/naming-checker.js +0 -116
  421. package/dist/plugins/typescript/analyzers/naming-checker.js.map +0 -1
  422. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts +0 -80
  423. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts.map +0 -1
  424. package/dist/plugins/typescript/analyzers/pattern-detector.js +0 -267
  425. package/dist/plugins/typescript/analyzers/pattern-detector.js.map +0 -1
  426. package/dist/plugins/typescript/analyzers/security-checker.d.ts +0 -34
  427. package/dist/plugins/typescript/analyzers/security-checker.d.ts.map +0 -1
  428. package/dist/plugins/typescript/analyzers/security-checker.js +0 -126
  429. package/dist/plugins/typescript/analyzers/security-checker.js.map +0 -1
  430. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts +0 -32
  431. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts.map +0 -1
  432. package/dist/plugins/typescript/analyzers/type-safety-checker.js +0 -86
  433. package/dist/plugins/typescript/analyzers/type-safety-checker.js.map +0 -1
  434. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts +0 -47
  435. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts.map +0 -1
  436. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js +0 -152
  437. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js.map +0 -1
  438. /package/dist/core/{transform/symbol/change-signature → change-signature}/index.d.ts +0 -0
  439. /package/dist/core/{transform/symbol/change-signature → change-signature}/index.js +0 -0
  440. /package/dist/core/{transform/symbol/change-signature → change-signature}/signature-parser.js +0 -0
  441. /package/dist/core/{transform/symbol/change-signature → change-signature}/types.js +0 -0
  442. /package/dist/core/{transform/location/move-file → move-file}/index.d.ts +0 -0
  443. /package/dist/core/{transform/location/move-file → move-file}/index.js +0 -0
  444. /package/dist/core/{transform/location/move-file → move-file}/types.js +0 -0
  445. /package/dist/core/{transform/location/move-member → move-member}/index.d.ts +0 -0
  446. /package/dist/core/{transform/location/move-member → move-member}/index.js +0 -0
  447. /package/dist/core/{transform/location/move-member → move-member}/member-extractor.js +0 -0
  448. /package/dist/core/{transform/location/move-member → move-member}/types.js +0 -0
  449. /package/dist/core/{transform/symbol/rename → rename}/index.d.ts +0 -0
  450. /package/dist/core/{transform/symbol/rename → rename}/index.js +0 -0
  451. /package/dist/core/{transform/symbol/rename → rename}/types.js +0 -0
  452. /package/dist/core/{transform/shared → shared}/symbol-finder.js +0 -0
@@ -1,730 +0,0 @@
1
- /**
2
- * 提取函式重構器
3
- * 將選取的程式碼片段提取為獨立函式
4
- */
5
- import * as ts from 'typescript';
6
- import { TypeScriptParser } from '../../../../plugins/typescript/parser.js';
7
- /**
8
- * 函式提取分析器
9
- * 分析選取的程式碼是否適合提取為函式
10
- */
11
- export class ExtractionAnalyzer {
12
- parser;
13
- constructor() {
14
- this.parser = new TypeScriptParser();
15
- }
16
- /**
17
- * 分析程式碼片段的可提取性
18
- */
19
- async analyze(code, selection) {
20
- const issues = [];
21
- const variables = [];
22
- const dependencies = [];
23
- // 基本驗證
24
- if (!code || code.trim().length === 0) {
25
- issues.push('選取的程式碼為空');
26
- return { canExtract: false, issues, variables, dependencies };
27
- }
28
- // 解析 AST
29
- const ast = await this.parseCode(code);
30
- if (!ast) {
31
- issues.push('程式碼解析失敗');
32
- return { canExtract: false, issues, variables, dependencies };
33
- }
34
- // 分析變數使用
35
- const variableAnalysis = this.analyzeVariables(ast);
36
- variables.push(...variableAnalysis.variables);
37
- // 檢查提取限制
38
- this.checkExtractionConstraints(ast, selection, issues);
39
- // 分析依賴
40
- dependencies.push(...this.findDependencies(ast));
41
- // 推導返回值型別
42
- const returnType = this.extractReturnType(ast);
43
- return {
44
- canExtract: issues.length === 0,
45
- issues,
46
- variables,
47
- dependencies,
48
- returnType
49
- };
50
- }
51
- /**
52
- * 檢查提取限制
53
- */
54
- checkExtractionConstraints(ast, selection, issues) {
55
- // 檢查是否包含 return 語句
56
- const hasReturn = this.containsReturn(ast);
57
- // 檢查是否包含 break/continue
58
- if (this.containsJumpStatement(ast)) {
59
- issues.push('選取範圍包含 break 或 continue 語句');
60
- }
61
- // 檢查是否跨越語句邊界
62
- if (!this.isCompleteStatements(ast)) {
63
- issues.push('選取範圍不是完整的語句');
64
- }
65
- // 檢查巢狀函式定義
66
- if (this.containsFunctionDefinition(ast)) {
67
- issues.push('選取範圍包含函式定義');
68
- }
69
- // 檢查外部變數修改
70
- if (ast.code) {
71
- // 先找出所有宣告的變數
72
- const declaredVars = new Set();
73
- const declarationPattern = /(?:const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;
74
- let declMatch;
75
- while ((declMatch = declarationPattern.exec(ast.code)) !== null) {
76
- declaredVars.add(declMatch[1]);
77
- }
78
- // 然後找出所有賦值(簡化邏輯:只檢測真正的外部變數修改)
79
- // 使用更精確的模式:變數名後面直接跟 = (中間只能有空白)
80
- const simpleAssignmentPattern = /([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=(?!=)/g;
81
- const uniqueAssignments = new Set();
82
- let assignMatch;
83
- while ((assignMatch = simpleAssignmentPattern.exec(ast.code)) !== null) {
84
- const varName = assignMatch[1];
85
- const position = assignMatch.index || 0;
86
- const fullMatch = assignMatch[0]; // 例如 "varName ="
87
- // 檢查完整匹配中是否包含型別註解
88
- // 如果變數名前面有 ':' 字元,很可能是型別註解
89
- const beforeVar = ast.code.substring(Math.max(0, position - 5), position);
90
- if (beforeVar.includes(':') || beforeVar.includes('.')) {
91
- continue;
92
- }
93
- // 檢查是否為變數宣告
94
- const beforeDecl = ast.code.substring(Math.max(0, position - 10), position);
95
- if (/(?:const|let|var|type|interface)\s+$/.test(beforeDecl)) {
96
- continue;
97
- }
98
- // 檢查是否為外部變數(沒有在程式碼中宣告)
99
- if (!declaredVars.has(varName) &&
100
- !['return', 'function', 'if', 'else', 'for', 'while', 'case'].includes(varName)) {
101
- uniqueAssignments.add(varName);
102
- }
103
- }
104
- // FIXME: 外部變數檢測使用正則表達式太不可靠,暫時禁用
105
- // TODO: 未來使用真正的 TypeScript AST parser 改進
106
- // 如果有多個不同的外部變數修改,發出警告但不阻止提取
107
- const uniqueCount = uniqueAssignments.size;
108
- if (uniqueCount > 1) {
109
- // 暫時只警告,不阻止
110
- // const vars = Array.from(uniqueAssignments).join(', ');
111
- // issues.push(`警告:可能有多個返回值 (檢測到: ${vars})`);
112
- }
113
- }
114
- }
115
- /**
116
- * 分析變數使用情況
117
- */
118
- analyzeVariables(ast) {
119
- const variables = [];
120
- const definedVars = new Set();
121
- const usedVars = new Set();
122
- // 簡化實作:使用正規表達式解析變數
123
- if (ast.code) {
124
- // 找出程式碼中的變數使用
125
- const variableMatches = ast.code.match(/\b[a-zA-Z_$][a-zA-Z0-9_$]*\b/g) || [];
126
- // 過濾出真正的變數(排除關鍵字)
127
- const keywords = new Set(['if', 'else', 'for', 'while', 'do', 'break', 'continue',
128
- 'function', 'return', 'var', 'let', 'const', 'true', 'false', 'null',
129
- 'undefined', 'new', 'this', 'typeof', 'instanceof', 'console', 'log',
130
- 'map', 'filter', 'reduce', 'forEach', 'length', 'push', 'pop', 'item', 'i']);
131
- for (const match of variableMatches) {
132
- if (!keywords.has(match) && !definedVars.has(match)) {
133
- usedVars.add(match);
134
- }
135
- }
136
- // 檢查本地定義的變數
137
- const localDeclarations = ast.code.match(/(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g) || [];
138
- for (const decl of localDeclarations) {
139
- const varName = decl.replace(/(?:let|const|var)\s+/, '');
140
- definedVars.add(varName);
141
- usedVars.delete(varName); // 移除本地定義的變數
142
- }
143
- // 檢查函式參數
144
- const functionParams = ast.code.match(/function\s*\w*\s*\(([^)]*)\)/);
145
- if (functionParams && functionParams[1]) {
146
- const params = functionParams[1].split(',').map(p => p.trim().replace(/:\s*\w+/, ''));
147
- for (const param of params) {
148
- if (param) {
149
- definedVars.add(param);
150
- usedVars.delete(param);
151
- }
152
- }
153
- }
154
- }
155
- // 建立變數資訊
156
- for (const varName of usedVars) {
157
- variables.push({
158
- name: varName,
159
- type: 'any', // 簡化實作
160
- isParameter: true,
161
- isReturned: false,
162
- scope: 'closure',
163
- usages: []
164
- });
165
- }
166
- return { variables };
167
- }
168
- /**
169
- * 使用 TypeScript Parser 解析程式碼
170
- */
171
- async parseCode(code) {
172
- try {
173
- // 使用 TypeScript Parser 解析程式碼片段
174
- // 為了解析片段,我們將它包裝在一個函式中以形成完整的語句
175
- const wrappedCode = `function __extractedCode__() {\n${code}\n}`;
176
- const virtualPath = 'virtual-extract.ts';
177
- const tsAST = await this.parser.parse(wrappedCode, virtualPath);
178
- const sourceFile = tsAST.tsSourceFile;
179
- if (!sourceFile) {
180
- return null;
181
- }
182
- // 找到我們包裝的函式內部的語句
183
- let extractedStatements = null;
184
- ts.forEachChild(sourceFile, (node) => {
185
- if (ts.isFunctionDeclaration(node) && node.name?.text === '__extractedCode__') {
186
- if (node.body) {
187
- extractedStatements = node.body;
188
- }
189
- }
190
- });
191
- if (!extractedStatements) {
192
- return null;
193
- }
194
- // 建立我們的 ASTNode 結構(相容舊版介面)
195
- return {
196
- type: 'Program',
197
- start: 0,
198
- end: code.length,
199
- loc: {
200
- start: { line: 1, column: 0 },
201
- end: { line: code.split('\n').length, column: 0 }
202
- },
203
- children: [],
204
- code,
205
- tsNode: extractedStatements, // 保存 TypeScript AST 節點
206
- tsSourceFile: sourceFile // 保存 SourceFile 供型別檢查使用
207
- };
208
- }
209
- catch (error) {
210
- console.debug('Parse error:', error);
211
- return null;
212
- }
213
- }
214
- /**
215
- * 遍歷 AST
216
- */
217
- traverse(node, visitor) {
218
- visitor(node);
219
- if (node.children) {
220
- for (const child of node.children) {
221
- this.traverse(child, visitor);
222
- }
223
- }
224
- }
225
- /**
226
- * 檢查是否包含 return 語句(使用真實 TypeScript AST)
227
- */
228
- containsReturn(ast) {
229
- if (!ast.tsNode) {
230
- // 降級到舊邏輯
231
- let hasReturn = false;
232
- this.traverse(ast, (node) => {
233
- if (node.type === 'ReturnStatement') {
234
- hasReturn = true;
235
- }
236
- });
237
- return hasReturn;
238
- }
239
- let hasReturn = false;
240
- const visit = (node) => {
241
- if (ts.isReturnStatement(node)) {
242
- hasReturn = true;
243
- return; // 找到就可以停止
244
- }
245
- ts.forEachChild(node, visit);
246
- };
247
- visit(ast.tsNode);
248
- return hasReturn;
249
- }
250
- /**
251
- * 推導返回值型別
252
- */
253
- extractReturnType(ast) {
254
- if (!ast.tsNode || !ast.tsSourceFile) {
255
- // 降級:簡單檢查是否有 return
256
- return this.containsReturn(ast) ? 'any' : 'void';
257
- }
258
- // 收集所有 return 語句的型別
259
- const returnTypes = [];
260
- let hasReturnWithoutValue = false;
261
- const visit = (node) => {
262
- if (ts.isReturnStatement(node)) {
263
- if (node.expression) {
264
- // 嘗試推導 return 表達式的型別
265
- const type = this.inferTypeFromExpression(node.expression, ast.tsSourceFile);
266
- returnTypes.push(type);
267
- }
268
- else {
269
- hasReturnWithoutValue = true;
270
- }
271
- }
272
- ts.forEachChild(node, visit);
273
- };
274
- visit(ast.tsNode);
275
- // 決定最終返回型別
276
- if (returnTypes.length === 0 && !hasReturnWithoutValue) {
277
- return 'void';
278
- }
279
- if (hasReturnWithoutValue && returnTypes.length === 0) {
280
- return 'void';
281
- }
282
- if (returnTypes.length === 0) {
283
- return 'void';
284
- }
285
- // 如果所有返回型別都相同,使用該型別
286
- const uniqueTypes = [...new Set(returnTypes)];
287
- if (uniqueTypes.length === 1) {
288
- return uniqueTypes[0];
289
- }
290
- // 如果有多種型別,使用 union type
291
- return uniqueTypes.join(' | ');
292
- }
293
- /**
294
- * 從表達式推導型別
295
- */
296
- inferTypeFromExpression(expr, sourceFile) {
297
- // 字串字面量
298
- if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
299
- return 'string';
300
- }
301
- // 數字字面量
302
- if (ts.isNumericLiteral(expr)) {
303
- return 'number';
304
- }
305
- // 布林字面量
306
- if (expr.kind === ts.SyntaxKind.TrueKeyword || expr.kind === ts.SyntaxKind.FalseKeyword) {
307
- return 'boolean';
308
- }
309
- // null
310
- if (expr.kind === ts.SyntaxKind.NullKeyword) {
311
- return 'null';
312
- }
313
- // undefined
314
- if (expr.kind === ts.SyntaxKind.UndefinedKeyword) {
315
- return 'undefined';
316
- }
317
- // 識別符號(變數)- 嘗試從上下文推導
318
- if (ts.isIdentifier(expr)) {
319
- // 檢查是否是參數或已知變數
320
- const varName = expr.text;
321
- // 嘗試在包裝函式的參數中查找型別
322
- // 這裡簡化處理,實際專案中應該從完整檔案的上下文取得
323
- const text = sourceFile.text;
324
- const paramPattern = new RegExp(`\\b${varName}\\s*:\\s*([a-zA-Z][a-zA-Z0-9]*)`);
325
- const match = text.match(paramPattern);
326
- if (match) {
327
- return match[1];
328
- }
329
- return 'any';
330
- }
331
- // 陣列字面量
332
- if (ts.isArrayLiteralExpression(expr)) {
333
- if (expr.elements.length === 0) {
334
- return 'any[]';
335
- }
336
- const elementType = this.inferTypeFromExpression(expr.elements[0], sourceFile);
337
- return `${elementType}[]`;
338
- }
339
- // 物件字面量
340
- if (ts.isObjectLiteralExpression(expr)) {
341
- return 'object';
342
- }
343
- // 函式呼叫
344
- if (ts.isCallExpression(expr)) {
345
- // 簡化:返回 any
346
- return 'any';
347
- }
348
- // 預設返回 any
349
- return 'any';
350
- }
351
- /**
352
- * 檢查是否包含跳躍語句
353
- */
354
- containsJumpStatement(ast) {
355
- let hasJump = false;
356
- this.traverse(ast, (node) => {
357
- if (node.type === 'BreakStatement' || node.type === 'ContinueStatement') {
358
- hasJump = true;
359
- }
360
- });
361
- return hasJump;
362
- }
363
- /**
364
- * 檢查是否為完整語句
365
- */
366
- isCompleteStatements(ast) {
367
- // 簡化實作:假設總是完整的
368
- return true;
369
- }
370
- /**
371
- * 檢查是否包含函式定義
372
- */
373
- containsFunctionDefinition(ast) {
374
- let hasFunction = false;
375
- this.traverse(ast, (node) => {
376
- if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
377
- hasFunction = true;
378
- }
379
- });
380
- return hasFunction;
381
- }
382
- /**
383
- * 找出依賴項
384
- */
385
- findDependencies(ast) {
386
- const dependencies = [];
387
- // 簡化實作
388
- return dependencies;
389
- }
390
- }
391
- /**
392
- * 函式提取器主類
393
- */
394
- export class FunctionExtractor {
395
- analyzer = new ExtractionAnalyzer();
396
- /**
397
- * 提取函式 (別名,保持向後相容)
398
- * 支援兩種呼叫方式:
399
- * 1. extractFunction(code, selection, config)
400
- * 2. extractFunction(code, start, end, name) - 舊格式
401
- */
402
- async extractFunction(code, selectionOrStart, configOrEnd, nameOrUndefined) {
403
- // 檢查是否為舊格式呼叫 (4 個參數)
404
- if (typeof selectionOrStart === 'number' && typeof configOrEnd === 'number') {
405
- // 將行號轉換為 Range 格式
406
- const startLine = selectionOrStart;
407
- const endLine = configOrEnd;
408
- const selection = {
409
- start: { line: startLine, column: 0 },
410
- end: { line: endLine, column: 0 }
411
- };
412
- const config = {
413
- functionName: nameOrUndefined,
414
- generateComments: true,
415
- preserveFormatting: true,
416
- validateExtraction: true
417
- };
418
- return this.extract(code, selection, config);
419
- }
420
- // 新格式呼叫
421
- return this.extract(code, selectionOrStart, configOrEnd);
422
- }
423
- /**
424
- * 提取函式
425
- */
426
- async extract(code, selection, config = {
427
- generateComments: true,
428
- preserveFormatting: true,
429
- validateExtraction: true,
430
- insertionPoint: 'before'
431
- }) {
432
- // 輸入驗證
433
- if (typeof code !== 'string') {
434
- throw new Error('程式碼必須是字串');
435
- }
436
- if (!selection || !this.isValidRange(selection)) {
437
- throw new Error('選取範圍無效');
438
- }
439
- // 分析可提取性(現在是 async)
440
- const analysis = await this.analyzer.analyze(code, selection);
441
- if (!analysis.canExtract) {
442
- return {
443
- success: false,
444
- functionName: '',
445
- edits: [],
446
- parameters: [],
447
- errors: analysis.issues,
448
- warnings: []
449
- };
450
- }
451
- // 提取選取的程式碼
452
- const selectedCode = this.extractSelectedCode(code, selection);
453
- // 產生函式名稱
454
- const functionName = config.functionName || this.generateFunctionName(selectedCode);
455
- // 產生函式程式碼(使用推導出的返回型別)
456
- const functionCode = this.generateFunction(functionName, selectedCode, analysis.variables, config, analysis.returnType);
457
- // 檢查是否為跨檔案提取
458
- if (config.targetFile && config.sourceFile) {
459
- // 跨檔案提取模式
460
- return await this.extractToSeparateFile(code, selection, functionName, functionCode, analysis.variables, config);
461
- }
462
- // 一般提取模式(同檔案)
463
- const edits = this.generateEdits(code, selection, functionName, functionCode, analysis.variables);
464
- return {
465
- success: true,
466
- functionName,
467
- edits,
468
- parameters: analysis.variables,
469
- returnType: analysis.returnType,
470
- errors: [],
471
- warnings: []
472
- };
473
- }
474
- /**
475
- * 驗證範圍格式
476
- */
477
- isValidRange(range) {
478
- return range.start && range.end &&
479
- typeof range.start.line === 'number' &&
480
- typeof range.start.column === 'number' &&
481
- typeof range.end.line === 'number' &&
482
- typeof range.end.column === 'number' &&
483
- (range.start.line < range.end.line ||
484
- (range.start.line === range.end.line && range.start.column < range.end.column));
485
- }
486
- /**
487
- * 提取選取的程式碼
488
- */
489
- extractSelectedCode(code, selection) {
490
- const lines = code.split('\n');
491
- const selectedLines = [];
492
- for (let i = selection.start.line - 1; i < selection.end.line; i++) {
493
- if (i < 0 || i >= lines.length) {
494
- continue;
495
- }
496
- let line = lines[i];
497
- // 處理開始行
498
- if (i === selection.start.line - 1) {
499
- line = line.substring(selection.start.column);
500
- }
501
- // 處理結束行
502
- if (i === selection.end.line - 1) {
503
- line = line.substring(0, selection.end.column - (i === selection.start.line - 1 ? selection.start.column : 0));
504
- }
505
- selectedLines.push(line);
506
- }
507
- return selectedLines.join('\n');
508
- }
509
- /**
510
- * 產生函式名稱
511
- */
512
- generateFunctionName(code) {
513
- // 簡單的函式名稱生成邏輯
514
- const words = code.match(/\b[a-zA-Z_][a-zA-Z0-9_]*\b/g) || [];
515
- const uniqueWords = [...new Set(words)].filter(word => !['const', 'let', 'var', 'if', 'else', 'for', 'while', 'function', 'return'].includes(word));
516
- if (uniqueWords.length > 0) {
517
- return `extracted${uniqueWords[0].charAt(0).toUpperCase()}${uniqueWords[0].slice(1)}`;
518
- }
519
- return 'extractedFunction';
520
- }
521
- /**
522
- * 產生函式程式碼
523
- */
524
- generateFunction(functionName, code, parameters, config, inferredReturnType) {
525
- // 生成帶型別的參數列表
526
- const params = parameters
527
- .filter(p => p.isParameter)
528
- .map(p => `${p.name}: ${p.type}`)
529
- .join(', ');
530
- const returnVars = parameters.filter(p => p.isReturned);
531
- const returnStatement = returnVars.length > 0
532
- ? `\n return ${returnVars.map(v => v.name).join(', ')};`
533
- : '';
534
- // 使用推導出的返回型別,如果沒有則降級到舊邏輯
535
- let returnType;
536
- if (inferredReturnType) {
537
- returnType = `: ${inferredReturnType}`;
538
- }
539
- else {
540
- const hasReturn = code.includes('return') || returnVars.length > 0;
541
- returnType = hasReturn ? ': any' : ': void';
542
- }
543
- const comment = config.generateComments
544
- ? `/**\n * 提取的函式\n * @param ${params.split(', ').map(p => `${p.split(':')[0]} 參數`).join('\n * @param ')}\n */\n`
545
- : '';
546
- // 縮排程式碼
547
- const indentedCode = code.split('\n').map(line => ` ${line}`).join('\n');
548
- return `${comment}function ${functionName}(${params})${returnType} {${indentedCode}${returnStatement}\n}`;
549
- }
550
- /**
551
- * 產生編輯操作
552
- */
553
- generateEdits(originalCode, selection, functionName, functionCode, parameters) {
554
- const edits = [];
555
- // 1. 替換選取的程式碼為函式呼叫
556
- const callParams = parameters
557
- .filter(p => p.isParameter)
558
- .map(p => p.name)
559
- .join(', ');
560
- const returnVars = parameters.filter(p => p.isReturned);
561
- const assignment = returnVars.length > 0
562
- ? `${returnVars.map(v => v.name).join(', ')} = `
563
- : '';
564
- const functionCall = `${assignment}${functionName}(${callParams});`;
565
- edits.push({
566
- range: selection,
567
- newText: functionCall,
568
- type: 'replace'
569
- });
570
- // 2. 插入函式定義
571
- // 簡化實作:在檔案開頭插入
572
- edits.push({
573
- range: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
574
- newText: functionCode + '\n\n',
575
- type: 'insert'
576
- });
577
- return edits;
578
- }
579
- /**
580
- * 跨檔案提取:將函式提取到獨立檔案
581
- */
582
- async extractToSeparateFile(code, selection, functionName, functionCode, parameters, config) {
583
- const fs = await import('fs/promises');
584
- const path = await import('path');
585
- try {
586
- // 計算相對 import 路徑
587
- const sourceDir = path.dirname(config.sourceFile);
588
- const targetDir = path.dirname(config.targetFile);
589
- const targetFileName = path.basename(config.targetFile, path.extname(config.targetFile));
590
- // 計算相對路徑
591
- let relativePath = path.relative(sourceDir, config.targetFile);
592
- // 移除副檔名
593
- if (relativePath.endsWith('.ts')) {
594
- relativePath = relativePath.slice(0, -3);
595
- }
596
- else if (relativePath.endsWith('.js')) {
597
- relativePath = relativePath.slice(0, -3);
598
- }
599
- // 確保路徑以 ./ 或 ../ 開頭
600
- if (!relativePath.startsWith('.')) {
601
- relativePath = './' + relativePath;
602
- }
603
- // 生成 import 語句
604
- const importStatement = `import { ${functionName} } from '${relativePath}';`;
605
- // 生成 export function(移除註解中的 @param 部分,因為跨檔案不需要)
606
- const exportedFunctionCode = functionCode
607
- .replace(/\/\*\*[\s\S]*?\*\/\n?/, '') // 移除註解
608
- .replace(/^function /, 'export function '); // 加上 export
609
- // 讀取或建立目標檔案內容
610
- let targetFileContent = '';
611
- try {
612
- targetFileContent = await fs.readFile(config.targetFile, 'utf-8');
613
- }
614
- catch (error) {
615
- // 檔案不存在,建立新檔案
616
- targetFileContent = '';
617
- }
618
- // 在目標檔案末尾加入函式
619
- if (targetFileContent.trim().length > 0) {
620
- targetFileContent += '\n\n' + exportedFunctionCode + '\n';
621
- }
622
- else {
623
- targetFileContent = exportedFunctionCode + '\n';
624
- }
625
- // 生成原始檔案的編輯:加入 import + 替換為函式呼叫
626
- const edits = [];
627
- // 1. 替換選取範圍為函式呼叫
628
- const callParams = parameters
629
- .filter(p => p.isParameter)
630
- .map(p => p.name)
631
- .join(', ');
632
- const returnVars = parameters.filter(p => p.isReturned);
633
- const assignment = returnVars.length > 0
634
- ? `${returnVars.map(v => v.name).join(', ')} = `
635
- : '';
636
- const functionCall = `${assignment}${functionName}(${callParams});`;
637
- edits.push({
638
- range: selection,
639
- newText: functionCall,
640
- type: 'replace'
641
- });
642
- // 2. 在檔案開頭加入 import 語句
643
- edits.push({
644
- range: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
645
- newText: importStatement + '\n',
646
- type: 'insert'
647
- });
648
- return {
649
- success: true,
650
- functionName,
651
- edits,
652
- parameters,
653
- errors: [],
654
- warnings: [],
655
- targetFileContent,
656
- importStatement
657
- };
658
- }
659
- catch (error) {
660
- return {
661
- success: false,
662
- functionName,
663
- edits: [],
664
- parameters: [],
665
- errors: [`跨檔案提取失敗: ${error instanceof Error ? error.message : String(error)}`],
666
- warnings: []
667
- };
668
- }
669
- }
670
- /**
671
- * 批次提取
672
- */
673
- async extractMultiple(extractions) {
674
- const results = await Promise.all(extractions.map(({ code, selection, config }) => this.extract(code, selection, config)));
675
- return results;
676
- }
677
- /**
678
- * 預覽提取結果
679
- */
680
- async preview(code, selection, config) {
681
- const result = await this.extract(code, selection, config);
682
- if (!result.success) {
683
- throw new Error(`提取預覽失敗: ${result.errors.join(', ')}`);
684
- }
685
- // 應用編輯操作
686
- let modifiedCode = code;
687
- for (const edit of result.edits.reverse()) { // 反向應用避免位置偏移
688
- modifiedCode = this.applyEdit(modifiedCode, edit);
689
- }
690
- return {
691
- originalCode: code,
692
- modifiedCode,
693
- functionCode: result.edits.find(edit => edit.type === 'insert')?.newText || ''
694
- };
695
- }
696
- /**
697
- * 應用編輯操作
698
- */
699
- applyEdit(code, edit) {
700
- const lines = code.split('\n');
701
- switch (edit.type) {
702
- case 'replace':
703
- // 簡化實作
704
- return code.substring(0, this.rangeToOffset(code, edit.range.start)) +
705
- edit.newText +
706
- code.substring(this.rangeToOffset(code, edit.range.end));
707
- case 'insert':
708
- const offset = this.rangeToOffset(code, edit.range.start);
709
- return code.substring(0, offset) + edit.newText + code.substring(offset);
710
- case 'delete':
711
- return code.substring(0, this.rangeToOffset(code, edit.range.start)) +
712
- code.substring(this.rangeToOffset(code, edit.range.end));
713
- default:
714
- return code;
715
- }
716
- }
717
- /**
718
- * 將範圍轉換為偏移量
719
- */
720
- rangeToOffset(code, position) {
721
- const lines = code.split('\n');
722
- let offset = 0;
723
- for (let i = 0; i < position.line - 1 && i < lines.length; i++) {
724
- offset += lines[i].length + 1; // +1 for newline
725
- }
726
- offset += position.column;
727
- return Math.min(offset, code.length);
728
- }
729
- }
730
- //# sourceMappingURL=extract-function.js.map