agent-ide 0.1.10 → 0.3.3
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.
- package/README.md +28 -278
- package/dist/application/events/event-bus.d.ts.map +1 -1
- package/dist/application/events/event-bus.js.map +1 -1
- package/dist/application/index.d.ts +3 -1
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +10 -5
- package/dist/application/index.js.map +1 -1
- package/dist/application/services/cache-coordinator.service.d.ts.map +1 -1
- package/dist/application/services/cache-coordinator.service.js.map +1 -1
- package/dist/application/services/error-handler.service.d.ts.map +1 -1
- package/dist/application/services/error-handler.service.js.map +1 -1
- package/dist/application/services/module-coordinator.service.d.ts +13 -3
- package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
- package/dist/application/services/module-coordinator.service.js +65 -25
- package/dist/application/services/module-coordinator.service.js.map +1 -1
- package/dist/application/services/session-manager.service.d.ts.map +1 -1
- package/dist/application/services/session-manager.service.js.map +1 -1
- package/dist/application/services/workflow-engine.service.d.ts +1 -1
- package/dist/application/services/workflow-engine.service.d.ts.map +1 -1
- package/dist/application/services/workflow-engine.service.js.map +1 -1
- package/dist/application/state/state-manager.d.ts +3 -3
- package/dist/application/state/state-manager.d.ts.map +1 -1
- package/dist/application/state/state-manager.js +3 -3
- package/dist/application/state/state-manager.js.map +1 -1
- package/dist/application/types.d.ts.map +1 -1
- package/dist/application/workflows/analysis-workflow.d.ts +1 -1
- package/dist/application/workflows/analysis-workflow.d.ts.map +1 -1
- package/dist/application/workflows/analysis-workflow.js +1 -1
- package/dist/application/workflows/analysis-workflow.js.map +1 -1
- package/dist/application/workflows/base-workflow.d.ts.map +1 -1
- package/dist/application/workflows/base-workflow.js.map +1 -1
- package/dist/application/workflows/index.d.ts +2 -2
- package/dist/application/workflows/index.d.ts.map +1 -1
- package/dist/application/workflows/index.js +2 -2
- package/dist/application/workflows/index.js.map +1 -1
- package/dist/application/workflows/refactor-workflow.d.ts +1 -1
- package/dist/application/workflows/refactor-workflow.d.ts.map +1 -1
- package/dist/application/workflows/refactor-workflow.js +1 -1
- package/dist/application/workflows/refactor-workflow.js.map +1 -1
- package/dist/core/dependency/cycle-detector.d.ts +1 -1
- package/dist/core/dependency/cycle-detector.d.ts.map +1 -1
- package/dist/core/dependency/cycle-detector.js +1 -1
- package/dist/core/dependency/cycle-detector.js.map +1 -1
- package/dist/core/dependency/dependency-analyzer.d.ts +3 -1
- package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -1
- package/dist/core/dependency/dependency-analyzer.js +35 -24
- package/dist/core/dependency/dependency-analyzer.js.map +1 -1
- package/dist/core/dependency/types.d.ts.map +1 -1
- package/dist/core/indexing/file-index.d.ts.map +1 -1
- package/dist/core/indexing/file-index.js +1 -1
- package/dist/core/indexing/file-index.js.map +1 -1
- package/dist/core/indexing/file-watcher.d.ts +4 -2
- package/dist/core/indexing/file-watcher.d.ts.map +1 -1
- package/dist/core/indexing/file-watcher.js +10 -6
- package/dist/core/indexing/file-watcher.js.map +1 -1
- package/dist/core/indexing/index-engine.d.ts +7 -1
- package/dist/core/indexing/index-engine.d.ts.map +1 -1
- package/dist/core/indexing/index-engine.js +49 -16
- package/dist/core/indexing/index-engine.js.map +1 -1
- package/dist/core/indexing/symbol-index.d.ts +4 -0
- package/dist/core/indexing/symbol-index.d.ts.map +1 -1
- package/dist/core/indexing/symbol-index.js +17 -0
- package/dist/core/indexing/symbol-index.js.map +1 -1
- package/dist/core/indexing/types.d.ts.map +1 -1
- package/dist/core/search/engines/text-engine.d.ts +3 -0
- package/dist/core/search/engines/text-engine.d.ts.map +1 -1
- package/dist/core/search/engines/text-engine.js +8 -7
- package/dist/core/search/engines/text-engine.js.map +1 -1
- package/dist/core/search/service.d.ts +2 -1
- package/dist/core/search/service.d.ts.map +1 -1
- package/dist/core/search/service.js +3 -3
- package/dist/core/search/service.js.map +1 -1
- package/dist/core/search/types.d.ts.map +1 -1
- package/dist/core/snapshot/index.d.ts +7 -0
- package/dist/core/snapshot/index.d.ts.map +1 -0
- package/dist/core/snapshot/index.js +6 -0
- package/dist/core/snapshot/index.js.map +1 -0
- package/dist/core/snapshot/snapshot-generator.d.ts +66 -0
- package/dist/core/snapshot/snapshot-generator.d.ts.map +1 -0
- package/dist/core/snapshot/snapshot-generator.js +258 -0
- package/dist/core/snapshot/snapshot-generator.js.map +1 -0
- package/dist/core/snapshot/types.d.ts +67 -0
- package/dist/core/snapshot/types.d.ts.map +1 -0
- package/dist/core/snapshot/types.js +25 -0
- package/dist/core/snapshot/types.js.map +1 -0
- package/dist/core/transform/index.d.ts +10 -0
- package/dist/core/transform/index.d.ts.map +1 -0
- package/dist/core/transform/index.js +21 -0
- package/dist/core/transform/index.js.map +1 -0
- package/dist/core/transform/location/index.d.ts +8 -0
- package/dist/core/transform/location/index.d.ts.map +1 -0
- package/dist/core/transform/location/index.js +9 -0
- package/dist/core/transform/location/index.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/import-resolver.d.ts +1 -1
- package/dist/core/transform/location/move-file/import-resolver.d.ts.map +1 -0
- package/dist/core/{move → transform/location/move-file}/import-resolver.js +19 -12
- package/dist/core/transform/location/move-file/import-resolver.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/index.d.ts +2 -2
- package/dist/core/transform/location/move-file/index.d.ts.map +1 -0
- package/dist/core/{move → transform/location/move-file}/index.js +2 -2
- package/dist/core/transform/location/move-file/index.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/move-service.d.ts +5 -3
- package/dist/core/transform/location/move-file/move-service.d.ts.map +1 -0
- package/dist/core/{move → transform/location/move-file}/move-service.js +74 -92
- package/dist/core/transform/location/move-file/move-service.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/types.d.ts +1 -1
- package/dist/core/transform/location/move-file/types.d.ts.map +1 -0
- package/dist/core/transform/location/move-file/types.js.map +1 -0
- package/dist/core/transform/location/move-member/index.d.ts +10 -0
- package/dist/core/transform/location/move-member/index.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/index.js +12 -0
- package/dist/core/transform/location/move-member/index.js.map +1 -0
- package/dist/core/transform/location/move-member/member-extractor.d.ts +96 -0
- package/dist/core/transform/location/move-member/member-extractor.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/member-extractor.js +439 -0
- package/dist/core/transform/location/move-member/member-extractor.js.map +1 -0
- package/dist/core/transform/location/move-member/move-member-service.d.ts +87 -0
- package/dist/core/transform/location/move-member/move-member-service.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/move-member-service.js +412 -0
- package/dist/core/transform/location/move-member/move-member-service.js.map +1 -0
- package/dist/core/transform/location/move-member/types.d.ts +182 -0
- package/dist/core/transform/location/move-member/types.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/types.js +75 -0
- package/dist/core/transform/location/move-member/types.js.map +1 -0
- package/dist/core/transform/location/shift/file-generator.d.ts +45 -0
- package/dist/core/transform/location/shift/file-generator.d.ts.map +1 -0
- package/dist/core/transform/location/shift/file-generator.js +94 -0
- package/dist/core/transform/location/shift/file-generator.js.map +1 -0
- package/dist/core/transform/location/shift/index.d.ts +11 -0
- package/dist/core/transform/location/shift/index.d.ts.map +1 -0
- package/dist/core/transform/location/shift/index.js +13 -0
- package/dist/core/transform/location/shift/index.js.map +1 -0
- package/dist/core/transform/location/shift/line-extractor.d.ts +55 -0
- package/dist/core/transform/location/shift/line-extractor.d.ts.map +1 -0
- package/dist/core/transform/location/shift/line-extractor.js +123 -0
- package/dist/core/transform/location/shift/line-extractor.js.map +1 -0
- package/dist/core/transform/location/shift/shift-service.d.ts +57 -0
- package/dist/core/transform/location/shift/shift-service.d.ts.map +1 -0
- package/dist/core/transform/location/shift/shift-service.js +199 -0
- package/dist/core/transform/location/shift/shift-service.js.map +1 -0
- package/dist/core/transform/location/shift/types.d.ts +195 -0
- package/dist/core/transform/location/shift/types.d.ts.map +1 -0
- package/dist/core/transform/location/shift/types.js +89 -0
- package/dist/core/transform/location/shift/types.js.map +1 -0
- package/dist/core/transform/shared/code-editor.d.ts +70 -0
- package/dist/core/transform/shared/code-editor.d.ts.map +1 -0
- package/dist/core/transform/shared/code-editor.js +206 -0
- package/dist/core/transform/shared/code-editor.js.map +1 -0
- package/dist/core/transform/shared/index.d.ts +7 -0
- package/dist/core/transform/shared/index.d.ts.map +1 -0
- package/dist/core/transform/shared/index.js +7 -0
- package/dist/core/transform/shared/index.js.map +1 -0
- package/dist/core/transform/shared/symbol-finder.d.ts +154 -0
- package/dist/core/transform/shared/symbol-finder.d.ts.map +1 -0
- package/dist/core/transform/shared/symbol-finder.js +433 -0
- package/dist/core/transform/shared/symbol-finder.js.map +1 -0
- package/dist/core/transform/structure/extract/extract-function.d.ts.map +1 -0
- package/dist/core/{refactor → transform/structure/extract}/extract-function.js +1 -1
- package/dist/core/transform/structure/extract/extract-function.js.map +1 -0
- package/dist/core/transform/structure/extract/index.d.ts +7 -0
- package/dist/core/transform/structure/extract/index.d.ts.map +1 -0
- package/dist/core/transform/structure/extract/index.js +9 -0
- package/dist/core/transform/structure/extract/index.js.map +1 -0
- package/dist/core/transform/structure/extract/swift-extractor.d.ts +98 -0
- package/dist/core/transform/structure/extract/swift-extractor.d.ts.map +1 -0
- package/dist/core/transform/structure/extract/swift-extractor.js +283 -0
- package/dist/core/transform/structure/extract/swift-extractor.js.map +1 -0
- package/dist/core/transform/structure/index.d.ts +8 -0
- package/dist/core/transform/structure/index.d.ts.map +1 -0
- package/dist/core/transform/structure/index.js +8 -0
- package/dist/core/transform/structure/index.js.map +1 -0
- package/dist/core/transform/structure/inline/index.d.ts +6 -0
- package/dist/core/transform/structure/inline/index.d.ts.map +1 -0
- package/dist/core/transform/structure/inline/index.js +6 -0
- package/dist/core/transform/structure/inline/index.js.map +1 -0
- package/dist/core/transform/structure/inline/inline-function.d.ts.map +1 -0
- package/dist/core/{refactor → transform/structure/inline}/inline-function.js +37 -26
- package/dist/core/transform/structure/inline/inline-function.js.map +1 -0
- package/dist/core/transform/structure/patterns/design-patterns.d.ts.map +1 -0
- package/dist/core/transform/structure/patterns/design-patterns.js.map +1 -0
- package/dist/core/transform/structure/patterns/index.d.ts +6 -0
- package/dist/core/transform/structure/patterns/index.d.ts.map +1 -0
- package/dist/core/transform/structure/patterns/index.js +6 -0
- package/dist/core/transform/structure/patterns/index.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.d.ts +94 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.js +544 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/index.d.ts +10 -0
- package/dist/core/transform/symbol/change-signature/index.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/index.js +12 -0
- package/dist/core/transform/symbol/change-signature/index.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.d.ts +76 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.js +387 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/types.d.ts +244 -0
- package/dist/core/transform/symbol/change-signature/types.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/types.js +73 -0
- package/dist/core/transform/symbol/change-signature/types.js.map +1 -0
- package/dist/core/transform/symbol/index.d.ts +7 -0
- package/dist/core/transform/symbol/index.d.ts.map +1 -0
- package/dist/core/transform/symbol/index.js +7 -0
- package/dist/core/transform/symbol/index.js.map +1 -0
- package/dist/core/transform/symbol/rename/index.d.ts +9 -0
- package/dist/core/transform/symbol/rename/index.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/index.js +5 -3
- package/dist/core/transform/symbol/rename/index.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/reference-updater.d.ts +2 -2
- package/dist/core/transform/symbol/rename/reference-updater.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/reference-updater.js +16 -8
- package/dist/core/transform/symbol/rename/reference-updater.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/rename-engine.d.ts +2 -2
- package/dist/core/transform/symbol/rename/rename-engine.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/rename-engine.js +3 -3
- package/dist/core/transform/symbol/rename/rename-engine.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/scope-analyzer.d.ts +3 -3
- package/dist/core/transform/symbol/rename/scope-analyzer.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/scope-analyzer.js +2 -2
- package/dist/core/transform/symbol/rename/scope-analyzer.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/types.d.ts +2 -2
- package/dist/core/transform/symbol/rename/types.d.ts.map +1 -0
- package/dist/core/transform/symbol/rename/types.js.map +1 -0
- package/dist/core/transform/types.d.ts +185 -0
- package/dist/core/transform/types.d.ts.map +1 -0
- package/dist/core/transform/types.js +150 -0
- package/dist/core/transform/types.js.map +1 -0
- package/dist/infrastructure/cache/cache-manager.d.ts +1 -1
- package/dist/infrastructure/cache/cache-manager.d.ts.map +1 -1
- package/dist/infrastructure/cache/cache-manager.js +1 -1
- package/dist/infrastructure/cache/cache-manager.js.map +1 -1
- package/dist/infrastructure/cache/memory-cache.js +1 -1
- package/dist/infrastructure/cache/memory-cache.js.map +1 -1
- package/dist/infrastructure/cache/strategies.d.ts +1 -1
- package/dist/infrastructure/cache/strategies.d.ts.map +1 -1
- package/dist/infrastructure/cache/strategies.js +1 -1
- package/dist/infrastructure/cache/strategies.js.map +1 -1
- package/dist/infrastructure/formatters/diff-generator.d.ts +11 -0
- package/dist/infrastructure/formatters/diff-generator.d.ts.map +1 -0
- package/dist/infrastructure/formatters/diff-generator.js +217 -0
- package/dist/infrastructure/formatters/diff-generator.js.map +1 -0
- package/dist/infrastructure/formatters/index.d.ts +11 -0
- package/dist/infrastructure/formatters/index.d.ts.map +1 -0
- package/dist/infrastructure/formatters/index.js +13 -0
- package/dist/infrastructure/formatters/index.js.map +1 -0
- package/dist/infrastructure/formatters/preview-converter.d.ts +85 -0
- package/dist/infrastructure/formatters/preview-converter.d.ts.map +1 -0
- package/dist/infrastructure/formatters/preview-converter.js +209 -0
- package/dist/infrastructure/formatters/preview-converter.js.map +1 -0
- package/dist/infrastructure/formatters/preview-formatter.d.ts +61 -0
- package/dist/infrastructure/formatters/preview-formatter.d.ts.map +1 -0
- package/dist/infrastructure/formatters/preview-formatter.js +208 -0
- package/dist/infrastructure/formatters/preview-formatter.js.map +1 -0
- package/dist/infrastructure/formatters/query-formatter.d.ts +63 -0
- package/dist/infrastructure/formatters/query-formatter.d.ts.map +1 -0
- package/dist/infrastructure/formatters/query-formatter.js +218 -0
- package/dist/infrastructure/formatters/query-formatter.js.map +1 -0
- package/dist/infrastructure/formatters/query-types.d.ts +165 -0
- package/dist/infrastructure/formatters/query-types.d.ts.map +1 -0
- package/dist/infrastructure/formatters/query-types.js +30 -0
- package/dist/infrastructure/formatters/query-types.js.map +1 -0
- package/dist/infrastructure/formatters/types.d.ts +153 -0
- package/dist/infrastructure/formatters/types.d.ts.map +1 -0
- package/dist/infrastructure/formatters/types.js +27 -0
- package/dist/infrastructure/formatters/types.js.map +1 -0
- package/dist/infrastructure/parser/analysis-types.d.ts +198 -0
- package/dist/infrastructure/parser/analysis-types.d.ts.map +1 -0
- package/dist/infrastructure/parser/analysis-types.js +6 -0
- package/dist/infrastructure/parser/analysis-types.js.map +1 -0
- package/dist/infrastructure/parser/base.d.ts +37 -1
- package/dist/infrastructure/parser/base.d.ts.map +1 -1
- package/dist/infrastructure/parser/base.js +73 -1
- package/dist/infrastructure/parser/base.js.map +1 -1
- package/dist/infrastructure/parser/factory.d.ts +3 -3
- package/dist/infrastructure/parser/factory.d.ts.map +1 -1
- package/dist/infrastructure/parser/factory.js +1 -1
- package/dist/infrastructure/parser/factory.js.map +1 -1
- package/dist/infrastructure/parser/index.d.ts +1 -0
- package/dist/infrastructure/parser/index.d.ts.map +1 -1
- package/dist/infrastructure/parser/index.js.map +1 -1
- package/dist/infrastructure/parser/interface.d.ts +64 -1
- package/dist/infrastructure/parser/interface.d.ts.map +1 -1
- package/dist/infrastructure/parser/interface.js +11 -1
- package/dist/infrastructure/parser/interface.js.map +1 -1
- package/dist/infrastructure/parser/registry.d.ts +1 -1
- package/dist/infrastructure/parser/registry.d.ts.map +1 -1
- package/dist/infrastructure/parser/registry.js +1 -1
- package/dist/infrastructure/parser/registry.js.map +1 -1
- package/dist/infrastructure/parser/types.d.ts.map +1 -1
- package/dist/infrastructure/storage/file-system.d.ts +2 -1
- package/dist/infrastructure/storage/file-system.d.ts.map +1 -1
- package/dist/infrastructure/storage/file-system.interface.d.ts +69 -0
- package/dist/infrastructure/storage/file-system.interface.d.ts.map +1 -0
- package/dist/infrastructure/storage/file-system.interface.js +6 -0
- package/dist/infrastructure/storage/file-system.interface.js.map +1 -0
- package/dist/infrastructure/storage/file-system.js.map +1 -1
- package/dist/infrastructure/storage/index.d.ts +2 -2
- package/dist/infrastructure/storage/index.d.ts.map +1 -1
- package/dist/infrastructure/storage/index.js +1 -6
- package/dist/infrastructure/storage/index.js.map +1 -1
- package/dist/infrastructure/storage/mem-file-system.d.ts +44 -0
- package/dist/infrastructure/storage/mem-file-system.d.ts.map +1 -0
- package/dist/infrastructure/storage/mem-file-system.js +105 -0
- package/dist/infrastructure/storage/mem-file-system.js.map +1 -0
- package/dist/infrastructure/storage/path-utils.d.ts +1 -1
- package/dist/infrastructure/storage/path-utils.d.ts.map +1 -1
- package/dist/interfaces/cli/cli.d.ts +13 -70
- package/dist/interfaces/cli/cli.d.ts.map +1 -1
- package/dist/interfaces/cli/cli.js +65 -1186
- package/dist/interfaces/cli/cli.js.map +1 -1
- package/dist/interfaces/cli/commands/analyze.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/analyze.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/analyze.command.js +460 -0
- package/dist/interfaces/cli/commands/analyze.command.js.map +1 -0
- package/dist/interfaces/cli/commands/change-signature.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/change-signature.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/change-signature.command.js +299 -0
- package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -0
- package/dist/interfaces/cli/commands/deps.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/deps.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/deps.command.js +143 -0
- package/dist/interfaces/cli/commands/deps.command.js.map +1 -0
- package/dist/interfaces/cli/commands/extract.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/extract.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/extract.command.js +314 -0
- package/dist/interfaces/cli/commands/extract.command.js.map +1 -0
- package/dist/interfaces/cli/commands/index.d.ts +16 -0
- package/dist/interfaces/cli/commands/index.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/index.js +15 -0
- package/dist/interfaces/cli/commands/index.js.map +1 -0
- package/dist/interfaces/cli/commands/inline.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/inline.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/inline.command.js +208 -0
- package/dist/interfaces/cli/commands/inline.command.js.map +1 -0
- package/dist/interfaces/cli/commands/move-member.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/move-member.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/move-member.command.js +194 -0
- package/dist/interfaces/cli/commands/move-member.command.js.map +1 -0
- package/dist/interfaces/cli/commands/move.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/move.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/move.command.js +220 -0
- package/dist/interfaces/cli/commands/move.command.js.map +1 -0
- package/dist/interfaces/cli/commands/refactor.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/refactor.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/refactor.command.js +414 -0
- package/dist/interfaces/cli/commands/refactor.command.js.map +1 -0
- package/dist/interfaces/cli/commands/rename.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/rename.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/rename.command.js +272 -0
- package/dist/interfaces/cli/commands/rename.command.js.map +1 -0
- package/dist/interfaces/cli/commands/search.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/search.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/search.command.js +409 -0
- package/dist/interfaces/cli/commands/search.command.js.map +1 -0
- package/dist/interfaces/cli/commands/shift.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/shift.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/shift.command.js +143 -0
- package/dist/interfaces/cli/commands/shift.command.js.map +1 -0
- package/dist/interfaces/cli/commands/snapshot.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/snapshot.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/snapshot.command.js +68 -0
- package/dist/interfaces/cli/commands/snapshot.command.js.map +1 -0
- package/dist/interfaces/cli/commands/types.d.ts +18 -0
- package/dist/interfaces/cli/commands/types.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/types.js +5 -0
- package/dist/interfaces/cli/commands/types.js.map +1 -0
- package/dist/interfaces/cli/index.d.ts +1 -1
- package/dist/interfaces/cli/index.d.ts.map +1 -1
- package/dist/interfaces/cli/index.js +1 -1
- package/dist/interfaces/cli/index.js.map +1 -1
- package/dist/interfaces/cli/preview-output-handler.d.ts +53 -0
- package/dist/interfaces/cli/preview-output-handler.d.ts.map +1 -0
- package/dist/interfaces/cli/preview-output-handler.js +73 -0
- package/dist/interfaces/cli/preview-output-handler.js.map +1 -0
- package/dist/interfaces/cli/unified-output-handler.d.ts +77 -0
- package/dist/interfaces/cli/unified-output-handler.d.ts.map +1 -0
- package/dist/interfaces/cli/unified-output-handler.js +140 -0
- package/dist/interfaces/cli/unified-output-handler.js.map +1 -0
- package/dist/plugins/javascript/index.d.ts +2 -2
- package/dist/plugins/javascript/index.d.ts.map +1 -1
- package/dist/plugins/javascript/index.js +1 -1
- package/dist/plugins/javascript/index.js.map +1 -1
- package/dist/plugins/javascript/parser.d.ts +41 -0
- package/dist/plugins/javascript/parser.d.ts.map +1 -1
- package/dist/plugins/javascript/parser.js +284 -0
- package/dist/plugins/javascript/parser.js.map +1 -1
- package/dist/plugins/javascript/types.d.ts.map +1 -1
- package/dist/plugins/javascript/types.js.map +1 -1
- package/dist/plugins/python/analyzers/complexity-analyzer.d.ts +50 -0
- package/dist/plugins/python/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/complexity-analyzer.js +172 -0
- package/dist/plugins/python/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/plugins/python/analyzers/duplication-detector.d.ts +39 -0
- package/dist/plugins/python/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/duplication-detector.js +146 -0
- package/dist/plugins/python/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/python/analyzers/error-handling-checker.d.ts +28 -0
- package/dist/plugins/python/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/error-handling-checker.js +143 -0
- package/dist/plugins/python/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/naming-checker.d.ts +56 -0
- package/dist/plugins/python/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/naming-checker.js +220 -0
- package/dist/plugins/python/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/pattern-detector.d.ts +44 -0
- package/dist/plugins/python/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/pattern-detector.js +222 -0
- package/dist/plugins/python/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/python/analyzers/security-checker.d.ts +56 -0
- package/dist/plugins/python/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/security-checker.js +279 -0
- package/dist/plugins/python/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/type-safety-checker.d.ts +44 -0
- package/dist/plugins/python/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/type-safety-checker.js +177 -0
- package/dist/plugins/python/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts +37 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.js +141 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/python/dependency-analyzer.d.ts +86 -0
- package/dist/plugins/python/dependency-analyzer.d.ts.map +1 -0
- package/dist/plugins/python/dependency-analyzer.js +252 -0
- package/dist/plugins/python/dependency-analyzer.js.map +1 -0
- package/dist/plugins/python/index.d.ts +17 -0
- package/dist/plugins/python/index.d.ts.map +1 -0
- package/dist/plugins/python/index.js +23 -0
- package/dist/plugins/python/index.js.map +1 -0
- package/dist/plugins/python/parser.d.ts +150 -0
- package/dist/plugins/python/parser.d.ts.map +1 -0
- package/dist/plugins/python/parser.js +476 -0
- package/dist/plugins/python/parser.js.map +1 -0
- package/dist/plugins/python/symbol-extractor.d.ts +108 -0
- package/dist/plugins/python/symbol-extractor.d.ts.map +1 -0
- package/dist/plugins/python/symbol-extractor.js +389 -0
- package/dist/plugins/python/symbol-extractor.js.map +1 -0
- package/dist/plugins/python/tree-sitter-bridge.d.ts +57 -0
- package/dist/plugins/python/tree-sitter-bridge.d.ts.map +1 -0
- package/dist/plugins/python/tree-sitter-bridge.js +267 -0
- package/dist/plugins/python/tree-sitter-bridge.js.map +1 -0
- package/dist/plugins/python/types.d.ts +179 -0
- package/dist/plugins/python/types.d.ts.map +1 -0
- package/dist/plugins/python/types.js +252 -0
- package/dist/plugins/python/types.js.map +1 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts +41 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.js +206 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/plugins/swift/analyzers/duplication-detector.d.ts +89 -0
- package/dist/plugins/swift/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/duplication-detector.js +271 -0
- package/dist/plugins/swift/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.d.ts +34 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.js +135 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/naming-checker.d.ts +47 -0
- package/dist/plugins/swift/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/naming-checker.js +161 -0
- package/dist/plugins/swift/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/pattern-detector.d.ts +78 -0
- package/dist/plugins/swift/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/pattern-detector.js +247 -0
- package/dist/plugins/swift/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/swift/analyzers/security-checker.d.ts +38 -0
- package/dist/plugins/swift/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/security-checker.js +135 -0
- package/dist/plugins/swift/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.d.ts +41 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.js +121 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts +38 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.js +211 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/swift/dependency-analyzer.d.ts +33 -0
- package/dist/plugins/swift/dependency-analyzer.d.ts.map +1 -0
- package/dist/plugins/swift/dependency-analyzer.js +95 -0
- package/dist/plugins/swift/dependency-analyzer.js.map +1 -0
- package/dist/plugins/swift/index.d.ts +14 -0
- package/dist/plugins/swift/index.d.ts.map +1 -0
- package/dist/plugins/swift/index.js +19 -0
- package/dist/plugins/swift/index.js.map +1 -0
- package/dist/plugins/swift/parser.d.ts +160 -0
- package/dist/plugins/swift/parser.d.ts.map +1 -0
- package/dist/plugins/swift/parser.js +670 -0
- package/dist/plugins/swift/parser.js.map +1 -0
- package/dist/plugins/swift/swift-bridge/swift-parser +0 -0
- package/dist/plugins/swift/symbol-extractor.d.ts +46 -0
- package/dist/plugins/swift/symbol-extractor.d.ts.map +1 -0
- package/dist/plugins/swift/symbol-extractor.js +187 -0
- package/dist/plugins/swift/symbol-extractor.js.map +1 -0
- package/dist/plugins/swift/types.d.ts +137 -0
- package/dist/plugins/swift/types.d.ts.map +1 -0
- package/dist/plugins/swift/types.js +212 -0
- package/dist/plugins/swift/types.js.map +1 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts +39 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.js +196 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/{core/analysis → plugins/typescript/analyzers}/duplication-detector.d.ts +34 -3
- package/dist/plugins/typescript/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/duplication-detector.js +695 -0
- package/dist/plugins/typescript/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts +26 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.js +84 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/naming-checker.d.ts +30 -0
- package/dist/plugins/typescript/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/naming-checker.js +116 -0
- package/dist/plugins/typescript/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.d.ts +80 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.js +267 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/typescript/analyzers/security-checker.d.ts +34 -0
- package/dist/plugins/typescript/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/security-checker.js +126 -0
- package/dist/plugins/typescript/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts +32 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.js +86 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts +47 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.js +152 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/typescript/parser.d.ts +41 -0
- package/dist/plugins/typescript/parser.d.ts.map +1 -1
- package/dist/plugins/typescript/parser.js +348 -3
- package/dist/plugins/typescript/parser.js.map +1 -1
- package/dist/plugins/typescript/symbol-extractor.d.ts.map +1 -1
- package/dist/plugins/typescript/symbol-extractor.js +12 -0
- package/dist/plugins/typescript/symbol-extractor.js.map +1 -1
- package/dist/plugins/typescript/types.d.ts.map +1 -1
- package/dist/plugins/typescript/types.js +10 -0
- package/dist/plugins/typescript/types.js.map +1 -1
- package/dist/shared/errors/config-error.d.ts +1 -1
- package/dist/shared/errors/config-error.d.ts.map +1 -1
- package/dist/shared/errors/config-error.js +1 -1
- package/dist/shared/errors/config-error.js.map +1 -1
- package/dist/shared/errors/file-error.d.ts +1 -1
- package/dist/shared/errors/file-error.d.ts.map +1 -1
- package/dist/shared/errors/file-error.js +1 -1
- package/dist/shared/errors/file-error.js.map +1 -1
- package/dist/shared/errors/index.d.ts +1 -1
- package/dist/shared/errors/index.d.ts.map +1 -1
- package/dist/shared/errors/index.js +4 -4
- package/dist/shared/errors/index.js.map +1 -1
- package/dist/shared/errors/parser-error.d.ts +1 -1
- package/dist/shared/errors/parser-error.d.ts.map +1 -1
- package/dist/shared/errors/parser-error.js +1 -1
- package/dist/shared/errors/parser-error.js.map +1 -1
- package/dist/shared/errors/validation-error.d.ts +1 -1
- package/dist/shared/errors/validation-error.d.ts.map +1 -1
- package/dist/shared/errors/validation-error.js +1 -1
- package/dist/shared/errors/validation-error.js.map +1 -1
- package/dist/shared/types/ast.d.ts +1 -1
- package/dist/shared/types/ast.d.ts.map +1 -1
- package/dist/shared/types/ast.js +1 -1
- package/dist/shared/types/ast.js.map +1 -1
- package/dist/shared/types/symbol.d.ts +8 -2
- package/dist/shared/types/symbol.d.ts.map +1 -1
- package/dist/shared/types/symbol.js +8 -2
- package/dist/shared/types/symbol.js.map +1 -1
- package/dist/shared/utils/index.d.ts +5 -5
- package/dist/shared/utils/index.d.ts.map +1 -1
- package/dist/shared/utils/index.js +5 -5
- package/dist/shared/utils/index.js.map +1 -1
- package/package.json +21 -9
- package/bin/mcp-server.js +0 -20
- package/dist/core/analysis/complexity-analyzer.d.ts +0 -81
- package/dist/core/analysis/complexity-analyzer.d.ts.map +0 -1
- package/dist/core/analysis/complexity-analyzer.js +0 -255
- package/dist/core/analysis/complexity-analyzer.js.map +0 -1
- package/dist/core/analysis/dead-code-detector.d.ts +0 -152
- package/dist/core/analysis/dead-code-detector.d.ts.map +0 -1
- package/dist/core/analysis/dead-code-detector.js +0 -351
- package/dist/core/analysis/dead-code-detector.js.map +0 -1
- package/dist/core/analysis/duplication-detector.d.ts.map +0 -1
- package/dist/core/analysis/duplication-detector.js +0 -433
- package/dist/core/analysis/duplication-detector.js.map +0 -1
- package/dist/core/analysis/index.d.ts +0 -9
- package/dist/core/analysis/index.d.ts.map +0 -1
- package/dist/core/analysis/index.js +0 -13
- package/dist/core/analysis/index.js.map +0 -1
- package/dist/core/analysis/quality-metrics.d.ts +0 -158
- package/dist/core/analysis/quality-metrics.d.ts.map +0 -1
- package/dist/core/analysis/quality-metrics.js +0 -442
- package/dist/core/analysis/quality-metrics.js.map +0 -1
- package/dist/core/move/import-resolver.d.ts.map +0 -1
- package/dist/core/move/import-resolver.js.map +0 -1
- package/dist/core/move/index.d.ts.map +0 -1
- package/dist/core/move/index.js.map +0 -1
- package/dist/core/move/move-service.d.ts.map +0 -1
- package/dist/core/move/move-service.js.map +0 -1
- package/dist/core/move/types.d.ts.map +0 -1
- package/dist/core/move/types.js.map +0 -1
- package/dist/core/refactor/design-patterns.d.ts.map +0 -1
- package/dist/core/refactor/design-patterns.js.map +0 -1
- package/dist/core/refactor/extract-function.d.ts.map +0 -1
- package/dist/core/refactor/extract-function.js.map +0 -1
- package/dist/core/refactor/index.d.ts +0 -8
- package/dist/core/refactor/index.d.ts.map +0 -1
- package/dist/core/refactor/index.js +0 -11
- package/dist/core/refactor/index.js.map +0 -1
- package/dist/core/refactor/inline-function.d.ts.map +0 -1
- package/dist/core/refactor/inline-function.js.map +0 -1
- package/dist/core/rename/index.d.ts +0 -9
- package/dist/core/rename/index.d.ts.map +0 -1
- package/dist/core/rename/index.js.map +0 -1
- package/dist/core/rename/reference-updater.d.ts.map +0 -1
- package/dist/core/rename/reference-updater.js.map +0 -1
- package/dist/core/rename/rename-engine.d.ts.map +0 -1
- package/dist/core/rename/rename-engine.js.map +0 -1
- package/dist/core/rename/scope-analyzer.d.ts.map +0 -1
- package/dist/core/rename/scope-analyzer.js.map +0 -1
- package/dist/core/rename/types.d.ts.map +0 -1
- package/dist/core/rename/types.js.map +0 -1
- package/dist/interfaces/mcp/index.d.ts +0 -7
- package/dist/interfaces/mcp/index.d.ts.map +0 -1
- package/dist/interfaces/mcp/index.js +0 -6
- package/dist/interfaces/mcp/index.js.map +0 -1
- package/dist/interfaces/mcp/mcp-server.d.ts +0 -34
- package/dist/interfaces/mcp/mcp-server.d.ts.map +0 -1
- package/dist/interfaces/mcp/mcp-server.js +0 -162
- package/dist/interfaces/mcp/mcp-server.js.map +0 -1
- package/dist/interfaces/mcp/mcp.d.ts +0 -52
- package/dist/interfaces/mcp/mcp.d.ts.map +0 -1
- package/dist/interfaces/mcp/mcp.js +0 -853
- package/dist/interfaces/mcp/mcp.js.map +0 -1
- /package/dist/core/{move → transform/location/move-file}/types.js +0 -0
- /package/dist/core/{refactor → transform/structure/extract}/extract-function.d.ts +0 -0
- /package/dist/core/{refactor → transform/structure/inline}/inline-function.d.ts +0 -0
- /package/dist/core/{refactor → transform/structure/patterns}/design-patterns.d.ts +0 -0
- /package/dist/core/{refactor → transform/structure/patterns}/design-patterns.js +0 -0
- /package/dist/core/{rename → transform/symbol/rename}/types.js +0 -0
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swift Parser 主要實作
|
|
3
|
+
* 實作 ParserPlugin 介面
|
|
4
|
+
*/
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
import { promisify } from 'util';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import { createValidationSuccess, createValidationFailure, createCodeEdit, createDefinition, createUsage } from '../../infrastructure/parser/index.js';
|
|
10
|
+
import { createAST, createASTMetadata, ReferenceType, SymbolType } from '../../shared/types/index.js';
|
|
11
|
+
import { SwiftNodeKind, createSwiftASTNode, createParseError, getNodeName, isValidIdentifier } from './types.js';
|
|
12
|
+
import { createSymbolExtractor } from '../swift/symbol-extractor.js';
|
|
13
|
+
import { createDependencyAnalyzer } from '../swift/dependency-analyzer.js';
|
|
14
|
+
const execAsync = promisify(exec);
|
|
15
|
+
/**
|
|
16
|
+
* Swift Parser 實作
|
|
17
|
+
*/
|
|
18
|
+
export class SwiftParser {
|
|
19
|
+
name = 'swift';
|
|
20
|
+
version = '1.0.0';
|
|
21
|
+
supportedExtensions = ['.swift'];
|
|
22
|
+
supportedLanguages = ['swift'];
|
|
23
|
+
symbolExtractor;
|
|
24
|
+
dependencyAnalyzer;
|
|
25
|
+
cliPath;
|
|
26
|
+
constructor(cliPath = 'swift-parser') {
|
|
27
|
+
this.symbolExtractor = createSymbolExtractor();
|
|
28
|
+
this.dependencyAnalyzer = createDependencyAnalyzer();
|
|
29
|
+
this.cliPath = cliPath;
|
|
30
|
+
}
|
|
31
|
+
// ===== 10 個基本方法 =====
|
|
32
|
+
/**
|
|
33
|
+
* 解析 Swift 程式碼
|
|
34
|
+
*/
|
|
35
|
+
async parse(code, filePath) {
|
|
36
|
+
this.validateInput(code, filePath);
|
|
37
|
+
try {
|
|
38
|
+
// 呼叫 Swift CLI Bridge
|
|
39
|
+
const cliPath = this.resolveCliPath();
|
|
40
|
+
const escapedCode = code.replace(/'/g, '\'\\\'\''); // 逸出單引號
|
|
41
|
+
const { stdout } = await execAsync(`echo '${escapedCode}' | ${cliPath}`, {
|
|
42
|
+
maxBuffer: 10 * 1024 * 1024 // 10MB buffer
|
|
43
|
+
});
|
|
44
|
+
// 解析 JSON 輸出
|
|
45
|
+
const cliOutput = JSON.parse(stdout);
|
|
46
|
+
// 檢查解析錯誤
|
|
47
|
+
if (cliOutput.parseErrors) {
|
|
48
|
+
throw createParseError(`Swift 語法錯誤: ${cliOutput.parseErrors.map((e) => e.message).join(', ')}`);
|
|
49
|
+
}
|
|
50
|
+
// 轉換為標準 AST
|
|
51
|
+
const rootNode = this.convertCLINodeToASTNode(cliOutput.root);
|
|
52
|
+
const metadata = createASTMetadata('swift', cliOutput.metadata?.parserVersion || this.version, {}, Date.now(), 0);
|
|
53
|
+
const baseAST = createAST(filePath, rootNode, metadata);
|
|
54
|
+
const ast = {
|
|
55
|
+
...baseAST,
|
|
56
|
+
root: rootNode,
|
|
57
|
+
swiftVersion: cliOutput.metadata?.parserVersion,
|
|
58
|
+
diagnostics: []
|
|
59
|
+
};
|
|
60
|
+
return ast;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw createParseError(`解析失敗: ${error instanceof Error ? error.message : String(error)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 解析 Swift CLI Bridge 路徑
|
|
68
|
+
*/
|
|
69
|
+
resolveCliPath() {
|
|
70
|
+
// 優先使用建構參數指定的路徑
|
|
71
|
+
if (this.cliPath && this.cliPath !== 'swift-parser') {
|
|
72
|
+
if (fs.existsSync(this.cliPath)) {
|
|
73
|
+
return this.cliPath;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// 從 dist/ 目錄解析(build 時已複製)
|
|
77
|
+
const distPath = path.join(__dirname, 'swift-bridge', 'swift-parser');
|
|
78
|
+
if (fs.existsSync(distPath)) {
|
|
79
|
+
return distPath;
|
|
80
|
+
}
|
|
81
|
+
// 開發環境:從 src/ 目錄解析
|
|
82
|
+
const projectRoot = process.cwd();
|
|
83
|
+
const srcPath = path.join(projectRoot, 'src/plugins/swift/swift-bridge/swift-parser');
|
|
84
|
+
if (fs.existsSync(srcPath)) {
|
|
85
|
+
return srcPath;
|
|
86
|
+
}
|
|
87
|
+
// 錯誤:CLI Bridge 未找到
|
|
88
|
+
throw new Error('Swift CLI Bridge not found. Please run: cd src/plugins/swift/swift-bridge && bash build.sh');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 轉換 CLI Bridge 節點為 AST 節點
|
|
92
|
+
*/
|
|
93
|
+
convertCLINodeToASTNode(cliNode) {
|
|
94
|
+
const swiftKind = this.nodeTypeToSwiftKind(cliNode.type);
|
|
95
|
+
const node = {
|
|
96
|
+
type: cliNode.type,
|
|
97
|
+
range: cliNode.range,
|
|
98
|
+
swiftKind,
|
|
99
|
+
properties: cliNode.properties || {},
|
|
100
|
+
children: (cliNode.children || []).map((child) => this.convertCLINodeToASTNode(child)),
|
|
101
|
+
attributes: this.extractAttributes(cliNode),
|
|
102
|
+
modifiers: this.extractModifiers(cliNode),
|
|
103
|
+
source: cliNode.source || undefined
|
|
104
|
+
};
|
|
105
|
+
return node;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 節點類型轉換為 SwiftNodeKind
|
|
109
|
+
*/
|
|
110
|
+
nodeTypeToSwiftKind(nodeType) {
|
|
111
|
+
// 對應 Swift CLI Bridge 的節點類型
|
|
112
|
+
const mapping = {
|
|
113
|
+
'SourceFile': SwiftNodeKind.SourceFile,
|
|
114
|
+
'ClassDecl': SwiftNodeKind.Class,
|
|
115
|
+
'StructDecl': SwiftNodeKind.Struct,
|
|
116
|
+
'ProtocolDecl': SwiftNodeKind.Protocol,
|
|
117
|
+
'EnumDecl': SwiftNodeKind.Enum,
|
|
118
|
+
'FunctionDecl': SwiftNodeKind.Function,
|
|
119
|
+
'FuncDecl': SwiftNodeKind.Function,
|
|
120
|
+
'VariableDecl': SwiftNodeKind.Variable,
|
|
121
|
+
'ImportDecl': SwiftNodeKind.Import
|
|
122
|
+
};
|
|
123
|
+
return mapping[nodeType] || SwiftNodeKind.Unknown;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 從節點提取屬性(@Published, @State 等)
|
|
127
|
+
*/
|
|
128
|
+
extractAttributes(node) {
|
|
129
|
+
// 從 properties 或子節點中提取屬性
|
|
130
|
+
if (node.properties?.attributes) {
|
|
131
|
+
return node.properties.attributes.split(',').map((a) => a.trim());
|
|
132
|
+
}
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 從節點提取修飾符(public, private 等)
|
|
137
|
+
*/
|
|
138
|
+
extractModifiers(node) {
|
|
139
|
+
// 從 properties 或子節點中提取修飾符
|
|
140
|
+
if (node.properties?.modifiers) {
|
|
141
|
+
return node.properties.modifiers.split(' ').filter((m) => m.length > 0);
|
|
142
|
+
}
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 提取符號
|
|
147
|
+
*/
|
|
148
|
+
async extractSymbols(ast) {
|
|
149
|
+
const typedAst = ast;
|
|
150
|
+
return await this.symbolExtractor.extractSymbols(typedAst);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 查找符號引用
|
|
154
|
+
* 在當前 AST 中查找所有對指定符號的引用
|
|
155
|
+
*/
|
|
156
|
+
async findReferences(ast, symbol) {
|
|
157
|
+
const typedAst = ast;
|
|
158
|
+
const references = [];
|
|
159
|
+
// 遍歷 AST 尋找匹配的識別符
|
|
160
|
+
this.findReferencesInNode(typedAst.root, symbol.name, typedAst.sourceFile, references, symbol);
|
|
161
|
+
return references;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 提取依賴關係
|
|
165
|
+
*/
|
|
166
|
+
async extractDependencies(ast) {
|
|
167
|
+
const typedAst = ast;
|
|
168
|
+
return await this.dependencyAnalyzer.extractDependencies(typedAst);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 重新命名符號
|
|
172
|
+
*/
|
|
173
|
+
async rename(ast, position, newName) {
|
|
174
|
+
this.validateRenameInput(newName);
|
|
175
|
+
// 查找位置上的符號
|
|
176
|
+
const symbol = await this.findSymbolAtPosition(ast, position);
|
|
177
|
+
if (!symbol) {
|
|
178
|
+
throw new Error('在指定位置找不到符號');
|
|
179
|
+
}
|
|
180
|
+
// 查找所有引用
|
|
181
|
+
const references = await this.findReferences(ast, symbol);
|
|
182
|
+
// 建立編輯操作
|
|
183
|
+
const edits = [];
|
|
184
|
+
for (const reference of references) {
|
|
185
|
+
const edit = createCodeEdit(reference.location.filePath, reference.location.range, newName, 'rename');
|
|
186
|
+
edits.push(edit);
|
|
187
|
+
}
|
|
188
|
+
return edits;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 提取函式重構
|
|
192
|
+
*/
|
|
193
|
+
async extractFunction(_ast, _selection) {
|
|
194
|
+
throw new Error('提取函式重構尚未實作');
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 查找定義
|
|
198
|
+
*/
|
|
199
|
+
async findDefinition(ast, position) {
|
|
200
|
+
const symbol = await this.findSymbolAtPosition(ast, position);
|
|
201
|
+
if (!symbol) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
return createDefinition(symbol.location, this.symbolTypeToDefinitionKind(symbol.type));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 查找使用位置
|
|
208
|
+
*/
|
|
209
|
+
async findUsages(ast, symbol) {
|
|
210
|
+
const references = await this.findReferences(ast, symbol);
|
|
211
|
+
return references
|
|
212
|
+
.filter(ref => ref.type === ReferenceType.Usage)
|
|
213
|
+
.map(ref => createUsage(ref.location, 'reference'));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 驗證插件狀態
|
|
217
|
+
*/
|
|
218
|
+
async validate() {
|
|
219
|
+
try {
|
|
220
|
+
// 檢查 Swift CLI Bridge 是否可用
|
|
221
|
+
const { stdout } = await execAsync(`command -v ${this.cliPath}`);
|
|
222
|
+
if (!stdout) {
|
|
223
|
+
return createValidationFailure([{
|
|
224
|
+
code: 'SWIFT_CLI_UNAVAILABLE',
|
|
225
|
+
message: 'Swift CLI Bridge 不可用',
|
|
226
|
+
location: {
|
|
227
|
+
filePath: '',
|
|
228
|
+
range: {
|
|
229
|
+
start: { line: 0, column: 0, offset: 0 },
|
|
230
|
+
end: { line: 0, column: 0, offset: 0 }
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}]);
|
|
234
|
+
}
|
|
235
|
+
return createValidationSuccess();
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
// CLI Bridge 尚未實作,暫時返回成功
|
|
239
|
+
return createValidationSuccess();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 清理資源
|
|
244
|
+
*/
|
|
245
|
+
async dispose() {
|
|
246
|
+
// 清理資源
|
|
247
|
+
this.symbolExtractor = null;
|
|
248
|
+
this.dependencyAnalyzer = null;
|
|
249
|
+
}
|
|
250
|
+
// ===== 9 個分析方法 =====
|
|
251
|
+
/**
|
|
252
|
+
* 檢測未使用的符號
|
|
253
|
+
*/
|
|
254
|
+
async detectUnusedSymbols(ast, allSymbols) {
|
|
255
|
+
const unusedCodes = [];
|
|
256
|
+
for (const symbol of allSymbols) {
|
|
257
|
+
const references = await this.findReferences(ast, symbol);
|
|
258
|
+
// 只有定義但沒有使用的符號
|
|
259
|
+
const usages = references.filter(ref => ref.type === ReferenceType.Usage);
|
|
260
|
+
if (usages.length === 0) {
|
|
261
|
+
unusedCodes.push({
|
|
262
|
+
type: symbol.type === SymbolType.Function ? 'function' :
|
|
263
|
+
symbol.type === SymbolType.Class ? 'class' : 'variable',
|
|
264
|
+
name: symbol.name,
|
|
265
|
+
location: {
|
|
266
|
+
filePath: symbol.location.filePath,
|
|
267
|
+
line: symbol.location.range.start.line,
|
|
268
|
+
column: symbol.location.range.start.column
|
|
269
|
+
},
|
|
270
|
+
confidence: 0.9,
|
|
271
|
+
reason: `符號 "${symbol.name}" 已定義但從未使用`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return unusedCodes;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 分析程式碼複雜度
|
|
279
|
+
*/
|
|
280
|
+
async analyzeComplexity(code, _ast) {
|
|
281
|
+
const lines = code.split('\n');
|
|
282
|
+
const complexity = this.calculateCyclomaticComplexity(code);
|
|
283
|
+
return {
|
|
284
|
+
cyclomaticComplexity: complexity,
|
|
285
|
+
cognitiveComplexity: Math.floor(complexity * 1.2),
|
|
286
|
+
evaluation: complexity > 20 ? 'very-complex' :
|
|
287
|
+
complexity > 10 ? 'complex' :
|
|
288
|
+
complexity > 5 ? 'moderate' : 'simple',
|
|
289
|
+
functionCount: (code.match(/\bfunc\b/g) || []).length,
|
|
290
|
+
averageComplexity: complexity / Math.max(1, (code.match(/\bfunc\b/g) || []).length),
|
|
291
|
+
maxComplexity: complexity,
|
|
292
|
+
maxComplexityFunction: undefined
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 提取程式碼片段(用於重複代碼檢測)
|
|
297
|
+
*/
|
|
298
|
+
async extractCodeFragments(code, filePath) {
|
|
299
|
+
const fragments = [];
|
|
300
|
+
const lines = code.split('\n');
|
|
301
|
+
// 提取方法片段
|
|
302
|
+
for (let i = 0; i < lines.length; i++) {
|
|
303
|
+
const line = lines[i];
|
|
304
|
+
if (/func\s+\w+/.test(line)) {
|
|
305
|
+
let braceCount = (line.match(/{/g) || []).length;
|
|
306
|
+
let endLine = i;
|
|
307
|
+
for (let j = i + 1; j < lines.length && braceCount > 0; j++) {
|
|
308
|
+
braceCount += (lines[j].match(/{/g) || []).length;
|
|
309
|
+
braceCount -= (lines[j].match(/}/g) || []).length;
|
|
310
|
+
endLine = j;
|
|
311
|
+
}
|
|
312
|
+
if (endLine > i && endLine - i + 1 >= 3) {
|
|
313
|
+
const methodCode = lines.slice(i, endLine + 1).join('\n');
|
|
314
|
+
const { createHash } = await import('crypto');
|
|
315
|
+
fragments.push({
|
|
316
|
+
type: 'method',
|
|
317
|
+
code: methodCode,
|
|
318
|
+
tokens: methodCode.split(/\s+/).filter(t => t.length > 0),
|
|
319
|
+
location: { filePath, startLine: i + 1, endLine: endLine + 1 },
|
|
320
|
+
hash: createHash('md5').update(methodCode).digest('hex')
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return fragments;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* 檢測樣板模式
|
|
329
|
+
*/
|
|
330
|
+
async detectPatterns(_code, _ast) {
|
|
331
|
+
// Swift 特定模式檢測(如 guard let、if let 等)
|
|
332
|
+
return [];
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* 檢查型別安全問題
|
|
336
|
+
*/
|
|
337
|
+
async checkTypeSafety(code, ast) {
|
|
338
|
+
const issues = [];
|
|
339
|
+
const lines = code.split('\n');
|
|
340
|
+
for (let i = 0; i < lines.length; i++) {
|
|
341
|
+
const line = lines[i];
|
|
342
|
+
// 檢測 as! 強制轉型
|
|
343
|
+
if (/as!\s+/.test(line)) {
|
|
344
|
+
issues.push({
|
|
345
|
+
type: 'unsafe-cast',
|
|
346
|
+
location: { filePath: ast.sourceFile, line: i + 1, column: 0 },
|
|
347
|
+
message: '使用了 as! 強制轉型,可能導致運行時崩潰',
|
|
348
|
+
severity: 'error'
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
// 檢測強制解包 !
|
|
352
|
+
if (/\w+!/.test(line) && !/if\s+let|guard\s+let/.test(line)) {
|
|
353
|
+
issues.push({
|
|
354
|
+
type: 'unsafe-cast',
|
|
355
|
+
location: { filePath: ast.sourceFile, line: i + 1, column: 0 },
|
|
356
|
+
message: '使用了強制解包 !,建議使用 if let 或 guard let',
|
|
357
|
+
severity: 'warning'
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return issues;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 檢查錯誤處理問題
|
|
365
|
+
*/
|
|
366
|
+
async checkErrorHandling(code, ast) {
|
|
367
|
+
const issues = [];
|
|
368
|
+
const lines = code.split('\n');
|
|
369
|
+
for (let i = 0; i < lines.length; i++) {
|
|
370
|
+
const line = lines[i];
|
|
371
|
+
// 檢測空 catch 區塊
|
|
372
|
+
if (/catch\s*\{?\s*\}/.test(line)) {
|
|
373
|
+
issues.push({
|
|
374
|
+
type: 'empty-catch',
|
|
375
|
+
location: { filePath: ast.sourceFile, line: i + 1, column: 0 },
|
|
376
|
+
message: '空的 catch 區塊,應該處理錯誤',
|
|
377
|
+
severity: 'warning'
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
// 檢測 try? 靜默錯誤
|
|
381
|
+
if (/try\?/.test(line)) {
|
|
382
|
+
issues.push({
|
|
383
|
+
type: 'silent-error',
|
|
384
|
+
location: { filePath: ast.sourceFile, line: i + 1, column: 0 },
|
|
385
|
+
message: '使用 try? 靜默錯誤,建議使用 do-catch 處理',
|
|
386
|
+
severity: 'warning'
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return issues;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* 檢查安全性問題
|
|
394
|
+
*/
|
|
395
|
+
async checkSecurity(code, ast) {
|
|
396
|
+
const issues = [];
|
|
397
|
+
const lines = code.split('\n');
|
|
398
|
+
for (let i = 0; i < lines.length; i++) {
|
|
399
|
+
const line = lines[i];
|
|
400
|
+
// 檢測硬編碼密碼
|
|
401
|
+
if (/(password|apiKey|token|secret)\s*=\s*"[^"]{3,}"/.test(line) &&
|
|
402
|
+
!/ProcessInfo/.test(line)) {
|
|
403
|
+
issues.push({
|
|
404
|
+
type: 'hardcoded-secret',
|
|
405
|
+
location: { filePath: ast.sourceFile, line: i + 1, column: 0 },
|
|
406
|
+
message: '硬編碼的密碼或密鑰,應使用 Keychain 或環境變數',
|
|
407
|
+
severity: 'critical'
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return issues;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* 檢查命名規範問題
|
|
415
|
+
*/
|
|
416
|
+
async checkNamingConventions(symbols, filePath) {
|
|
417
|
+
const issues = [];
|
|
418
|
+
for (const symbol of symbols) {
|
|
419
|
+
// Swift 規範:變數和函式用 camelCase
|
|
420
|
+
if (symbol.type === SymbolType.Variable ||
|
|
421
|
+
symbol.type === SymbolType.Function) {
|
|
422
|
+
if (/^[A-Z]/.test(symbol.name)) {
|
|
423
|
+
issues.push({
|
|
424
|
+
type: 'invalid-naming',
|
|
425
|
+
symbolName: symbol.name,
|
|
426
|
+
symbolType: symbol.type,
|
|
427
|
+
location: {
|
|
428
|
+
filePath,
|
|
429
|
+
line: symbol.location.range.start.line,
|
|
430
|
+
column: symbol.location.range.start.column
|
|
431
|
+
},
|
|
432
|
+
message: `變數/函式 "${symbol.name}" 應使用 camelCase 命名`
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
// Swift 規範:類別和協定用 PascalCase
|
|
437
|
+
if (symbol.type === SymbolType.Class ||
|
|
438
|
+
symbol.type === SymbolType.Interface) {
|
|
439
|
+
if (!/^[A-Z]/.test(symbol.name)) {
|
|
440
|
+
issues.push({
|
|
441
|
+
type: 'invalid-naming',
|
|
442
|
+
symbolName: symbol.name,
|
|
443
|
+
symbolType: symbol.type,
|
|
444
|
+
location: {
|
|
445
|
+
filePath,
|
|
446
|
+
line: symbol.location.range.start.line,
|
|
447
|
+
column: symbol.location.range.start.column
|
|
448
|
+
},
|
|
449
|
+
message: `類別/協定 "${symbol.name}" 應使用 PascalCase 命名`
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
// 檢測底線開頭變數(Swift 不建議)
|
|
454
|
+
if (symbol.name.startsWith('_')) {
|
|
455
|
+
issues.push({
|
|
456
|
+
type: 'invalid-naming',
|
|
457
|
+
symbolName: symbol.name,
|
|
458
|
+
symbolType: symbol.type,
|
|
459
|
+
location: {
|
|
460
|
+
filePath,
|
|
461
|
+
line: symbol.location.range.start.line,
|
|
462
|
+
column: symbol.location.range.start.column
|
|
463
|
+
},
|
|
464
|
+
message: `符號 "${symbol.name}" 以底線開頭,違反 Swift 命名規範`
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return issues;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* 判斷檔案是否為測試檔案
|
|
472
|
+
*/
|
|
473
|
+
isTestFile(filePath) {
|
|
474
|
+
return /Tests\.swift$/.test(filePath) || filePath.includes('/Tests/');
|
|
475
|
+
}
|
|
476
|
+
// ===== 可選方法 =====
|
|
477
|
+
/**
|
|
478
|
+
* 獲取 Swift 特定的排除模式
|
|
479
|
+
*/
|
|
480
|
+
getDefaultExcludePatterns() {
|
|
481
|
+
return [
|
|
482
|
+
'.build/**',
|
|
483
|
+
'DerivedData/**',
|
|
484
|
+
'**/*Tests.swift',
|
|
485
|
+
'**/Tests/**',
|
|
486
|
+
'*.xcodeproj/**',
|
|
487
|
+
'*.xcworkspace/**',
|
|
488
|
+
'Pods/**',
|
|
489
|
+
'Carthage/**'
|
|
490
|
+
];
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* 判斷是否應該忽略特定檔案
|
|
494
|
+
*/
|
|
495
|
+
shouldIgnoreFile(filePath) {
|
|
496
|
+
const patterns = this.getDefaultExcludePatterns();
|
|
497
|
+
return patterns.some(pattern => {
|
|
498
|
+
const regex = new RegExp(pattern.replace(/\*\*/g, '.*').replace(/\*/g, '[^/]*'));
|
|
499
|
+
return regex.test(filePath);
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* 判斷符號是否為抽象宣告
|
|
504
|
+
*/
|
|
505
|
+
isAbstractDeclaration(symbol) {
|
|
506
|
+
const abstractTypes = [
|
|
507
|
+
SymbolType.Class,
|
|
508
|
+
SymbolType.Struct,
|
|
509
|
+
SymbolType.Protocol,
|
|
510
|
+
SymbolType.Interface, // 保留以兼容舊程式碼
|
|
511
|
+
SymbolType.Type, // typealias
|
|
512
|
+
SymbolType.Enum
|
|
513
|
+
];
|
|
514
|
+
return abstractTypes.includes(symbol.type);
|
|
515
|
+
}
|
|
516
|
+
// ===== 私有輔助方法 =====
|
|
517
|
+
validateInput(code, filePath) {
|
|
518
|
+
if (!code.trim()) {
|
|
519
|
+
throw new Error('程式碼內容不能為空');
|
|
520
|
+
}
|
|
521
|
+
if (!filePath.trim()) {
|
|
522
|
+
throw new Error('檔案路徑不能為空');
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
validateRenameInput(newName) {
|
|
526
|
+
if (!newName.trim()) {
|
|
527
|
+
throw new Error('新名稱不能為空');
|
|
528
|
+
}
|
|
529
|
+
if (!isValidIdentifier(newName)) {
|
|
530
|
+
throw new Error('新名稱必須是有效的 Swift 識別符');
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* 模擬解析(實際需要呼叫 CLI Bridge)
|
|
535
|
+
*/
|
|
536
|
+
mockParse(code) {
|
|
537
|
+
return createSwiftASTNode(SwiftNodeKind.SourceFile, code);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* 在節點中遞歸查找引用
|
|
541
|
+
*/
|
|
542
|
+
findReferencesInNode(node, symbolName, filePath, references, symbol) {
|
|
543
|
+
// 檢查當前節點名稱
|
|
544
|
+
const nodeName = getNodeName(node);
|
|
545
|
+
if (nodeName === symbolName) {
|
|
546
|
+
// 使用節點的 range 資訊(如果有)
|
|
547
|
+
const range = node.range || {
|
|
548
|
+
start: { line: 1, column: 1, offset: 0 },
|
|
549
|
+
end: { line: 1, column: 1, offset: 0 }
|
|
550
|
+
};
|
|
551
|
+
references.push({
|
|
552
|
+
symbol,
|
|
553
|
+
location: {
|
|
554
|
+
filePath,
|
|
555
|
+
range
|
|
556
|
+
},
|
|
557
|
+
type: ReferenceType.Usage
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
// 檢查節點的 source code 是否包含符號(用於捕捉類型引用等)
|
|
561
|
+
// 例如:`let user: User` 中的 User 可能不是獨立節點
|
|
562
|
+
if (node.source) {
|
|
563
|
+
const regex = new RegExp(`\\b${this.escapeRegex(symbolName)}\\b`, 'g');
|
|
564
|
+
let match;
|
|
565
|
+
while ((match = regex.exec(node.source)) !== null) {
|
|
566
|
+
// 確保不重複添加(如果已經透過 nodeName 匹配到)
|
|
567
|
+
if (nodeName !== symbolName) {
|
|
568
|
+
const range = node.range || {
|
|
569
|
+
start: { line: 1, column: match.index + 1, offset: 0 },
|
|
570
|
+
end: { line: 1, column: match.index + symbolName.length + 1, offset: 0 }
|
|
571
|
+
};
|
|
572
|
+
references.push({
|
|
573
|
+
symbol,
|
|
574
|
+
location: {
|
|
575
|
+
filePath,
|
|
576
|
+
range
|
|
577
|
+
},
|
|
578
|
+
type: ReferenceType.Usage
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
// 遞歸處理子節點
|
|
584
|
+
if (node.children) {
|
|
585
|
+
for (const child of node.children) {
|
|
586
|
+
this.findReferencesInNode(child, symbolName, filePath, references, symbol);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* 逸出正則表達式特殊字符
|
|
592
|
+
*/
|
|
593
|
+
escapeRegex(text) {
|
|
594
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* 查找指定位置的符號
|
|
598
|
+
*/
|
|
599
|
+
async findSymbolAtPosition(ast, position) {
|
|
600
|
+
const symbols = await this.extractSymbols(ast);
|
|
601
|
+
// 簡化實作:返回第一個符號
|
|
602
|
+
return symbols[0] || null;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* 計算圈複雜度
|
|
606
|
+
*/
|
|
607
|
+
calculateCyclomaticComplexity(code) {
|
|
608
|
+
let complexity = 1;
|
|
609
|
+
// 計算控制流關鍵字(單詞類)
|
|
610
|
+
const wordKeywords = ['if', 'else', 'for', 'while', 'guard', 'switch', 'case'];
|
|
611
|
+
for (const keyword of wordKeywords) {
|
|
612
|
+
const regex = new RegExp(`\\b${keyword}\\b`, 'g');
|
|
613
|
+
const matches = code.match(regex);
|
|
614
|
+
if (matches) {
|
|
615
|
+
complexity += matches.length;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
// 計算邏輯運算子(需要轉義特殊字元)
|
|
619
|
+
const operators = [
|
|
620
|
+
{ pattern: '&&', name: 'logical-and' },
|
|
621
|
+
{ pattern: '||', name: 'logical-or' },
|
|
622
|
+
{ pattern: '?', name: 'ternary' }
|
|
623
|
+
];
|
|
624
|
+
for (const op of operators) {
|
|
625
|
+
const escapedPattern = op.pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
626
|
+
const regex = new RegExp(escapedPattern, 'g');
|
|
627
|
+
const matches = code.match(regex);
|
|
628
|
+
if (matches) {
|
|
629
|
+
complexity += matches.length;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return complexity;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* SymbolType 轉換為 DefinitionKind
|
|
636
|
+
*/
|
|
637
|
+
symbolTypeToDefinitionKind(symbolType) {
|
|
638
|
+
switch (symbolType) {
|
|
639
|
+
case SymbolType.Class:
|
|
640
|
+
return 'class';
|
|
641
|
+
case SymbolType.Struct:
|
|
642
|
+
return 'struct';
|
|
643
|
+
case SymbolType.Protocol:
|
|
644
|
+
return 'protocol';
|
|
645
|
+
case SymbolType.Interface:
|
|
646
|
+
return 'interface';
|
|
647
|
+
case SymbolType.Function:
|
|
648
|
+
return 'function';
|
|
649
|
+
case SymbolType.Variable:
|
|
650
|
+
return 'variable';
|
|
651
|
+
case SymbolType.Property:
|
|
652
|
+
return 'property';
|
|
653
|
+
case SymbolType.Constant:
|
|
654
|
+
return 'constant';
|
|
655
|
+
case SymbolType.Type:
|
|
656
|
+
return 'type';
|
|
657
|
+
case SymbolType.Enum:
|
|
658
|
+
return 'enum';
|
|
659
|
+
default:
|
|
660
|
+
return 'variable';
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* 建立 Swift Parser 實例
|
|
666
|
+
*/
|
|
667
|
+
export function createSwiftParser(cliPath) {
|
|
668
|
+
return new SwiftParser(cliPath);
|
|
669
|
+
}
|
|
670
|
+
//# sourceMappingURL=parser.js.map
|