agent-ide 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +678 -0
- package/bin/agent-ide.js +19 -0
- package/bin/mcp-server.js +20 -0
- package/dist/application/events/event-bus.d.ts +107 -0
- package/dist/application/events/event-bus.d.ts.map +1 -0
- package/dist/application/events/event-bus.js +364 -0
- package/dist/application/events/event-bus.js.map +1 -0
- package/dist/application/events/event-types.d.ts +195 -0
- package/dist/application/events/event-types.d.ts.map +1 -0
- package/dist/application/events/event-types.js +36 -0
- package/dist/application/events/event-types.js.map +1 -0
- package/dist/application/events/index.d.ts +6 -0
- package/dist/application/events/index.d.ts.map +1 -0
- package/dist/application/events/index.js +6 -0
- package/dist/application/events/index.js.map +1 -0
- package/dist/application/index.d.ts +85 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +138 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/services/cache-coordinator.service.d.ts +69 -0
- package/dist/application/services/cache-coordinator.service.d.ts.map +1 -0
- package/dist/application/services/cache-coordinator.service.js +251 -0
- package/dist/application/services/cache-coordinator.service.js.map +1 -0
- package/dist/application/services/error-handler.service.d.ts +56 -0
- package/dist/application/services/error-handler.service.d.ts.map +1 -0
- package/dist/application/services/error-handler.service.js +273 -0
- package/dist/application/services/error-handler.service.js.map +1 -0
- package/dist/application/services/index.d.ts +8 -0
- package/dist/application/services/index.d.ts.map +1 -0
- package/dist/application/services/index.js +8 -0
- package/dist/application/services/index.js.map +1 -0
- package/dist/application/services/module-coordinator.service.d.ts +70 -0
- package/dist/application/services/module-coordinator.service.d.ts.map +1 -0
- package/dist/application/services/module-coordinator.service.js +418 -0
- package/dist/application/services/module-coordinator.service.js.map +1 -0
- package/dist/application/services/session-manager.service.d.ts +86 -0
- package/dist/application/services/session-manager.service.d.ts.map +1 -0
- package/dist/application/services/session-manager.service.js +318 -0
- package/dist/application/services/session-manager.service.js.map +1 -0
- package/dist/application/services/workflow-engine.service.d.ts +76 -0
- package/dist/application/services/workflow-engine.service.d.ts.map +1 -0
- package/dist/application/services/workflow-engine.service.js +405 -0
- package/dist/application/services/workflow-engine.service.js.map +1 -0
- package/dist/application/state/application-state.d.ts +164 -0
- package/dist/application/state/application-state.d.ts.map +1 -0
- package/dist/application/state/application-state.js +290 -0
- package/dist/application/state/application-state.js.map +1 -0
- package/dist/application/state/index.d.ts +15 -0
- package/dist/application/state/index.d.ts.map +1 -0
- package/dist/application/state/index.js +15 -0
- package/dist/application/state/index.js.map +1 -0
- package/dist/application/state/session-state.d.ts +114 -0
- package/dist/application/state/session-state.d.ts.map +1 -0
- package/dist/application/state/session-state.js +188 -0
- package/dist/application/state/session-state.js.map +1 -0
- package/dist/application/state/state-manager.d.ts +122 -0
- package/dist/application/state/state-manager.d.ts.map +1 -0
- package/dist/application/state/state-manager.js +234 -0
- package/dist/application/state/state-manager.js.map +1 -0
- package/dist/application/types.d.ts +280 -0
- package/dist/application/types.d.ts.map +1 -0
- package/dist/application/types.js +13 -0
- package/dist/application/types.js.map +1 -0
- package/dist/application/workflows/analysis-workflow.d.ts +239 -0
- package/dist/application/workflows/analysis-workflow.d.ts.map +1 -0
- package/dist/application/workflows/analysis-workflow.js +395 -0
- package/dist/application/workflows/analysis-workflow.js.map +1 -0
- package/dist/application/workflows/base-workflow.d.ts +108 -0
- package/dist/application/workflows/base-workflow.d.ts.map +1 -0
- package/dist/application/workflows/base-workflow.js +236 -0
- package/dist/application/workflows/base-workflow.js.map +1 -0
- package/dist/application/workflows/index.d.ts +115 -0
- package/dist/application/workflows/index.d.ts.map +1 -0
- package/dist/application/workflows/index.js +218 -0
- package/dist/application/workflows/index.js.map +1 -0
- package/dist/application/workflows/refactor-workflow.d.ts +107 -0
- package/dist/application/workflows/refactor-workflow.d.ts.map +1 -0
- package/dist/application/workflows/refactor-workflow.js +310 -0
- package/dist/application/workflows/refactor-workflow.js.map +1 -0
- package/dist/core/analysis/complexity-analyzer.d.ts +81 -0
- package/dist/core/analysis/complexity-analyzer.d.ts.map +1 -0
- package/dist/core/analysis/complexity-analyzer.js +254 -0
- package/dist/core/analysis/complexity-analyzer.js.map +1 -0
- package/dist/core/analysis/dead-code-detector.d.ts +123 -0
- package/dist/core/analysis/dead-code-detector.d.ts.map +1 -0
- package/dist/core/analysis/dead-code-detector.js +275 -0
- package/dist/core/analysis/dead-code-detector.js.map +1 -0
- package/dist/core/analysis/duplication-detector.d.ts +150 -0
- package/dist/core/analysis/duplication-detector.d.ts.map +1 -0
- package/dist/core/analysis/duplication-detector.js +433 -0
- package/dist/core/analysis/duplication-detector.js.map +1 -0
- package/dist/core/analysis/index.d.ts +9 -0
- package/dist/core/analysis/index.d.ts.map +1 -0
- package/dist/core/analysis/index.js +13 -0
- package/dist/core/analysis/index.js.map +1 -0
- package/dist/core/analysis/quality-metrics.d.ts +158 -0
- package/dist/core/analysis/quality-metrics.d.ts.map +1 -0
- package/dist/core/analysis/quality-metrics.js +442 -0
- package/dist/core/analysis/quality-metrics.js.map +1 -0
- package/dist/core/dependency/cycle-detector.d.ts +81 -0
- package/dist/core/dependency/cycle-detector.d.ts.map +1 -0
- package/dist/core/dependency/cycle-detector.js +300 -0
- package/dist/core/dependency/cycle-detector.js.map +1 -0
- package/dist/core/dependency/dependency-analyzer.d.ts +152 -0
- package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -0
- package/dist/core/dependency/dependency-analyzer.js +458 -0
- package/dist/core/dependency/dependency-analyzer.js.map +1 -0
- package/dist/core/dependency/dependency-graph.d.ts +156 -0
- package/dist/core/dependency/dependency-graph.d.ts.map +1 -0
- package/dist/core/dependency/dependency-graph.js +371 -0
- package/dist/core/dependency/dependency-graph.js.map +1 -0
- package/dist/core/dependency/index.d.ts +27 -0
- package/dist/core/dependency/index.d.ts.map +1 -0
- package/dist/core/dependency/index.js +36 -0
- package/dist/core/dependency/index.js.map +1 -0
- package/dist/core/dependency/types.d.ts +168 -0
- package/dist/core/dependency/types.d.ts.map +1 -0
- package/dist/core/dependency/types.js +103 -0
- package/dist/core/dependency/types.js.map +1 -0
- package/dist/core/indexing/file-index.d.ts +117 -0
- package/dist/core/indexing/file-index.d.ts.map +1 -0
- package/dist/core/indexing/file-index.js +302 -0
- package/dist/core/indexing/file-index.js.map +1 -0
- package/dist/core/indexing/file-watcher.d.ts +110 -0
- package/dist/core/indexing/file-watcher.d.ts.map +1 -0
- package/dist/core/indexing/file-watcher.js +280 -0
- package/dist/core/indexing/file-watcher.js.map +1 -0
- package/dist/core/indexing/index-engine.d.ts +120 -0
- package/dist/core/indexing/index-engine.d.ts.map +1 -0
- package/dist/core/indexing/index-engine.js +445 -0
- package/dist/core/indexing/index-engine.js.map +1 -0
- package/dist/core/indexing/index.d.ts +25 -0
- package/dist/core/indexing/index.d.ts.map +1 -0
- package/dist/core/indexing/index.js +36 -0
- package/dist/core/indexing/index.js.map +1 -0
- package/dist/core/indexing/symbol-index.d.ts +107 -0
- package/dist/core/indexing/symbol-index.d.ts.map +1 -0
- package/dist/core/indexing/symbol-index.js +352 -0
- package/dist/core/indexing/symbol-index.js.map +1 -0
- package/dist/core/indexing/types.d.ts +222 -0
- package/dist/core/indexing/types.d.ts.map +1 -0
- package/dist/core/indexing/types.js +143 -0
- package/dist/core/indexing/types.js.map +1 -0
- package/dist/core/move/import-resolver.d.ts +54 -0
- package/dist/core/move/import-resolver.d.ts.map +1 -0
- package/dist/core/move/import-resolver.js +268 -0
- package/dist/core/move/import-resolver.js.map +1 -0
- package/dist/core/move/index.d.ts +10 -0
- package/dist/core/move/index.d.ts.map +1 -0
- package/dist/core/move/index.js +12 -0
- package/dist/core/move/index.js.map +1 -0
- package/dist/core/move/move-service.d.ts +67 -0
- package/dist/core/move/move-service.d.ts.map +1 -0
- package/dist/core/move/move-service.js +400 -0
- package/dist/core/move/move-service.js.map +1 -0
- package/dist/core/move/types.d.ts +266 -0
- package/dist/core/move/types.d.ts.map +1 -0
- package/dist/core/move/types.js +101 -0
- package/dist/core/move/types.js.map +1 -0
- package/dist/core/performance/analyzer.d.ts +62 -0
- package/dist/core/performance/analyzer.d.ts.map +1 -0
- package/dist/core/performance/analyzer.js +378 -0
- package/dist/core/performance/analyzer.js.map +1 -0
- package/dist/core/performance/cache-manager.d.ts +161 -0
- package/dist/core/performance/cache-manager.d.ts.map +1 -0
- package/dist/core/performance/cache-manager.js +375 -0
- package/dist/core/performance/cache-manager.js.map +1 -0
- package/dist/core/performance/index.d.ts +14 -0
- package/dist/core/performance/index.d.ts.map +1 -0
- package/dist/core/performance/index.js +17 -0
- package/dist/core/performance/index.js.map +1 -0
- package/dist/core/performance/interfaces.d.ts +188 -0
- package/dist/core/performance/interfaces.d.ts.map +1 -0
- package/dist/core/performance/interfaces.js +17 -0
- package/dist/core/performance/interfaces.js.map +1 -0
- package/dist/core/performance/memory-manager.d.ts +176 -0
- package/dist/core/performance/memory-manager.d.ts.map +1 -0
- package/dist/core/performance/memory-manager.js +364 -0
- package/dist/core/performance/memory-manager.js.map +1 -0
- package/dist/core/performance/monitor.d.ts +92 -0
- package/dist/core/performance/monitor.d.ts.map +1 -0
- package/dist/core/performance/monitor.js +228 -0
- package/dist/core/performance/monitor.js.map +1 -0
- package/dist/core/refactor/design-patterns.d.ts +178 -0
- package/dist/core/refactor/design-patterns.d.ts.map +1 -0
- package/dist/core/refactor/design-patterns.js +656 -0
- package/dist/core/refactor/design-patterns.js.map +1 -0
- package/dist/core/refactor/extract-function.d.ts +175 -0
- package/dist/core/refactor/extract-function.d.ts.map +1 -0
- package/dist/core/refactor/extract-function.js +478 -0
- package/dist/core/refactor/extract-function.js.map +1 -0
- package/dist/core/refactor/index.d.ts +8 -0
- package/dist/core/refactor/index.d.ts.map +1 -0
- package/dist/core/refactor/index.js +11 -0
- package/dist/core/refactor/index.js.map +1 -0
- package/dist/core/refactor/inline-function.d.ts +175 -0
- package/dist/core/refactor/inline-function.d.ts.map +1 -0
- package/dist/core/refactor/inline-function.js +425 -0
- package/dist/core/refactor/inline-function.js.map +1 -0
- package/dist/core/rename/index.d.ts +9 -0
- package/dist/core/rename/index.d.ts.map +1 -0
- package/dist/core/rename/index.js +13 -0
- package/dist/core/rename/index.js.map +1 -0
- package/dist/core/rename/reference-updater.d.ts +77 -0
- package/dist/core/rename/reference-updater.d.ts.map +1 -0
- package/dist/core/rename/reference-updater.js +400 -0
- package/dist/core/rename/reference-updater.js.map +1 -0
- package/dist/core/rename/rename-engine.d.ts +69 -0
- package/dist/core/rename/rename-engine.d.ts.map +1 -0
- package/dist/core/rename/rename-engine.js +350 -0
- package/dist/core/rename/rename-engine.js.map +1 -0
- package/dist/core/rename/scope-analyzer.d.ts +75 -0
- package/dist/core/rename/scope-analyzer.d.ts.map +1 -0
- package/dist/core/rename/scope-analyzer.js +269 -0
- package/dist/core/rename/scope-analyzer.js.map +1 -0
- package/dist/core/rename/types.d.ts +163 -0
- package/dist/core/rename/types.d.ts.map +1 -0
- package/dist/core/rename/types.js +80 -0
- package/dist/core/rename/types.js.map +1 -0
- package/dist/core/search/engines/text-engine.d.ts +52 -0
- package/dist/core/search/engines/text-engine.d.ts.map +1 -0
- package/dist/core/search/engines/text-engine.js +376 -0
- package/dist/core/search/engines/text-engine.js.map +1 -0
- package/dist/core/search/index.d.ts +10 -0
- package/dist/core/search/index.d.ts.map +1 -0
- package/dist/core/search/index.js +11 -0
- package/dist/core/search/index.js.map +1 -0
- package/dist/core/search/service.d.ts +105 -0
- package/dist/core/search/service.d.ts.map +1 -0
- package/dist/core/search/service.js +384 -0
- package/dist/core/search/service.js.map +1 -0
- package/dist/core/search/types.d.ts +357 -0
- package/dist/core/search/types.d.ts.map +1 -0
- package/dist/core/search/types.js +47 -0
- package/dist/core/search/types.js.map +1 -0
- package/dist/infrastructure/cache/cache-manager.d.ts +113 -0
- package/dist/infrastructure/cache/cache-manager.d.ts.map +1 -0
- package/dist/infrastructure/cache/cache-manager.js +279 -0
- package/dist/infrastructure/cache/cache-manager.js.map +1 -0
- package/dist/infrastructure/cache/index.d.ts +138 -0
- package/dist/infrastructure/cache/index.d.ts.map +1 -0
- package/dist/infrastructure/cache/index.js +266 -0
- package/dist/infrastructure/cache/index.js.map +1 -0
- package/dist/infrastructure/cache/memory-cache.d.ts +94 -0
- package/dist/infrastructure/cache/memory-cache.d.ts.map +1 -0
- package/dist/infrastructure/cache/memory-cache.js +327 -0
- package/dist/infrastructure/cache/memory-cache.js.map +1 -0
- package/dist/infrastructure/cache/strategies.d.ts +99 -0
- package/dist/infrastructure/cache/strategies.d.ts.map +1 -0
- package/dist/infrastructure/cache/strategies.js +230 -0
- package/dist/infrastructure/cache/strategies.js.map +1 -0
- package/dist/infrastructure/cache/types.d.ts +220 -0
- package/dist/infrastructure/cache/types.d.ts.map +1 -0
- package/dist/infrastructure/cache/types.js +42 -0
- package/dist/infrastructure/cache/types.js.map +1 -0
- package/dist/infrastructure/parser/base.d.ts +126 -0
- package/dist/infrastructure/parser/base.d.ts.map +1 -0
- package/dist/infrastructure/parser/base.js +269 -0
- package/dist/infrastructure/parser/base.js.map +1 -0
- package/dist/infrastructure/parser/factory.d.ts +141 -0
- package/dist/infrastructure/parser/factory.d.ts.map +1 -0
- package/dist/infrastructure/parser/factory.js +306 -0
- package/dist/infrastructure/parser/factory.js.map +1 -0
- package/dist/infrastructure/parser/index.d.ts +12 -0
- package/dist/infrastructure/parser/index.d.ts.map +1 -0
- package/dist/infrastructure/parser/index.js +12 -0
- package/dist/infrastructure/parser/index.js.map +1 -0
- package/dist/infrastructure/parser/interface.d.ts +108 -0
- package/dist/infrastructure/parser/interface.d.ts.map +1 -0
- package/dist/infrastructure/parser/interface.js +72 -0
- package/dist/infrastructure/parser/interface.js.map +1 -0
- package/dist/infrastructure/parser/registry.d.ts +141 -0
- package/dist/infrastructure/parser/registry.d.ts.map +1 -0
- package/dist/infrastructure/parser/registry.js +289 -0
- package/dist/infrastructure/parser/registry.js.map +1 -0
- package/dist/infrastructure/parser/types.d.ts +172 -0
- package/dist/infrastructure/parser/types.d.ts.map +1 -0
- package/dist/infrastructure/parser/types.js +147 -0
- package/dist/infrastructure/parser/types.js.map +1 -0
- package/dist/infrastructure/storage/file-system.d.ts +74 -0
- package/dist/infrastructure/storage/file-system.d.ts.map +1 -0
- package/dist/infrastructure/storage/file-system.js +334 -0
- package/dist/infrastructure/storage/file-system.js.map +1 -0
- package/dist/infrastructure/storage/file-watcher.d.ts +84 -0
- package/dist/infrastructure/storage/file-watcher.d.ts.map +1 -0
- package/dist/infrastructure/storage/file-watcher.js +249 -0
- package/dist/infrastructure/storage/file-watcher.js.map +1 -0
- package/dist/infrastructure/storage/index.d.ts +11 -0
- package/dist/infrastructure/storage/index.d.ts.map +1 -0
- package/dist/infrastructure/storage/index.js +16 -0
- package/dist/infrastructure/storage/index.js.map +1 -0
- package/dist/infrastructure/storage/path-utils.d.ts +96 -0
- package/dist/infrastructure/storage/path-utils.d.ts.map +1 -0
- package/dist/infrastructure/storage/path-utils.js +272 -0
- package/dist/infrastructure/storage/path-utils.js.map +1 -0
- package/dist/infrastructure/storage/types.d.ts +106 -0
- package/dist/infrastructure/storage/types.d.ts.map +1 -0
- package/dist/infrastructure/storage/types.js +53 -0
- package/dist/infrastructure/storage/types.js.map +1 -0
- package/dist/interfaces/cli/cli.d.ts +70 -0
- package/dist/interfaces/cli/cli.d.ts.map +1 -0
- package/dist/interfaces/cli/cli.js +1054 -0
- package/dist/interfaces/cli/cli.js.map +1 -0
- package/dist/interfaces/cli/index.d.ts +7 -0
- package/dist/interfaces/cli/index.d.ts.map +1 -0
- package/dist/interfaces/cli/index.js +22 -0
- package/dist/interfaces/cli/index.js.map +1 -0
- package/dist/interfaces/mcp/index.d.ts +7 -0
- package/dist/interfaces/mcp/index.d.ts.map +1 -0
- package/dist/interfaces/mcp/index.js +6 -0
- package/dist/interfaces/mcp/index.js.map +1 -0
- package/dist/interfaces/mcp/mcp-server.d.ts +34 -0
- package/dist/interfaces/mcp/mcp-server.d.ts.map +1 -0
- package/dist/interfaces/mcp/mcp-server.js +154 -0
- package/dist/interfaces/mcp/mcp-server.js.map +1 -0
- package/dist/interfaces/mcp/mcp.d.ts +44 -0
- package/dist/interfaces/mcp/mcp.d.ts.map +1 -0
- package/dist/interfaces/mcp/mcp.js +559 -0
- package/dist/interfaces/mcp/mcp.js.map +1 -0
- package/dist/plugins/javascript/index.d.ts +12 -0
- package/dist/plugins/javascript/index.d.ts.map +1 -0
- package/dist/plugins/javascript/index.js +16 -0
- package/dist/plugins/javascript/index.js.map +1 -0
- package/dist/plugins/javascript/parser.d.ts +81 -0
- package/dist/plugins/javascript/parser.d.ts.map +1 -0
- package/dist/plugins/javascript/parser.js +457 -0
- package/dist/plugins/javascript/parser.js.map +1 -0
- package/dist/plugins/javascript/types.d.ts +131 -0
- package/dist/plugins/javascript/types.d.ts.map +1 -0
- package/dist/plugins/javascript/types.js +366 -0
- package/dist/plugins/javascript/types.js.map +1 -0
- package/dist/plugins/swift/index.d.ts +11 -0
- package/dist/plugins/swift/index.d.ts.map +1 -0
- package/dist/plugins/swift/index.js +15 -0
- package/dist/plugins/swift/index.js.map +1 -0
- package/dist/plugins/swift/parser.d.ts +98 -0
- package/dist/plugins/swift/parser.d.ts.map +1 -0
- package/dist/plugins/swift/parser.js +612 -0
- package/dist/plugins/swift/parser.js.map +1 -0
- package/dist/plugins/swift/types.d.ts +196 -0
- package/dist/plugins/swift/types.d.ts.map +1 -0
- package/dist/plugins/swift/types.js +268 -0
- package/dist/plugins/swift/types.js.map +1 -0
- package/dist/plugins/typescript/dependency-analyzer.d.ts +78 -0
- package/dist/plugins/typescript/dependency-analyzer.d.ts.map +1 -0
- package/dist/plugins/typescript/dependency-analyzer.js +305 -0
- package/dist/plugins/typescript/dependency-analyzer.js.map +1 -0
- package/dist/plugins/typescript/index.d.ts +9 -0
- package/dist/plugins/typescript/index.d.ts.map +1 -0
- package/dist/plugins/typescript/index.js +8 -0
- package/dist/plugins/typescript/index.js.map +1 -0
- package/dist/plugins/typescript/parser.d.ts +117 -0
- package/dist/plugins/typescript/parser.d.ts.map +1 -0
- package/dist/plugins/typescript/parser.js +888 -0
- package/dist/plugins/typescript/parser.js.map +1 -0
- package/dist/plugins/typescript/symbol-extractor.d.ts +76 -0
- package/dist/plugins/typescript/symbol-extractor.d.ts.map +1 -0
- package/dist/plugins/typescript/symbol-extractor.js +339 -0
- package/dist/plugins/typescript/symbol-extractor.js.map +1 -0
- package/dist/plugins/typescript/types.d.ts +131 -0
- package/dist/plugins/typescript/types.d.ts.map +1 -0
- package/dist/plugins/typescript/types.js +331 -0
- package/dist/plugins/typescript/types.js.map +1 -0
- package/dist/shared/errors/base-error.d.ts +27 -0
- package/dist/shared/errors/base-error.d.ts.map +1 -0
- package/dist/shared/errors/base-error.js +58 -0
- package/dist/shared/errors/base-error.js.map +1 -0
- package/dist/shared/errors/config-error.d.ts +21 -0
- package/dist/shared/errors/config-error.d.ts.map +1 -0
- package/dist/shared/errors/config-error.js +34 -0
- package/dist/shared/errors/config-error.js.map +1 -0
- package/dist/shared/errors/file-error.d.ts +21 -0
- package/dist/shared/errors/file-error.d.ts.map +1 -0
- package/dist/shared/errors/file-error.js +34 -0
- package/dist/shared/errors/file-error.js.map +1 -0
- package/dist/shared/errors/index.d.ts +59 -0
- package/dist/shared/errors/index.d.ts.map +1 -0
- package/dist/shared/errors/index.js +114 -0
- package/dist/shared/errors/index.js.map +1 -0
- package/dist/shared/errors/parser-error.d.ts +72 -0
- package/dist/shared/errors/parser-error.d.ts.map +1 -0
- package/dist/shared/errors/parser-error.js +104 -0
- package/dist/shared/errors/parser-error.js.map +1 -0
- package/dist/shared/errors/validation-error.d.ts +21 -0
- package/dist/shared/errors/validation-error.d.ts.map +1 -0
- package/dist/shared/errors/validation-error.js +34 -0
- package/dist/shared/errors/validation-error.js.map +1 -0
- package/dist/shared/index.d.ts +11 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +22 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/types/ast.d.ts +78 -0
- package/dist/shared/types/ast.d.ts.map +1 -0
- package/dist/shared/types/ast.js +215 -0
- package/dist/shared/types/ast.js.map +1 -0
- package/dist/shared/types/core.d.ts +65 -0
- package/dist/shared/types/core.d.ts.map +1 -0
- package/dist/shared/types/core.js +114 -0
- package/dist/shared/types/core.js.map +1 -0
- package/dist/shared/types/index.d.ts +11 -0
- package/dist/shared/types/index.d.ts.map +1 -0
- package/dist/shared/types/index.js +12 -0
- package/dist/shared/types/index.js.map +1 -0
- package/dist/shared/types/symbol.d.ts +119 -0
- package/dist/shared/types/symbol.d.ts.map +1 -0
- package/dist/shared/types/symbol.js +197 -0
- package/dist/shared/types/symbol.js.map +1 -0
- package/dist/shared/utils/array.d.ts +68 -0
- package/dist/shared/utils/array.d.ts.map +1 -0
- package/dist/shared/utils/array.js +165 -0
- package/dist/shared/utils/array.js.map +1 -0
- package/dist/shared/utils/async.d.ts +87 -0
- package/dist/shared/utils/async.d.ts.map +1 -0
- package/dist/shared/utils/async.js +185 -0
- package/dist/shared/utils/async.js.map +1 -0
- package/dist/shared/utils/index.d.ts +32 -0
- package/dist/shared/utils/index.d.ts.map +1 -0
- package/dist/shared/utils/index.js +37 -0
- package/dist/shared/utils/index.js.map +1 -0
- package/dist/shared/utils/memory-monitor.d.ts +83 -0
- package/dist/shared/utils/memory-monitor.d.ts.map +1 -0
- package/dist/shared/utils/memory-monitor.js +168 -0
- package/dist/shared/utils/memory-monitor.js.map +1 -0
- package/dist/shared/utils/object.d.ts +71 -0
- package/dist/shared/utils/object.d.ts.map +1 -0
- package/dist/shared/utils/object.js +284 -0
- package/dist/shared/utils/object.js.map +1 -0
- package/dist/shared/utils/path.d.ts +59 -0
- package/dist/shared/utils/path.d.ts.map +1 -0
- package/dist/shared/utils/path.js +201 -0
- package/dist/shared/utils/path.js.map +1 -0
- package/dist/shared/utils/string.d.ts +74 -0
- package/dist/shared/utils/string.d.ts.map +1 -0
- package/dist/shared/utils/string.js +201 -0
- package/dist/shared/utils/string.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Parser 主要實作
|
|
3
|
+
* 實作 ParserPlugin 介面
|
|
4
|
+
*/
|
|
5
|
+
import * as ts from 'typescript';
|
|
6
|
+
import { createValidationSuccess, createValidationFailure, createCodeEdit, createDefinition, createUsage } from '../../infrastructure/parser/index.js';
|
|
7
|
+
import { createAST, createASTMetadata, ReferenceType, SymbolType } from '../../shared/types/index.js';
|
|
8
|
+
import { DEFAULT_COMPILER_OPTIONS, TypeScriptParseError, createTypeScriptASTNode, createParseError, tsPositionToPosition, positionToTsPosition, tsNodeToRange, isValidIdentifier } from './types.js';
|
|
9
|
+
import { createSymbolExtractor } from './symbol-extractor.js';
|
|
10
|
+
import { createDependencyAnalyzer } from './dependency-analyzer.js';
|
|
11
|
+
import { MemoryMonitor } from '../../shared/utils/memory-monitor.js';
|
|
12
|
+
/**
|
|
13
|
+
* TypeScript Parser 實作
|
|
14
|
+
*/
|
|
15
|
+
export class TypeScriptParser {
|
|
16
|
+
name = 'typescript';
|
|
17
|
+
version = '1.0.0';
|
|
18
|
+
supportedExtensions = ['.ts', '.tsx', '.d.ts'];
|
|
19
|
+
supportedLanguages = ['typescript', 'tsx'];
|
|
20
|
+
symbolExtractor;
|
|
21
|
+
dependencyAnalyzer;
|
|
22
|
+
compilerOptions;
|
|
23
|
+
languageService = null;
|
|
24
|
+
languageServiceHost = null;
|
|
25
|
+
files = new Map();
|
|
26
|
+
constructor(compilerOptions) {
|
|
27
|
+
this.symbolExtractor = createSymbolExtractor();
|
|
28
|
+
this.dependencyAnalyzer = createDependencyAnalyzer();
|
|
29
|
+
this.compilerOptions = { ...DEFAULT_COMPILER_OPTIONS, ...compilerOptions };
|
|
30
|
+
// 註冊到記憶體監控器
|
|
31
|
+
MemoryMonitor.getInstance().register(this);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 解析 TypeScript 程式碼
|
|
35
|
+
*/
|
|
36
|
+
async parse(code, filePath) {
|
|
37
|
+
this.validateInput(code, filePath);
|
|
38
|
+
let program = null;
|
|
39
|
+
try {
|
|
40
|
+
// 使用 TypeScript Compiler API 解析程式碼
|
|
41
|
+
const sourceFile = ts.createSourceFile(filePath, code, this.compilerOptions.target || ts.ScriptTarget.ES2020, true, // setParentNodes
|
|
42
|
+
this.getScriptKind(filePath));
|
|
43
|
+
// 檢查語法錯誤 - 使用 TypeScript Program 來檢查語法錯誤
|
|
44
|
+
program = ts.createProgram([filePath], this.compilerOptions, {
|
|
45
|
+
getSourceFile: (fileName) => fileName === filePath ? sourceFile : undefined,
|
|
46
|
+
writeFile: () => { },
|
|
47
|
+
getCurrentDirectory: () => process.cwd(),
|
|
48
|
+
getDirectories: () => [],
|
|
49
|
+
fileExists: () => true,
|
|
50
|
+
readFile: () => code,
|
|
51
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
52
|
+
useCaseSensitiveFileNames: () => true,
|
|
53
|
+
getNewLine: () => '\n',
|
|
54
|
+
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options)
|
|
55
|
+
});
|
|
56
|
+
// 獲取語法診斷,但不拋出錯誤(TypeScript 能從語法錯誤中恢復)
|
|
57
|
+
const syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
|
|
58
|
+
// 建立我們的 AST 結構
|
|
59
|
+
const rootNode = createTypeScriptASTNode(sourceFile, sourceFile);
|
|
60
|
+
const metadata = createASTMetadata(this.getLanguageFromFilePath(filePath), this.version, { compilerOptions: this.compilerOptions }, Date.now(), 0 // 會在 createAST 中計算
|
|
61
|
+
);
|
|
62
|
+
const baseAST = createAST(filePath, rootNode, metadata);
|
|
63
|
+
const ast = {
|
|
64
|
+
...baseAST,
|
|
65
|
+
root: rootNode,
|
|
66
|
+
tsSourceFile: sourceFile,
|
|
67
|
+
diagnostics: [...syntacticDiagnostics]
|
|
68
|
+
};
|
|
69
|
+
// 立即清理 Program 以避免記憶體洩漏
|
|
70
|
+
program = null;
|
|
71
|
+
return ast;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// 確保在錯誤情況下也清理 Program
|
|
75
|
+
program = null;
|
|
76
|
+
if (error instanceof TypeScriptParseError) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
throw createParseError(`解析失敗: ${error instanceof Error ? error.message : String(error)}`);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
// 最終清理,確保 Program 被釋放
|
|
83
|
+
if (program) {
|
|
84
|
+
program = null;
|
|
85
|
+
}
|
|
86
|
+
// 觸發垃圾回收(如果可用)
|
|
87
|
+
if (typeof global !== 'undefined' && 'gc' in global && typeof global.gc === 'function') {
|
|
88
|
+
global.gc();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 提取符號
|
|
94
|
+
*/
|
|
95
|
+
async extractSymbols(ast) {
|
|
96
|
+
const typedAst = ast;
|
|
97
|
+
return await this.symbolExtractor.extractSymbols(typedAst);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 查找符號引用
|
|
101
|
+
*/
|
|
102
|
+
async findReferences(ast, symbol) {
|
|
103
|
+
const typedAst = ast;
|
|
104
|
+
const typedSymbol = symbol;
|
|
105
|
+
// 確保 Language Service 已初始化
|
|
106
|
+
this.ensureLanguageServiceInitialized(typedAst.tsSourceFile);
|
|
107
|
+
if (!this.languageService) {
|
|
108
|
+
// 如果無法使用 Language Service,回退到原始方法
|
|
109
|
+
return this.findReferencesBasic(ast, symbol);
|
|
110
|
+
}
|
|
111
|
+
const fileName = typedAst.tsSourceFile.fileName;
|
|
112
|
+
// 取得符號位置
|
|
113
|
+
const symbolPosition = this.getSymbolPosition(typedSymbol, typedAst.tsSourceFile);
|
|
114
|
+
if (symbolPosition === undefined) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
// 使用 Language Service 查找引用
|
|
118
|
+
const referencesResult = this.languageService.findReferences(fileName, symbolPosition);
|
|
119
|
+
if (!referencesResult) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const references = [];
|
|
123
|
+
for (const refSymbol of referencesResult) {
|
|
124
|
+
for (const ref of refSymbol.references) {
|
|
125
|
+
const sourceFile = this.getSourceFileFromFileName(ref.fileName);
|
|
126
|
+
if (!sourceFile) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const range = {
|
|
130
|
+
start: tsPositionToPosition(sourceFile, ref.textSpan.start),
|
|
131
|
+
end: tsPositionToPosition(sourceFile, ref.textSpan.start + ref.textSpan.length)
|
|
132
|
+
};
|
|
133
|
+
const refType = ref.isDefinition
|
|
134
|
+
? ReferenceType.Definition
|
|
135
|
+
: ReferenceType.Usage;
|
|
136
|
+
references.push({
|
|
137
|
+
symbol,
|
|
138
|
+
location: {
|
|
139
|
+
filePath: ref.fileName,
|
|
140
|
+
range
|
|
141
|
+
},
|
|
142
|
+
type: refType
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return references;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 基本的符號引用查找(回退方法)
|
|
150
|
+
*/
|
|
151
|
+
async findReferencesBasic(ast, symbol) {
|
|
152
|
+
const typedAst = ast;
|
|
153
|
+
const typedSymbol = symbol;
|
|
154
|
+
const references = [];
|
|
155
|
+
const symbolName = typedSymbol.name;
|
|
156
|
+
// 獲取符號的標識符節點
|
|
157
|
+
const symbolIdentifier = this.getIdentifierFromSymbolNode(typedSymbol.tsNode);
|
|
158
|
+
if (!symbolIdentifier) {
|
|
159
|
+
return references;
|
|
160
|
+
}
|
|
161
|
+
// 使用 TypeScript 原生的節點遍歷,收集所有標識符
|
|
162
|
+
const collectIdentifiers = (node) => {
|
|
163
|
+
if (ts.isIdentifier(node) && node.text === symbolName) {
|
|
164
|
+
// 檢查這個標識符是否真的引用了我們的符號
|
|
165
|
+
if (this.isReferenceToSymbol(node, typedSymbol)) {
|
|
166
|
+
const location = {
|
|
167
|
+
filePath: typedAst.tsSourceFile.fileName,
|
|
168
|
+
range: tsNodeToRange(node, typedAst.tsSourceFile)
|
|
169
|
+
};
|
|
170
|
+
const referenceType = this.getReferenceType(node, typedSymbol);
|
|
171
|
+
references.push({
|
|
172
|
+
symbol,
|
|
173
|
+
location,
|
|
174
|
+
type: referenceType
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// 遞歸處理所有子節點
|
|
179
|
+
ts.forEachChild(node, collectIdentifiers);
|
|
180
|
+
};
|
|
181
|
+
// 從 SourceFile 開始遍歷
|
|
182
|
+
collectIdentifiers(typedAst.tsSourceFile);
|
|
183
|
+
return references;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 提取依賴關係
|
|
187
|
+
*/
|
|
188
|
+
async extractDependencies(ast) {
|
|
189
|
+
const typedAst = ast;
|
|
190
|
+
return await this.dependencyAnalyzer.extractDependencies(typedAst);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 重新命名符號
|
|
194
|
+
*/
|
|
195
|
+
async rename(ast, position, newName) {
|
|
196
|
+
this.validateRenameInput(newName);
|
|
197
|
+
const typedAst = ast;
|
|
198
|
+
const tsPosition = positionToTsPosition(typedAst.tsSourceFile, position);
|
|
199
|
+
// 查找位置上的節點
|
|
200
|
+
const node = this.findNodeAtPosition(typedAst.tsSourceFile, tsPosition);
|
|
201
|
+
if (!node) {
|
|
202
|
+
throw new Error('在指定位置找不到符號');
|
|
203
|
+
}
|
|
204
|
+
// 確保節點是標識符或可重新命名的宣告
|
|
205
|
+
let targetIdentifier = null;
|
|
206
|
+
if (ts.isIdentifier(node)) {
|
|
207
|
+
targetIdentifier = node;
|
|
208
|
+
}
|
|
209
|
+
else if (this.isRenameableNode(node)) {
|
|
210
|
+
targetIdentifier = this.getIdentifierFromSymbolNode(node);
|
|
211
|
+
}
|
|
212
|
+
if (!targetIdentifier) {
|
|
213
|
+
throw new Error('該位置的符號不支援重新命名');
|
|
214
|
+
}
|
|
215
|
+
// 驗證位置確實在標識符上
|
|
216
|
+
const identifierStart = targetIdentifier.getStart(typedAst.tsSourceFile);
|
|
217
|
+
const identifierEnd = targetIdentifier.getEnd();
|
|
218
|
+
if (tsPosition < identifierStart || tsPosition >= identifierEnd) {
|
|
219
|
+
throw new Error('指定位置不在有效的符號標識符上');
|
|
220
|
+
}
|
|
221
|
+
// 查找所有引用
|
|
222
|
+
const symbol = await this.findSymbolAtPosition(typedAst, position);
|
|
223
|
+
if (!symbol) {
|
|
224
|
+
throw new Error('無法找到符號定義');
|
|
225
|
+
}
|
|
226
|
+
const references = await this.findReferences(ast, symbol);
|
|
227
|
+
// 建立編輯操作
|
|
228
|
+
const edits = [];
|
|
229
|
+
for (const reference of references) {
|
|
230
|
+
const edit = createCodeEdit(reference.location.filePath, reference.location.range, newName, 'rename');
|
|
231
|
+
edits.push(edit);
|
|
232
|
+
}
|
|
233
|
+
return edits;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 提取函式重構
|
|
237
|
+
*/
|
|
238
|
+
async extractFunction(ast, selection) {
|
|
239
|
+
// 這是一個複雜的重構操作,目前提供基本實作
|
|
240
|
+
throw new Error('提取函式重構尚未實作');
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 查找定義
|
|
244
|
+
*/
|
|
245
|
+
async findDefinition(ast, position) {
|
|
246
|
+
const typedAst = ast;
|
|
247
|
+
const tsPosition = positionToTsPosition(typedAst.tsSourceFile, position);
|
|
248
|
+
const node = this.findNodeAtPosition(typedAst.tsSourceFile, tsPosition);
|
|
249
|
+
if (!node) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
// 檢查節點是否有效
|
|
253
|
+
if (!node.kind) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
// 如果當前節點本身就是定義,返回它
|
|
257
|
+
if (this.isDefinitionNode(node)) {
|
|
258
|
+
const location = {
|
|
259
|
+
filePath: typedAst.tsSourceFile.fileName,
|
|
260
|
+
range: tsNodeToRange(node, typedAst.tsSourceFile)
|
|
261
|
+
};
|
|
262
|
+
return createDefinition(location, this.getDefinitionKind(node));
|
|
263
|
+
}
|
|
264
|
+
// 如果是標識符,查找它的定義
|
|
265
|
+
if (ts.isIdentifier(node)) {
|
|
266
|
+
const name = node.text;
|
|
267
|
+
const symbols = await this.extractSymbols(ast);
|
|
268
|
+
// 查找匹配名稱的符號定義
|
|
269
|
+
for (const symbol of symbols) {
|
|
270
|
+
if (symbol.name === name) {
|
|
271
|
+
// 直接返回符號的定義位置(不需要檢查 isReferenceToSymbol,因為我們是在查找定義)
|
|
272
|
+
return createDefinition(symbol.location, this.symbolTypeToDefinitionKind(symbol.type));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// 查找符號的定義
|
|
277
|
+
const symbol = await this.findSymbolAtPosition(typedAst, position);
|
|
278
|
+
if (symbol) {
|
|
279
|
+
return createDefinition(symbol.location, this.symbolTypeToDefinitionKind(symbol.type));
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* 查找使用位置
|
|
285
|
+
*/
|
|
286
|
+
async findUsages(ast, symbol) {
|
|
287
|
+
const references = await this.findReferences(ast, symbol);
|
|
288
|
+
// 過濾出使用位置(排除定義)
|
|
289
|
+
return references
|
|
290
|
+
.filter(ref => ref.type === ReferenceType.Usage)
|
|
291
|
+
.map(ref => createUsage(ref.location, this.getReferenceUsageKind(ref)));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 驗證插件狀態
|
|
295
|
+
*/
|
|
296
|
+
async validate() {
|
|
297
|
+
try {
|
|
298
|
+
// 檢查 TypeScript 編譯器是否可用
|
|
299
|
+
const version = ts.version;
|
|
300
|
+
if (!version) {
|
|
301
|
+
return createValidationFailure([{
|
|
302
|
+
code: 'TS_UNAVAILABLE',
|
|
303
|
+
message: 'TypeScript 編譯器不可用',
|
|
304
|
+
location: { filePath: '', range: { start: { line: 0, column: 0, offset: 0 }, end: { line: 0, column: 0, offset: 0 } } }
|
|
305
|
+
}]);
|
|
306
|
+
}
|
|
307
|
+
// 檢查編譯器選項
|
|
308
|
+
const diagnostics = ts.getConfigFileParsingDiagnostics({
|
|
309
|
+
options: this.compilerOptions,
|
|
310
|
+
errors: []
|
|
311
|
+
});
|
|
312
|
+
if (diagnostics.length > 0) {
|
|
313
|
+
return createValidationFailure([{
|
|
314
|
+
code: 'TS_CONFIG_ERROR',
|
|
315
|
+
message: '編譯器選項配置錯誤',
|
|
316
|
+
location: { filePath: '', range: { start: { line: 0, column: 0, offset: 0 }, end: { line: 0, column: 0, offset: 0 } } }
|
|
317
|
+
}]);
|
|
318
|
+
}
|
|
319
|
+
return createValidationSuccess();
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
return createValidationFailure([{
|
|
323
|
+
code: 'TS_VALIDATION_ERROR',
|
|
324
|
+
message: `驗證失敗: ${error instanceof Error ? error.message : String(error)}`,
|
|
325
|
+
location: { filePath: '', range: { start: { line: 0, column: 0, offset: 0 }, end: { line: 0, column: 0, offset: 0 } } }
|
|
326
|
+
}]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* 清理資源
|
|
331
|
+
*/
|
|
332
|
+
async dispose() {
|
|
333
|
+
// 從記憶體監控器取消註冊
|
|
334
|
+
MemoryMonitor.getInstance().unregister(this);
|
|
335
|
+
// 清理 Language Service 和相關資源
|
|
336
|
+
if (this.languageService) {
|
|
337
|
+
this.languageService.dispose();
|
|
338
|
+
this.languageService = null;
|
|
339
|
+
}
|
|
340
|
+
// 清理 Language Service Host
|
|
341
|
+
this.languageServiceHost = null;
|
|
342
|
+
// 清理檔案快取
|
|
343
|
+
this.files.clear();
|
|
344
|
+
// 清理編譯器選項參考(完全清空而非設為空物件)
|
|
345
|
+
this.compilerOptions = null;
|
|
346
|
+
// 清理符號提取器和依賴分析器(如果有 dispose 方法)
|
|
347
|
+
if (this.symbolExtractor && 'dispose' in this.symbolExtractor && typeof this.symbolExtractor.dispose === 'function') {
|
|
348
|
+
await this.symbolExtractor.dispose();
|
|
349
|
+
}
|
|
350
|
+
if (this.dependencyAnalyzer && 'dispose' in this.dependencyAnalyzer && typeof this.dependencyAnalyzer.dispose === 'function') {
|
|
351
|
+
await this.dependencyAnalyzer.dispose();
|
|
352
|
+
}
|
|
353
|
+
// 清理其他參考
|
|
354
|
+
this.symbolExtractor = null;
|
|
355
|
+
this.dependencyAnalyzer = null;
|
|
356
|
+
// 多次觸發垃圾收集以確保記憶體完全釋放
|
|
357
|
+
if (typeof global !== 'undefined' && 'gc' in global && typeof global.gc === 'function') {
|
|
358
|
+
// 進行多次垃圾回收以確保釋放所有 TypeScript 相關資源
|
|
359
|
+
for (let i = 0; i < 3; i++) {
|
|
360
|
+
global.gc();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// 私有輔助方法
|
|
365
|
+
validateInput(code, filePath) {
|
|
366
|
+
if (!code.trim()) {
|
|
367
|
+
throw new Error('程式碼內容不能為空');
|
|
368
|
+
}
|
|
369
|
+
if (!filePath.trim()) {
|
|
370
|
+
throw new Error('檔案路徑不能為空');
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
validateRenameInput(newName) {
|
|
374
|
+
if (!newName.trim()) {
|
|
375
|
+
throw new Error('新名稱不能為空');
|
|
376
|
+
}
|
|
377
|
+
if (!isValidIdentifier(newName)) {
|
|
378
|
+
throw new Error('新名稱必須是有效的 TypeScript 識別符');
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
getScriptKind(filePath) {
|
|
382
|
+
const ext = filePath.substring(filePath.lastIndexOf('.'));
|
|
383
|
+
switch (ext) {
|
|
384
|
+
case '.tsx':
|
|
385
|
+
return ts.ScriptKind.TSX;
|
|
386
|
+
case '.d.ts':
|
|
387
|
+
return ts.ScriptKind.TS;
|
|
388
|
+
case '.ts':
|
|
389
|
+
default:
|
|
390
|
+
return ts.ScriptKind.TS;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
getLanguageFromFilePath(filePath) {
|
|
394
|
+
const ext = filePath.substring(filePath.lastIndexOf('.'));
|
|
395
|
+
return ext === '.tsx' ? 'tsx' : 'typescript';
|
|
396
|
+
}
|
|
397
|
+
getSyntacticDiagnostics(sourceFile) {
|
|
398
|
+
// 對於獨立的 SourceFile,我們跳過語法診斷檢查
|
|
399
|
+
// 在實際專案中,這通常由 Program 提供
|
|
400
|
+
return [];
|
|
401
|
+
}
|
|
402
|
+
findNodeAtPosition(sourceFile, position) {
|
|
403
|
+
function findNode(node) {
|
|
404
|
+
if (position >= node.getStart(sourceFile) && position < node.getEnd()) {
|
|
405
|
+
// 先檢查子節點
|
|
406
|
+
for (const child of node.getChildren(sourceFile)) {
|
|
407
|
+
const result = findNode(child);
|
|
408
|
+
if (result) {
|
|
409
|
+
return result;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// 如果子節點中沒找到,返回當前節點
|
|
413
|
+
return node;
|
|
414
|
+
}
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
return findNode(sourceFile);
|
|
418
|
+
}
|
|
419
|
+
isReferenceToSymbol(node, symbol) {
|
|
420
|
+
if (!ts.isIdentifier(node)) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
const name = node.text;
|
|
424
|
+
if (name !== symbol.name) {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
// 找到符號的標識符節點
|
|
428
|
+
const symbolIdentifier = this.getIdentifierFromSymbolNode(symbol.tsNode);
|
|
429
|
+
if (!symbolIdentifier) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
// 檢查是否為相同符號的引用
|
|
433
|
+
// 1. 如果是符號的定義位置本身
|
|
434
|
+
if (node === symbolIdentifier) {
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
// 2. 對於型別宣告(類別、介面、型別別名等),檢查是否在型別位置使用
|
|
438
|
+
if (ts.isClassDeclaration(symbol.tsNode) ||
|
|
439
|
+
ts.isInterfaceDeclaration(symbol.tsNode) ||
|
|
440
|
+
ts.isTypeAliasDeclaration(symbol.tsNode) ||
|
|
441
|
+
ts.isEnumDeclaration(symbol.tsNode)) {
|
|
442
|
+
// 對於型別,只要名稱相同就是引用(在同一個檔案中)
|
|
443
|
+
if (node.getSourceFile() === symbolIdentifier.getSourceFile()) {
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
// 3. 對於變數、函式和方法,使用作用域檢查
|
|
448
|
+
const symbolScope = this.getScopeContainer(symbolIdentifier);
|
|
449
|
+
const nodeScope = this.getScopeContainer(node);
|
|
450
|
+
// 檢查是否在相同作用域或符號的子作用域內
|
|
451
|
+
if (nodeScope === symbolScope || this.isInScopeChain(node, symbolScope)) {
|
|
452
|
+
// 檢查是否被遮蔽(同名變數在更內層作用域)
|
|
453
|
+
if (!this.isShadowed(node, symbolIdentifier)) {
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
getIdentifierFromSymbolNode(node) {
|
|
460
|
+
// 如果本身就是 Identifier,直接返回
|
|
461
|
+
if (ts.isIdentifier(node)) {
|
|
462
|
+
return node;
|
|
463
|
+
}
|
|
464
|
+
// 對於變數宣告,標識符在 name 屬性中
|
|
465
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
466
|
+
return node.name;
|
|
467
|
+
}
|
|
468
|
+
// 對於函式宣告,標識符在 name 屬性中
|
|
469
|
+
if (ts.isFunctionDeclaration(node) && node.name && ts.isIdentifier(node.name)) {
|
|
470
|
+
return node.name;
|
|
471
|
+
}
|
|
472
|
+
// 對於類別宣告
|
|
473
|
+
if (ts.isClassDeclaration(node) && node.name && ts.isIdentifier(node.name)) {
|
|
474
|
+
return node.name;
|
|
475
|
+
}
|
|
476
|
+
// 對於方法宣告
|
|
477
|
+
if (ts.isMethodDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
478
|
+
return node.name;
|
|
479
|
+
}
|
|
480
|
+
// 對於屬性宣告
|
|
481
|
+
if (ts.isPropertyDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
482
|
+
return node.name;
|
|
483
|
+
}
|
|
484
|
+
// 對於參數
|
|
485
|
+
if (ts.isParameter(node) && ts.isIdentifier(node.name)) {
|
|
486
|
+
return node.name;
|
|
487
|
+
}
|
|
488
|
+
// 對於介面宣告
|
|
489
|
+
if (ts.isInterfaceDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
490
|
+
return node.name;
|
|
491
|
+
}
|
|
492
|
+
// 對於型別別名宣告
|
|
493
|
+
if (ts.isTypeAliasDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
494
|
+
return node.name;
|
|
495
|
+
}
|
|
496
|
+
// 對於列舉宣告
|
|
497
|
+
if (ts.isEnumDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
498
|
+
return node.name;
|
|
499
|
+
}
|
|
500
|
+
// 對於命名空間宣告
|
|
501
|
+
if (ts.isModuleDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
502
|
+
return node.name;
|
|
503
|
+
}
|
|
504
|
+
// 對於 Get/Set 存取器
|
|
505
|
+
if ((ts.isGetAccessor(node) || ts.isSetAccessor(node)) && ts.isIdentifier(node.name)) {
|
|
506
|
+
return node.name;
|
|
507
|
+
}
|
|
508
|
+
// 對於型別參數(泛型)
|
|
509
|
+
if (ts.isTypeParameterDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
510
|
+
return node.name;
|
|
511
|
+
}
|
|
512
|
+
// 對於介面/型別的屬性簽名
|
|
513
|
+
if (ts.isPropertySignature(node) && ts.isIdentifier(node.name)) {
|
|
514
|
+
return node.name;
|
|
515
|
+
}
|
|
516
|
+
// 對於方法簽名
|
|
517
|
+
if (ts.isMethodSignature(node) && ts.isIdentifier(node.name)) {
|
|
518
|
+
return node.name;
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
getNodeScope(node) {
|
|
523
|
+
let current = node.parent;
|
|
524
|
+
while (current) {
|
|
525
|
+
if (ts.isFunctionDeclaration(current) ||
|
|
526
|
+
ts.isMethodDeclaration(current) ||
|
|
527
|
+
ts.isArrowFunction(current) ||
|
|
528
|
+
ts.isFunctionExpression(current)) {
|
|
529
|
+
return `function_${current.pos}_${current.end}`;
|
|
530
|
+
}
|
|
531
|
+
if (ts.isBlock(current) && current.parent &&
|
|
532
|
+
(ts.isIfStatement(current.parent) ||
|
|
533
|
+
ts.isForStatement(current.parent) ||
|
|
534
|
+
ts.isWhileStatement(current.parent))) {
|
|
535
|
+
return `block_${current.pos}_${current.end}`;
|
|
536
|
+
}
|
|
537
|
+
current = current.parent;
|
|
538
|
+
}
|
|
539
|
+
return 'global';
|
|
540
|
+
}
|
|
541
|
+
isInSameScope(node, symbolNode) {
|
|
542
|
+
// 找到符號定義所在的作用域
|
|
543
|
+
let symbolScope = symbolNode.parent;
|
|
544
|
+
while (symbolScope && !this.isScopeNode(symbolScope)) {
|
|
545
|
+
symbolScope = symbolScope.parent;
|
|
546
|
+
}
|
|
547
|
+
// 檢查節點是否在該作用域內
|
|
548
|
+
let currentScope = node.parent;
|
|
549
|
+
while (currentScope) {
|
|
550
|
+
if (currentScope === symbolScope) {
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
currentScope = currentScope.parent;
|
|
554
|
+
}
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
isScopeNode(node) {
|
|
558
|
+
return ts.isFunctionDeclaration(node) ||
|
|
559
|
+
ts.isMethodDeclaration(node) ||
|
|
560
|
+
ts.isArrowFunction(node) ||
|
|
561
|
+
ts.isFunctionExpression(node) ||
|
|
562
|
+
ts.isBlock(node) ||
|
|
563
|
+
ts.isSourceFile(node);
|
|
564
|
+
}
|
|
565
|
+
getReferenceType(node, symbol) {
|
|
566
|
+
// 找到符號的標識符節點
|
|
567
|
+
const symbolIdentifier = this.getIdentifierFromSymbolNode(symbol.tsNode);
|
|
568
|
+
// 如果是符號的原始定義位置
|
|
569
|
+
if (node === symbolIdentifier) {
|
|
570
|
+
return ReferenceType.Definition;
|
|
571
|
+
}
|
|
572
|
+
// 檢查是否為宣告(例如函式參數、變數宣告等)
|
|
573
|
+
if (this.isDeclarationNode(node.parent)) {
|
|
574
|
+
return ReferenceType.Declaration;
|
|
575
|
+
}
|
|
576
|
+
// 否則為使用
|
|
577
|
+
return ReferenceType.Usage;
|
|
578
|
+
}
|
|
579
|
+
isRenameableNode(node) {
|
|
580
|
+
return (ts.isIdentifier(node) ||
|
|
581
|
+
ts.isClassDeclaration(node) ||
|
|
582
|
+
ts.isInterfaceDeclaration(node) ||
|
|
583
|
+
ts.isFunctionDeclaration(node) ||
|
|
584
|
+
ts.isVariableDeclaration(node) ||
|
|
585
|
+
ts.isMethodDeclaration(node) ||
|
|
586
|
+
ts.isPropertyDeclaration(node) ||
|
|
587
|
+
ts.isTypeAliasDeclaration(node) ||
|
|
588
|
+
ts.isEnumDeclaration(node) ||
|
|
589
|
+
ts.isModuleDeclaration(node) ||
|
|
590
|
+
ts.isParameter(node) ||
|
|
591
|
+
ts.isGetAccessor(node) ||
|
|
592
|
+
ts.isSetAccessor(node) ||
|
|
593
|
+
ts.isTypeParameterDeclaration(node) ||
|
|
594
|
+
ts.isPropertySignature(node) ||
|
|
595
|
+
ts.isMethodSignature(node));
|
|
596
|
+
}
|
|
597
|
+
isDefinitionNode(node) {
|
|
598
|
+
return (ts.isClassDeclaration(node) ||
|
|
599
|
+
ts.isInterfaceDeclaration(node) ||
|
|
600
|
+
ts.isFunctionDeclaration(node) ||
|
|
601
|
+
ts.isVariableDeclaration(node) ||
|
|
602
|
+
ts.isMethodDeclaration(node) ||
|
|
603
|
+
ts.isPropertyDeclaration(node) ||
|
|
604
|
+
ts.isTypeAliasDeclaration(node) ||
|
|
605
|
+
ts.isEnumDeclaration(node));
|
|
606
|
+
}
|
|
607
|
+
isDeclarationNode(node) {
|
|
608
|
+
return (ts.isParameter(node) ||
|
|
609
|
+
ts.isVariableDeclaration(node) ||
|
|
610
|
+
ts.isBindingElement(node));
|
|
611
|
+
}
|
|
612
|
+
getDefinitionKind(node) {
|
|
613
|
+
if (ts.isClassDeclaration(node)) {
|
|
614
|
+
return 'class';
|
|
615
|
+
}
|
|
616
|
+
if (ts.isInterfaceDeclaration(node)) {
|
|
617
|
+
return 'interface';
|
|
618
|
+
}
|
|
619
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
620
|
+
return 'function';
|
|
621
|
+
}
|
|
622
|
+
if (ts.isMethodDeclaration(node)) {
|
|
623
|
+
return 'method';
|
|
624
|
+
}
|
|
625
|
+
if (ts.isVariableDeclaration(node)) {
|
|
626
|
+
return 'variable';
|
|
627
|
+
}
|
|
628
|
+
if (ts.isPropertyDeclaration(node)) {
|
|
629
|
+
return 'variable';
|
|
630
|
+
}
|
|
631
|
+
if (ts.isTypeAliasDeclaration(node)) {
|
|
632
|
+
return 'type';
|
|
633
|
+
}
|
|
634
|
+
if (ts.isEnumDeclaration(node)) {
|
|
635
|
+
return 'enum';
|
|
636
|
+
}
|
|
637
|
+
if (ts.isModuleDeclaration(node)) {
|
|
638
|
+
return 'module';
|
|
639
|
+
}
|
|
640
|
+
return 'variable';
|
|
641
|
+
}
|
|
642
|
+
symbolTypeToDefinitionKind(symbolType) {
|
|
643
|
+
// 將 SymbolType 映射到 DefinitionKind
|
|
644
|
+
switch (symbolType) {
|
|
645
|
+
case SymbolType.Class:
|
|
646
|
+
return 'class';
|
|
647
|
+
case SymbolType.Interface:
|
|
648
|
+
return 'interface';
|
|
649
|
+
case SymbolType.Function:
|
|
650
|
+
return 'function';
|
|
651
|
+
case SymbolType.Variable:
|
|
652
|
+
return 'variable';
|
|
653
|
+
case SymbolType.Constant:
|
|
654
|
+
return 'constant';
|
|
655
|
+
case SymbolType.Type:
|
|
656
|
+
return 'type';
|
|
657
|
+
case SymbolType.Enum:
|
|
658
|
+
return 'enum';
|
|
659
|
+
case SymbolType.Module:
|
|
660
|
+
return 'module';
|
|
661
|
+
case SymbolType.Namespace:
|
|
662
|
+
return 'namespace';
|
|
663
|
+
default:
|
|
664
|
+
return 'variable'; // 預設為變數
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
getReferenceUsageKind(reference) {
|
|
668
|
+
// 基於上下文判斷使用類型
|
|
669
|
+
return 'reference'; // 簡化實作
|
|
670
|
+
}
|
|
671
|
+
async findSymbolAtPosition(ast, position) {
|
|
672
|
+
const symbols = await this.extractSymbols(ast);
|
|
673
|
+
const tsPosition = positionToTsPosition(ast.tsSourceFile, position);
|
|
674
|
+
// 查找最精確匹配該位置的符號
|
|
675
|
+
let bestMatch = null;
|
|
676
|
+
let bestMatchSize = Number.MAX_SAFE_INTEGER;
|
|
677
|
+
for (const symbol of symbols) {
|
|
678
|
+
const typedSymbol = symbol;
|
|
679
|
+
// 獲取符號的標識符節點
|
|
680
|
+
const identifier = this.getIdentifierFromSymbolNode(typedSymbol.tsNode);
|
|
681
|
+
if (!identifier) {
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
// 檢查位置是否在標識符範圍內
|
|
685
|
+
const identifierStart = identifier.getStart(ast.tsSourceFile);
|
|
686
|
+
const identifierEnd = identifier.getEnd();
|
|
687
|
+
if (tsPosition >= identifierStart && tsPosition < identifierEnd) {
|
|
688
|
+
// 找到最小的匹配範圍(最精確的符號)
|
|
689
|
+
const size = identifierEnd - identifierStart;
|
|
690
|
+
if (size < bestMatchSize) {
|
|
691
|
+
bestMatch = symbol;
|
|
692
|
+
bestMatchSize = size;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return bestMatch;
|
|
697
|
+
}
|
|
698
|
+
isPositionInRange(position, range) {
|
|
699
|
+
if (position.line < range.start.line || position.line > range.end.line) {
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
if (position.line === range.start.line && position.column < range.start.column) {
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
if (position.line === range.end.line && position.column > range.end.column) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* 初始化 Language Service
|
|
712
|
+
*/
|
|
713
|
+
ensureLanguageServiceInitialized(sourceFile) {
|
|
714
|
+
if (this.languageService) {
|
|
715
|
+
// 更新檔案內容
|
|
716
|
+
this.updateFile(sourceFile.fileName, sourceFile.text);
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
// 添加當前檔案到檔案列表
|
|
720
|
+
this.updateFile(sourceFile.fileName, sourceFile.text);
|
|
721
|
+
// 建立 Language Service Host
|
|
722
|
+
this.languageServiceHost = {
|
|
723
|
+
getScriptFileNames: () => {
|
|
724
|
+
const fileNames = Array.from(this.files.keys());
|
|
725
|
+
// 確保包含當前檔案
|
|
726
|
+
if (!fileNames.includes(sourceFile.fileName)) {
|
|
727
|
+
fileNames.push(sourceFile.fileName);
|
|
728
|
+
}
|
|
729
|
+
return fileNames;
|
|
730
|
+
},
|
|
731
|
+
getScriptVersion: (fileName) => {
|
|
732
|
+
const file = this.files.get(fileName);
|
|
733
|
+
return file ? String(file.version) : '0';
|
|
734
|
+
},
|
|
735
|
+
getScriptSnapshot: (fileName) => {
|
|
736
|
+
const file = this.files.get(fileName);
|
|
737
|
+
if (file) {
|
|
738
|
+
return ts.ScriptSnapshot.fromString(file.content);
|
|
739
|
+
}
|
|
740
|
+
// 嘗試讀取實際檔案
|
|
741
|
+
try {
|
|
742
|
+
const content = ts.sys.readFile(fileName);
|
|
743
|
+
if (content) {
|
|
744
|
+
return ts.ScriptSnapshot.fromString(content);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
catch {
|
|
748
|
+
// 忽略錯誤
|
|
749
|
+
}
|
|
750
|
+
return undefined;
|
|
751
|
+
},
|
|
752
|
+
getCurrentDirectory: () => process.cwd(),
|
|
753
|
+
getCompilationSettings: () => ({
|
|
754
|
+
...this.compilerOptions,
|
|
755
|
+
// 確保啟用必要的選項
|
|
756
|
+
allowNonTsExtensions: true,
|
|
757
|
+
noResolve: false,
|
|
758
|
+
noLib: false,
|
|
759
|
+
lib: this.compilerOptions.lib || ['lib.es2020.d.ts']
|
|
760
|
+
}),
|
|
761
|
+
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
762
|
+
fileExists: (fileName) => {
|
|
763
|
+
return this.files.has(fileName) || (ts.sys.fileExists ? ts.sys.fileExists(fileName) : false);
|
|
764
|
+
},
|
|
765
|
+
readFile: (fileName) => {
|
|
766
|
+
const file = this.files.get(fileName);
|
|
767
|
+
if (file) {
|
|
768
|
+
return file.content;
|
|
769
|
+
}
|
|
770
|
+
return ts.sys.readFile ? ts.sys.readFile(fileName) : undefined;
|
|
771
|
+
},
|
|
772
|
+
readDirectory: ts.sys.readDirectory ? ts.sys.readDirectory : () => [],
|
|
773
|
+
getDirectories: ts.sys.getDirectories ? ts.sys.getDirectories : () => [],
|
|
774
|
+
directoryExists: ts.sys.directoryExists ? ts.sys.directoryExists : () => false,
|
|
775
|
+
realpath: ts.sys.realpath ? ts.sys.realpath : (path) => path,
|
|
776
|
+
getNewLine: () => '\n'
|
|
777
|
+
};
|
|
778
|
+
// 建立 Language Service
|
|
779
|
+
this.languageService = ts.createLanguageService(this.languageServiceHost, ts.createDocumentRegistry());
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* 更新檔案內容
|
|
783
|
+
*/
|
|
784
|
+
updateFile(fileName, content) {
|
|
785
|
+
const existing = this.files.get(fileName);
|
|
786
|
+
if (existing && existing.content === content) {
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
this.files.set(fileName, {
|
|
790
|
+
version: existing ? existing.version + 1 : 0,
|
|
791
|
+
content
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* 取得符號在檔案中的位置
|
|
796
|
+
*/
|
|
797
|
+
getSymbolPosition(symbol, sourceFile) {
|
|
798
|
+
const identifier = this.getIdentifierFromSymbolNode(symbol.tsNode);
|
|
799
|
+
if (!identifier) {
|
|
800
|
+
return undefined;
|
|
801
|
+
}
|
|
802
|
+
return identifier.getStart(sourceFile);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* 根據檔案名稱取得 SourceFile
|
|
806
|
+
*/
|
|
807
|
+
getSourceFileFromFileName(fileName) {
|
|
808
|
+
if (!this.languageService) {
|
|
809
|
+
return undefined;
|
|
810
|
+
}
|
|
811
|
+
const program = this.languageService.getProgram();
|
|
812
|
+
return program?.getSourceFile(fileName);
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* 取得節點的作用域容器
|
|
816
|
+
*/
|
|
817
|
+
getScopeContainer(node) {
|
|
818
|
+
let current = node.parent;
|
|
819
|
+
while (current) {
|
|
820
|
+
if (ts.isFunctionDeclaration(current) ||
|
|
821
|
+
ts.isFunctionExpression(current) ||
|
|
822
|
+
ts.isArrowFunction(current) ||
|
|
823
|
+
ts.isMethodDeclaration(current) ||
|
|
824
|
+
ts.isConstructorDeclaration(current) ||
|
|
825
|
+
ts.isBlock(current) ||
|
|
826
|
+
ts.isSourceFile(current)) {
|
|
827
|
+
return current;
|
|
828
|
+
}
|
|
829
|
+
current = current.parent;
|
|
830
|
+
}
|
|
831
|
+
return node.getSourceFile();
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* 檢查節點是否在指定作用域鏈內
|
|
835
|
+
*/
|
|
836
|
+
isInScopeChain(node, scopeContainer) {
|
|
837
|
+
let current = node.parent;
|
|
838
|
+
while (current) {
|
|
839
|
+
if (current === scopeContainer) {
|
|
840
|
+
return true;
|
|
841
|
+
}
|
|
842
|
+
current = current.parent;
|
|
843
|
+
}
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* 檢查符號是否被遮蔽
|
|
848
|
+
*/
|
|
849
|
+
isShadowed(node, originalIdentifier) {
|
|
850
|
+
const name = originalIdentifier.text;
|
|
851
|
+
let current = node.parent;
|
|
852
|
+
// 從 node 向上遍歷到 originalIdentifier 的作用域
|
|
853
|
+
while (current && current !== originalIdentifier.parent) {
|
|
854
|
+
// 檢查當前作用域是否有同名的宣告
|
|
855
|
+
if (ts.isFunctionDeclaration(current) ||
|
|
856
|
+
ts.isFunctionExpression(current) ||
|
|
857
|
+
ts.isArrowFunction(current) ||
|
|
858
|
+
ts.isMethodDeclaration(current)) {
|
|
859
|
+
// 檢查參數
|
|
860
|
+
if (current.parameters) {
|
|
861
|
+
for (const param of current.parameters) {
|
|
862
|
+
if (ts.isIdentifier(param.name) && param.name.text === name) {
|
|
863
|
+
return true; // 被參數遮蔽
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
// 檢查區塊作用域中的宣告
|
|
869
|
+
if (ts.isBlock(current)) {
|
|
870
|
+
for (const statement of current.statements) {
|
|
871
|
+
if (ts.isVariableStatement(statement)) {
|
|
872
|
+
for (const decl of statement.declarationList.declarations) {
|
|
873
|
+
if (ts.isIdentifier(decl.name) && decl.name.text === name) {
|
|
874
|
+
// 確認這個宣告在 node 之前
|
|
875
|
+
if (decl.pos < node.pos) {
|
|
876
|
+
return true; // 被區域變數遮蔽
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
current = current.parent;
|
|
884
|
+
}
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
//# sourceMappingURL=parser.js.map
|