@optave/codegraph 3.7.0 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -16
- package/dist/ast-analysis/engine.d.ts.map +1 -1
- package/dist/ast-analysis/engine.js +195 -30
- package/dist/ast-analysis/engine.js.map +1 -1
- package/dist/ast-analysis/metrics.d.ts +0 -3
- package/dist/ast-analysis/metrics.d.ts.map +1 -1
- package/dist/ast-analysis/metrics.js +30 -13
- package/dist/ast-analysis/metrics.js.map +1 -1
- package/dist/ast-analysis/rules/javascript.d.ts.map +1 -1
- package/dist/ast-analysis/rules/javascript.js +0 -1
- package/dist/ast-analysis/rules/javascript.js.map +1 -1
- package/dist/ast-analysis/shared.d.ts.map +1 -1
- package/dist/ast-analysis/shared.js +24 -19
- package/dist/ast-analysis/shared.js.map +1 -1
- package/dist/ast-analysis/visitor-utils.d.ts.map +1 -1
- package/dist/ast-analysis/visitor-utils.js +55 -39
- package/dist/ast-analysis/visitor-utils.js.map +1 -1
- package/dist/ast-analysis/visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitor.js +91 -70
- package/dist/ast-analysis/visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/ast-store-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/ast-store-visitor.js +52 -129
- package/dist/ast-analysis/visitors/ast-store-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.js +32 -39
- package/dist/ast-analysis/visitors/complexity-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.js +57 -38
- package/dist/ast-analysis/visitors/dataflow-visitor.js.map +1 -1
- package/dist/cli/commands/ast.js +2 -2
- package/dist/cli/commands/ast.js.map +1 -1
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +16 -2
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +29 -26
- package/dist/db/connection.js.map +1 -1
- package/dist/db/query-builder.d.ts.map +1 -1
- package/dist/db/query-builder.js +16 -5
- package/dist/db/query-builder.js.map +1 -1
- package/dist/db/repository/base.d.ts +10 -0
- package/dist/db/repository/base.d.ts.map +1 -1
- package/dist/db/repository/base.js +17 -0
- package/dist/db/repository/base.js.map +1 -1
- package/dist/db/repository/native-repository.d.ts +6 -1
- package/dist/db/repository/native-repository.d.ts.map +1 -1
- package/dist/db/repository/native-repository.js +77 -1
- package/dist/db/repository/native-repository.js.map +1 -1
- package/dist/db/repository/nodes.d.ts.map +1 -1
- package/dist/db/repository/nodes.js +8 -4
- package/dist/db/repository/nodes.js.map +1 -1
- package/dist/db/repository/sqlite-repository.d.ts +3 -0
- package/dist/db/repository/sqlite-repository.d.ts.map +1 -1
- package/dist/db/repository/sqlite-repository.js +26 -0
- package/dist/db/repository/sqlite-repository.js.map +1 -1
- package/dist/domain/analysis/brief.d.ts.map +1 -1
- package/dist/domain/analysis/brief.js +13 -17
- package/dist/domain/analysis/brief.js.map +1 -1
- package/dist/domain/analysis/context.d.ts.map +1 -1
- package/dist/domain/analysis/context.js +14 -11
- package/dist/domain/analysis/context.js.map +1 -1
- package/dist/domain/analysis/dependencies.d.ts.map +1 -1
- package/dist/domain/analysis/dependencies.js +53 -52
- package/dist/domain/analysis/dependencies.js.map +1 -1
- package/dist/domain/analysis/fn-impact.d.ts +2 -7
- package/dist/domain/analysis/fn-impact.d.ts.map +1 -1
- package/dist/domain/analysis/fn-impact.js +33 -31
- package/dist/domain/analysis/fn-impact.js.map +1 -1
- package/dist/domain/analysis/implementations.d.ts.map +1 -1
- package/dist/domain/analysis/implementations.js +11 -19
- package/dist/domain/analysis/implementations.js.map +1 -1
- package/dist/domain/analysis/module-map.d.ts.map +1 -1
- package/dist/domain/analysis/module-map.js +55 -76
- package/dist/domain/analysis/module-map.js.map +1 -1
- package/dist/domain/analysis/query-helpers.d.ts +7 -0
- package/dist/domain/analysis/query-helpers.d.ts.map +1 -1
- package/dist/domain/analysis/query-helpers.js +15 -1
- package/dist/domain/analysis/query-helpers.js.map +1 -1
- package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
- package/dist/domain/graph/builder/pipeline.js +315 -43
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +106 -1
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.js +17 -5
- package/dist/domain/graph/builder/stages/collect-files.js.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.js +99 -51
- package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.js +34 -7
- package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.js +50 -26
- package/dist/domain/graph/builder/stages/insert-nodes.js.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.js +95 -84
- package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
- package/dist/domain/graph/cycles.d.ts +6 -0
- package/dist/domain/graph/cycles.d.ts.map +1 -1
- package/dist/domain/graph/cycles.js +114 -22
- package/dist/domain/graph/cycles.js.map +1 -1
- package/dist/domain/graph/resolve.js +1 -1
- package/dist/domain/graph/resolve.js.map +1 -1
- package/dist/domain/graph/watcher.d.ts +2 -0
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +170 -75
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts +1 -6
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +101 -32
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/search/generator.js +1 -1
- package/dist/domain/search/generator.js.map +1 -1
- package/dist/domain/search/models.d.ts +4 -3
- package/dist/domain/search/models.d.ts.map +1 -1
- package/dist/domain/search/models.js +18 -5
- package/dist/domain/search/models.js.map +1 -1
- package/dist/domain/search/search/hybrid.d.ts.map +1 -1
- package/dist/domain/search/search/hybrid.js +29 -18
- package/dist/domain/search/search/hybrid.js.map +1 -1
- package/dist/extractors/clojure.d.ts +12 -0
- package/dist/extractors/clojure.d.ts.map +1 -0
- package/dist/extractors/clojure.js +245 -0
- package/dist/extractors/clojure.js.map +1 -0
- package/dist/extractors/cuda.d.ts +11 -0
- package/dist/extractors/cuda.d.ts.map +1 -0
- package/dist/extractors/cuda.js +302 -0
- package/dist/extractors/cuda.js.map +1 -0
- package/dist/extractors/erlang.d.ts +14 -0
- package/dist/extractors/erlang.d.ts.map +1 -0
- package/dist/extractors/erlang.js +239 -0
- package/dist/extractors/erlang.js.map +1 -0
- package/dist/extractors/fsharp.d.ts +13 -0
- package/dist/extractors/fsharp.d.ts.map +1 -0
- package/dist/extractors/fsharp.js +218 -0
- package/dist/extractors/fsharp.js.map +1 -0
- package/dist/extractors/gleam.d.ts +14 -0
- package/dist/extractors/gleam.d.ts.map +1 -0
- package/dist/extractors/gleam.js +229 -0
- package/dist/extractors/gleam.js.map +1 -0
- package/dist/extractors/go.js +36 -33
- package/dist/extractors/go.js.map +1 -1
- package/dist/extractors/groovy.d.ts +10 -0
- package/dist/extractors/groovy.d.ts.map +1 -0
- package/dist/extractors/groovy.js +304 -0
- package/dist/extractors/groovy.js.map +1 -0
- package/dist/extractors/helpers.d.ts.map +1 -1
- package/dist/extractors/helpers.js +40 -29
- package/dist/extractors/helpers.js.map +1 -1
- package/dist/extractors/index.d.ts +11 -0
- package/dist/extractors/index.d.ts.map +1 -1
- package/dist/extractors/index.js +11 -0
- package/dist/extractors/index.js.map +1 -1
- package/dist/extractors/java.js +58 -46
- package/dist/extractors/java.js.map +1 -1
- package/dist/extractors/javascript.js +46 -45
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/extractors/julia.d.ts +16 -0
- package/dist/extractors/julia.d.ts.map +1 -0
- package/dist/extractors/julia.js +287 -0
- package/dist/extractors/julia.js.map +1 -0
- package/dist/extractors/kotlin.js +84 -78
- package/dist/extractors/kotlin.js.map +1 -1
- package/dist/extractors/objc.d.ts +9 -0
- package/dist/extractors/objc.d.ts.map +1 -0
- package/dist/extractors/objc.js +406 -0
- package/dist/extractors/objc.js.map +1 -0
- package/dist/extractors/ocaml.js +74 -0
- package/dist/extractors/ocaml.js.map +1 -1
- package/dist/extractors/python.js +29 -24
- package/dist/extractors/python.js.map +1 -1
- package/dist/extractors/r.d.ts +13 -0
- package/dist/extractors/r.d.ts.map +1 -0
- package/dist/extractors/r.js +251 -0
- package/dist/extractors/r.js.map +1 -0
- package/dist/extractors/rust.js +41 -32
- package/dist/extractors/rust.js.map +1 -1
- package/dist/extractors/solidity.d.ts +9 -0
- package/dist/extractors/solidity.d.ts.map +1 -0
- package/dist/extractors/solidity.js +365 -0
- package/dist/extractors/solidity.js.map +1 -0
- package/dist/extractors/swift.js +83 -81
- package/dist/extractors/swift.js.map +1 -1
- package/dist/extractors/verilog.d.ts +9 -0
- package/dist/extractors/verilog.d.ts.map +1 -0
- package/dist/extractors/verilog.js +286 -0
- package/dist/extractors/verilog.js.map +1 -0
- package/dist/extractors/zig.js +58 -60
- package/dist/extractors/zig.js.map +1 -1
- package/dist/features/ast.d.ts +16 -14
- package/dist/features/ast.d.ts.map +1 -1
- package/dist/features/ast.js +84 -83
- package/dist/features/ast.js.map +1 -1
- package/dist/features/audit.d.ts.map +1 -1
- package/dist/features/audit.js +8 -6
- package/dist/features/audit.js.map +1 -1
- package/dist/features/branch-compare.d.ts.map +1 -1
- package/dist/features/branch-compare.js +69 -72
- package/dist/features/branch-compare.js.map +1 -1
- package/dist/features/communities.d.ts.map +1 -1
- package/dist/features/communities.js +19 -7
- package/dist/features/communities.js.map +1 -1
- package/dist/features/complexity.d.ts.map +1 -1
- package/dist/features/complexity.js +120 -125
- package/dist/features/complexity.js.map +1 -1
- package/dist/features/dataflow.d.ts.map +1 -1
- package/dist/features/dataflow.js +136 -137
- package/dist/features/dataflow.js.map +1 -1
- package/dist/features/flow.d.ts.map +1 -1
- package/dist/features/flow.js +84 -79
- package/dist/features/flow.js.map +1 -1
- package/dist/features/structure-query.d.ts.map +1 -1
- package/dist/features/structure-query.js +69 -65
- package/dist/features/structure-query.js.map +1 -1
- package/dist/graph/algorithms/bfs.d.ts +2 -0
- package/dist/graph/algorithms/bfs.d.ts.map +1 -1
- package/dist/graph/algorithms/bfs.js +27 -0
- package/dist/graph/algorithms/bfs.js.map +1 -1
- package/dist/graph/algorithms/centrality.d.ts +2 -0
- package/dist/graph/algorithms/centrality.d.ts.map +1 -1
- package/dist/graph/algorithms/centrality.js +28 -0
- package/dist/graph/algorithms/centrality.js.map +1 -1
- package/dist/graph/algorithms/leiden/optimiser.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/optimiser.js +70 -55
- package/dist/graph/algorithms/leiden/optimiser.js.map +1 -1
- package/dist/graph/algorithms/leiden/partition.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/partition.js +288 -266
- package/dist/graph/algorithms/leiden/partition.js.map +1 -1
- package/dist/graph/algorithms/louvain.d.ts +3 -4
- package/dist/graph/algorithms/louvain.d.ts.map +1 -1
- package/dist/graph/algorithms/louvain.js +29 -0
- package/dist/graph/algorithms/louvain.js.map +1 -1
- package/dist/graph/algorithms/shortest-path.d.ts +2 -0
- package/dist/graph/algorithms/shortest-path.d.ts.map +1 -1
- package/dist/graph/algorithms/shortest-path.js +18 -1
- package/dist/graph/algorithms/shortest-path.js.map +1 -1
- package/dist/graph/model.d.ts.map +1 -1
- package/dist/graph/model.js +5 -1
- package/dist/graph/model.js.map +1 -1
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +6 -4
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/infrastructure/suppress.d.ts +25 -0
- package/dist/infrastructure/suppress.d.ts.map +1 -0
- package/dist/infrastructure/suppress.js +43 -0
- package/dist/infrastructure/suppress.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +29 -24
- package/dist/mcp/server.js.map +1 -1
- package/dist/presentation/dataflow.d.ts.map +1 -1
- package/dist/presentation/dataflow.js +47 -38
- package/dist/presentation/dataflow.js.map +1 -1
- package/dist/presentation/diff-impact-mermaid.d.ts.map +1 -1
- package/dist/presentation/diff-impact-mermaid.js +60 -51
- package/dist/presentation/diff-impact-mermaid.js.map +1 -1
- package/dist/presentation/queries-cli/exports.d.ts.map +1 -1
- package/dist/presentation/queries-cli/exports.js +20 -14
- package/dist/presentation/queries-cli/exports.js.map +1 -1
- package/dist/presentation/queries-cli/impact.d.ts.map +1 -1
- package/dist/presentation/queries-cli/impact.js +15 -13
- package/dist/presentation/queries-cli/impact.js.map +1 -1
- package/dist/presentation/queries-cli/inspect.d.ts.map +1 -1
- package/dist/presentation/queries-cli/inspect.js +101 -79
- package/dist/presentation/queries-cli/inspect.js.map +1 -1
- package/dist/presentation/queries-cli/overview.d.ts.map +1 -1
- package/dist/presentation/queries-cli/overview.js +25 -16
- package/dist/presentation/queries-cli/overview.js.map +1 -1
- package/dist/presentation/queries-cli/path.js +26 -20
- package/dist/presentation/queries-cli/path.js.map +1 -1
- package/dist/presentation/result-formatter.d.ts +10 -0
- package/dist/presentation/result-formatter.d.ts.map +1 -1
- package/dist/presentation/result-formatter.js +16 -1
- package/dist/presentation/result-formatter.js.map +1 -1
- package/dist/presentation/viewer.d.ts.map +1 -1
- package/dist/presentation/viewer.js +18 -12
- package/dist/presentation/viewer.js.map +1 -1
- package/dist/shared/errors.d.ts +5 -0
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +5 -0
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/hierarchy.d.ts +8 -2
- package/dist/shared/hierarchy.d.ts.map +1 -1
- package/dist/shared/hierarchy.js +42 -1
- package/dist/shared/hierarchy.js.map +1 -1
- package/dist/shared/normalize.d.ts +6 -1
- package/dist/shared/normalize.d.ts.map +1 -1
- package/dist/shared/normalize.js +20 -12
- package/dist/shared/normalize.js.map +1 -1
- package/dist/shared/paginate.d.ts +0 -9
- package/dist/shared/paginate.d.ts.map +1 -1
- package/dist/shared/paginate.js +0 -15
- package/dist/shared/paginate.js.map +1 -1
- package/dist/types.d.ts +129 -3
- package/dist/types.d.ts.map +1 -1
- package/grammars/tree-sitter-clojure.wasm +0 -0
- package/grammars/tree-sitter-cuda.wasm +0 -0
- package/grammars/tree-sitter-erlang.wasm +0 -0
- package/grammars/tree-sitter-fsharp.wasm +0 -0
- package/grammars/tree-sitter-gleam.wasm +0 -0
- package/grammars/tree-sitter-groovy.wasm +0 -0
- package/grammars/tree-sitter-julia.wasm +0 -0
- package/grammars/tree-sitter-objc.wasm +0 -0
- package/grammars/tree-sitter-ocaml_interface.wasm +0 -0
- package/grammars/tree-sitter-r.wasm +0 -0
- package/grammars/tree-sitter-solidity.wasm +0 -0
- package/grammars/tree-sitter-verilog.wasm +0 -0
- package/package.json +18 -7
- package/src/ast-analysis/engine.ts +245 -42
- package/src/ast-analysis/metrics.ts +33 -11
- package/src/ast-analysis/rules/javascript.ts +0 -1
- package/src/ast-analysis/shared.ts +33 -24
- package/src/ast-analysis/visitor-utils.ts +52 -32
- package/src/ast-analysis/visitor.ts +132 -71
- package/src/ast-analysis/visitors/ast-store-visitor.ts +49 -119
- package/src/ast-analysis/visitors/complexity-visitor.ts +35 -40
- package/src/ast-analysis/visitors/dataflow-visitor.ts +87 -43
- package/src/cli/commands/ast.ts +2 -2
- package/src/cli/commands/watch.ts +16 -2
- package/src/db/connection.ts +29 -28
- package/src/db/query-builder.ts +15 -3
- package/src/db/repository/base.ts +20 -0
- package/src/db/repository/native-repository.ts +79 -1
- package/src/db/repository/nodes.ts +13 -8
- package/src/db/repository/sqlite-repository.ts +29 -0
- package/src/domain/analysis/brief.ts +15 -25
- package/src/domain/analysis/context.ts +17 -10
- package/src/domain/analysis/dependencies.ts +67 -76
- package/src/domain/analysis/fn-impact.ts +36 -43
- package/src/domain/analysis/implementations.ts +11 -17
- package/src/domain/analysis/module-map.ts +58 -92
- package/src/domain/analysis/query-helpers.ts +18 -1
- package/src/domain/graph/builder/pipeline.ts +366 -41
- package/src/domain/graph/builder/stages/build-edges.ts +162 -1
- package/src/domain/graph/builder/stages/collect-files.ts +18 -7
- package/src/domain/graph/builder/stages/detect-changes.ts +110 -56
- package/src/domain/graph/builder/stages/finalize.ts +41 -11
- package/src/domain/graph/builder/stages/insert-nodes.ts +75 -39
- package/src/domain/graph/builder/stages/resolve-imports.ts +122 -100
- package/src/domain/graph/cycles.ts +110 -23
- package/src/domain/graph/resolve.ts +1 -1
- package/src/domain/graph/watcher.ts +202 -96
- package/src/domain/parser.ts +122 -28
- package/src/domain/search/generator.ts +1 -1
- package/src/domain/search/models.ts +17 -4
- package/src/domain/search/search/hybrid.ts +69 -51
- package/src/extractors/clojure.ts +273 -0
- package/src/extractors/cuda.ts +316 -0
- package/src/extractors/erlang.ts +252 -0
- package/src/extractors/fsharp.ts +253 -0
- package/src/extractors/gleam.ts +246 -0
- package/src/extractors/go.ts +43 -33
- package/src/extractors/groovy.ts +332 -0
- package/src/extractors/helpers.ts +37 -23
- package/src/extractors/index.ts +11 -0
- package/src/extractors/java.ts +66 -47
- package/src/extractors/javascript.ts +45 -46
- package/src/extractors/julia.ts +318 -0
- package/src/extractors/kotlin.ts +84 -77
- package/src/extractors/objc.ts +431 -0
- package/src/extractors/ocaml.ts +78 -0
- package/src/extractors/python.ts +31 -25
- package/src/extractors/r.ts +253 -0
- package/src/extractors/rust.ts +37 -29
- package/src/extractors/solidity.ts +394 -0
- package/src/extractors/swift.ts +81 -80
- package/src/extractors/verilog.ts +315 -0
- package/src/extractors/zig.ts +58 -61
- package/src/features/ast.ts +131 -112
- package/src/features/audit.ts +8 -6
- package/src/features/branch-compare.ts +105 -79
- package/src/features/communities.ts +25 -10
- package/src/features/complexity.ts +171 -134
- package/src/features/dataflow.ts +165 -175
- package/src/features/flow.ts +129 -92
- package/src/features/structure-query.ts +79 -64
- package/src/graph/algorithms/bfs.ts +34 -0
- package/src/graph/algorithms/centrality.ts +30 -0
- package/src/graph/algorithms/leiden/optimiser.ts +99 -55
- package/src/graph/algorithms/leiden/partition.ts +359 -294
- package/src/graph/algorithms/louvain.ts +31 -4
- package/src/graph/algorithms/shortest-path.ts +20 -1
- package/src/graph/model.ts +6 -1
- package/src/infrastructure/config.ts +6 -4
- package/src/infrastructure/suppress.ts +47 -0
- package/src/mcp/server.ts +53 -37
- package/src/presentation/dataflow.ts +50 -44
- package/src/presentation/diff-impact-mermaid.ts +104 -62
- package/src/presentation/queries-cli/exports.ts +21 -13
- package/src/presentation/queries-cli/impact.ts +15 -13
- package/src/presentation/queries-cli/inspect.ts +100 -81
- package/src/presentation/queries-cli/overview.ts +26 -16
- package/src/presentation/queries-cli/path.ts +33 -25
- package/src/presentation/result-formatter.ts +19 -1
- package/src/presentation/viewer.ts +42 -14
- package/src/shared/errors.ts +6 -0
- package/src/shared/hierarchy.ts +50 -2
- package/src/shared/normalize.ts +31 -12
- package/src/shared/paginate.ts +0 -17
- package/src/types.ts +138 -3
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Call,
|
|
3
|
+
ExtractorOutput,
|
|
4
|
+
SubDeclaration,
|
|
5
|
+
TreeSitterNode,
|
|
6
|
+
TreeSitterTree,
|
|
7
|
+
} from '../types.js';
|
|
8
|
+
import {
|
|
9
|
+
extractModifierVisibility,
|
|
10
|
+
findChild,
|
|
11
|
+
findParentNode,
|
|
12
|
+
nodeEndLine,
|
|
13
|
+
stripQuotes,
|
|
14
|
+
} from './helpers.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Extract symbols from Solidity files.
|
|
18
|
+
*
|
|
19
|
+
* Solidity's tree-sitter grammar covers contracts, interfaces, libraries,
|
|
20
|
+
* structs, enums, events, errors, functions, modifiers, and import paths.
|
|
21
|
+
*/
|
|
22
|
+
export function extractSoliditySymbols(tree: TreeSitterTree, _filePath: string): ExtractorOutput {
|
|
23
|
+
const ctx: ExtractorOutput = {
|
|
24
|
+
definitions: [],
|
|
25
|
+
calls: [],
|
|
26
|
+
imports: [],
|
|
27
|
+
classes: [],
|
|
28
|
+
exports: [],
|
|
29
|
+
typeMap: new Map(),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
walkSolidityNode(tree.rootNode, ctx);
|
|
33
|
+
return ctx;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function walkSolidityNode(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
37
|
+
switch (node.type) {
|
|
38
|
+
case 'contract_declaration':
|
|
39
|
+
handleContractDecl(node, ctx, 'class');
|
|
40
|
+
break;
|
|
41
|
+
case 'interface_declaration':
|
|
42
|
+
handleContractDecl(node, ctx, 'interface');
|
|
43
|
+
break;
|
|
44
|
+
case 'library_declaration':
|
|
45
|
+
handleContractDecl(node, ctx, 'module');
|
|
46
|
+
break;
|
|
47
|
+
case 'struct_declaration':
|
|
48
|
+
handleStructDecl(node, ctx);
|
|
49
|
+
break;
|
|
50
|
+
case 'enum_declaration':
|
|
51
|
+
handleEnumDecl(node, ctx);
|
|
52
|
+
break;
|
|
53
|
+
case 'function_definition':
|
|
54
|
+
handleFunctionDef(node, ctx);
|
|
55
|
+
break;
|
|
56
|
+
case 'modifier_definition':
|
|
57
|
+
handleModifierDef(node, ctx);
|
|
58
|
+
break;
|
|
59
|
+
case 'event_definition':
|
|
60
|
+
handleEventDef(node, ctx);
|
|
61
|
+
break;
|
|
62
|
+
case 'error_declaration':
|
|
63
|
+
handleErrorDecl(node, ctx);
|
|
64
|
+
break;
|
|
65
|
+
case 'state_variable_declaration':
|
|
66
|
+
handleStateVarDecl(node, ctx);
|
|
67
|
+
break;
|
|
68
|
+
case 'import_directive':
|
|
69
|
+
handleImportDirective(node, ctx);
|
|
70
|
+
break;
|
|
71
|
+
case 'call_expression':
|
|
72
|
+
case 'function_call':
|
|
73
|
+
handleCallExpression(node, ctx);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
78
|
+
const child = node.child(i);
|
|
79
|
+
if (child) walkSolidityNode(child, ctx);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ── Handlers ───────────────────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
const SOL_PARENT_TYPES = [
|
|
86
|
+
'contract_declaration',
|
|
87
|
+
'interface_declaration',
|
|
88
|
+
'library_declaration',
|
|
89
|
+
] as const;
|
|
90
|
+
|
|
91
|
+
function handleContractDecl(
|
|
92
|
+
node: TreeSitterNode,
|
|
93
|
+
ctx: ExtractorOutput,
|
|
94
|
+
kind: 'class' | 'interface' | 'module',
|
|
95
|
+
): void {
|
|
96
|
+
const nameNode = node.childForFieldName('name');
|
|
97
|
+
if (!nameNode) return;
|
|
98
|
+
const name = nameNode.text;
|
|
99
|
+
|
|
100
|
+
const body = node.childForFieldName('body') || findChild(node, 'contract_body');
|
|
101
|
+
const members = body ? extractContractMembers(body) : [];
|
|
102
|
+
|
|
103
|
+
ctx.definitions.push({
|
|
104
|
+
name,
|
|
105
|
+
kind,
|
|
106
|
+
line: node.startPosition.row + 1,
|
|
107
|
+
endLine: nodeEndLine(node),
|
|
108
|
+
children: members.length > 0 ? members : undefined,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
extractInheritance(node, name, ctx);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Extract member declarations from a contract body node. */
|
|
115
|
+
function extractContractMembers(body: TreeSitterNode): SubDeclaration[] {
|
|
116
|
+
const members: SubDeclaration[] = [];
|
|
117
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
118
|
+
const child = body.child(i);
|
|
119
|
+
if (!child) continue;
|
|
120
|
+
const member = extractContractMember(child);
|
|
121
|
+
if (member) members.push(member);
|
|
122
|
+
}
|
|
123
|
+
return members;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Map a single contract body child to a SubDeclaration, or null if not a recognized member. */
|
|
127
|
+
function extractContractMember(child: TreeSitterNode): SubDeclaration | null {
|
|
128
|
+
const line = child.startPosition.row + 1;
|
|
129
|
+
switch (child.type) {
|
|
130
|
+
case 'function_definition': {
|
|
131
|
+
const fnName = child.childForFieldName('name');
|
|
132
|
+
return fnName ? { name: fnName.text, kind: 'method', line } : null;
|
|
133
|
+
}
|
|
134
|
+
case 'state_variable_declaration': {
|
|
135
|
+
const varName = child.childForFieldName('name');
|
|
136
|
+
return varName
|
|
137
|
+
? { name: varName.text, kind: 'property', line, visibility: extractSolVisibility(child) }
|
|
138
|
+
: null;
|
|
139
|
+
}
|
|
140
|
+
case 'event_definition': {
|
|
141
|
+
const evName = child.childForFieldName('name');
|
|
142
|
+
return evName ? { name: evName.text, kind: 'property', decorators: ['event'], line } : null;
|
|
143
|
+
}
|
|
144
|
+
case 'error_declaration': {
|
|
145
|
+
const errName = child.childForFieldName('name');
|
|
146
|
+
return errName ? { name: errName.text, kind: 'property', decorators: ['error'], line } : null;
|
|
147
|
+
}
|
|
148
|
+
case 'modifier_definition': {
|
|
149
|
+
const modName = child.childForFieldName('name');
|
|
150
|
+
return modName
|
|
151
|
+
? { name: modName.text, kind: 'method', decorators: ['modifier'], line }
|
|
152
|
+
: null;
|
|
153
|
+
}
|
|
154
|
+
default:
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Extract inheritance (extends) relationships from a contract node. */
|
|
160
|
+
function extractInheritance(node: TreeSitterNode, name: string, ctx: ExtractorOutput): void {
|
|
161
|
+
const inheritance = findChild(node, 'inheritance_specifier');
|
|
162
|
+
if (!inheritance) return;
|
|
163
|
+
for (let i = 0; i < inheritance.childCount; i++) {
|
|
164
|
+
const child = inheritance.child(i);
|
|
165
|
+
if (!child) continue;
|
|
166
|
+
if (child.type === 'user_defined_type' || child.type === 'identifier') {
|
|
167
|
+
ctx.classes.push({ name, extends: child.text, line: node.startPosition.row + 1 });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function handleStructDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
173
|
+
const nameNode = node.childForFieldName('name');
|
|
174
|
+
if (!nameNode) return;
|
|
175
|
+
|
|
176
|
+
const members: SubDeclaration[] = [];
|
|
177
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
178
|
+
const child = node.child(i);
|
|
179
|
+
if (child && child.type === 'struct_member') {
|
|
180
|
+
const memberName = child.childForFieldName('name');
|
|
181
|
+
if (memberName) {
|
|
182
|
+
members.push({
|
|
183
|
+
name: memberName.text,
|
|
184
|
+
kind: 'property',
|
|
185
|
+
line: child.startPosition.row + 1,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const parent = findParentNode(node, SOL_PARENT_TYPES);
|
|
192
|
+
const fullName = parent ? `${parent}.${nameNode.text}` : nameNode.text;
|
|
193
|
+
|
|
194
|
+
ctx.definitions.push({
|
|
195
|
+
name: fullName,
|
|
196
|
+
kind: 'struct',
|
|
197
|
+
line: node.startPosition.row + 1,
|
|
198
|
+
endLine: nodeEndLine(node),
|
|
199
|
+
children: members.length > 0 ? members : undefined,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function handleEnumDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
204
|
+
const nameNode = node.childForFieldName('name');
|
|
205
|
+
if (!nameNode) return;
|
|
206
|
+
|
|
207
|
+
const members: SubDeclaration[] = [];
|
|
208
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
209
|
+
const child = node.child(i);
|
|
210
|
+
if (child && child.type === 'enum_value') {
|
|
211
|
+
members.push({ name: child.text, kind: 'constant', line: child.startPosition.row + 1 });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const parent = findParentNode(node, SOL_PARENT_TYPES);
|
|
216
|
+
const fullName = parent ? `${parent}.${nameNode.text}` : nameNode.text;
|
|
217
|
+
|
|
218
|
+
ctx.definitions.push({
|
|
219
|
+
name: fullName,
|
|
220
|
+
kind: 'enum',
|
|
221
|
+
line: node.startPosition.row + 1,
|
|
222
|
+
endLine: nodeEndLine(node),
|
|
223
|
+
children: members.length > 0 ? members : undefined,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function handleFunctionDef(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
228
|
+
const nameNode = node.childForFieldName('name');
|
|
229
|
+
if (!nameNode) return;
|
|
230
|
+
const parent = findParentNode(node, SOL_PARENT_TYPES);
|
|
231
|
+
const fullName = parent ? `${parent}.${nameNode.text}` : nameNode.text;
|
|
232
|
+
const kind = parent ? 'method' : 'function';
|
|
233
|
+
|
|
234
|
+
const params = extractSolParams(node);
|
|
235
|
+
ctx.definitions.push({
|
|
236
|
+
name: fullName,
|
|
237
|
+
kind,
|
|
238
|
+
line: node.startPosition.row + 1,
|
|
239
|
+
endLine: nodeEndLine(node),
|
|
240
|
+
children: params.length > 0 ? params : undefined,
|
|
241
|
+
visibility: extractSolVisibility(node),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function handleModifierDef(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
246
|
+
const nameNode = node.childForFieldName('name');
|
|
247
|
+
if (!nameNode) return;
|
|
248
|
+
const parent = findParentNode(node, SOL_PARENT_TYPES);
|
|
249
|
+
const fullName = parent ? `${parent}.${nameNode.text}` : nameNode.text;
|
|
250
|
+
|
|
251
|
+
ctx.definitions.push({
|
|
252
|
+
name: fullName,
|
|
253
|
+
kind: 'function',
|
|
254
|
+
line: node.startPosition.row + 1,
|
|
255
|
+
endLine: nodeEndLine(node),
|
|
256
|
+
decorators: ['modifier'],
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleEventDef(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
261
|
+
const nameNode = node.childForFieldName('name');
|
|
262
|
+
if (!nameNode) return;
|
|
263
|
+
const parent = findParentNode(node, SOL_PARENT_TYPES);
|
|
264
|
+
const fullName = parent ? `${parent}.${nameNode.text}` : nameNode.text;
|
|
265
|
+
|
|
266
|
+
ctx.definitions.push({
|
|
267
|
+
name: fullName,
|
|
268
|
+
kind: 'type',
|
|
269
|
+
line: node.startPosition.row + 1,
|
|
270
|
+
endLine: nodeEndLine(node),
|
|
271
|
+
decorators: ['event'],
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function handleErrorDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
276
|
+
const nameNode = node.childForFieldName('name');
|
|
277
|
+
if (!nameNode) return;
|
|
278
|
+
const parent = findParentNode(node, SOL_PARENT_TYPES);
|
|
279
|
+
const fullName = parent ? `${parent}.${nameNode.text}` : nameNode.text;
|
|
280
|
+
|
|
281
|
+
ctx.definitions.push({
|
|
282
|
+
name: fullName,
|
|
283
|
+
kind: 'type',
|
|
284
|
+
line: node.startPosition.row + 1,
|
|
285
|
+
endLine: nodeEndLine(node),
|
|
286
|
+
decorators: ['error'],
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function handleStateVarDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
291
|
+
const nameNode = node.childForFieldName('name');
|
|
292
|
+
if (!nameNode) return;
|
|
293
|
+
const parent = findParentNode(node, SOL_PARENT_TYPES);
|
|
294
|
+
const fullName = parent ? `${parent}.${nameNode.text}` : nameNode.text;
|
|
295
|
+
|
|
296
|
+
ctx.definitions.push({
|
|
297
|
+
name: fullName,
|
|
298
|
+
kind: 'variable',
|
|
299
|
+
line: node.startPosition.row + 1,
|
|
300
|
+
endLine: nodeEndLine(node),
|
|
301
|
+
visibility: extractSolVisibility(node),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function handleImportDirective(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
306
|
+
// import "path"; or import { X } from "path"; or import "path" as Alias;
|
|
307
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
308
|
+
const child = node.child(i);
|
|
309
|
+
if (!child) continue;
|
|
310
|
+
if (child.type === 'string' || child.type === 'string_literal') {
|
|
311
|
+
const source = stripQuotes(child.text);
|
|
312
|
+
const names: string[] = [];
|
|
313
|
+
// Look for imported symbols
|
|
314
|
+
for (let j = 0; j < node.childCount; j++) {
|
|
315
|
+
const sibling = node.child(j);
|
|
316
|
+
if (sibling && sibling.type === 'identifier') names.push(sibling.text);
|
|
317
|
+
if (sibling && sibling.type === 'import_declaration') {
|
|
318
|
+
const id = findChild(sibling, 'identifier');
|
|
319
|
+
if (id) names.push(id.text);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
ctx.imports.push({
|
|
323
|
+
source,
|
|
324
|
+
names: names.length > 0 ? names : ['*'],
|
|
325
|
+
line: node.startPosition.row + 1,
|
|
326
|
+
});
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
// source_import: handles `import * as X from "path"`
|
|
330
|
+
if (child.type === 'source_import' || child.type === 'import_clause') {
|
|
331
|
+
const strNode = findChild(child, 'string') || findChild(child, 'string_literal');
|
|
332
|
+
if (strNode) {
|
|
333
|
+
ctx.imports.push({
|
|
334
|
+
source: stripQuotes(strNode.text),
|
|
335
|
+
names: ['*'],
|
|
336
|
+
line: node.startPosition.row + 1,
|
|
337
|
+
});
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function handleCallExpression(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
345
|
+
const funcNode = node.childForFieldName('function') || node.childForFieldName('callee');
|
|
346
|
+
if (!funcNode) return;
|
|
347
|
+
|
|
348
|
+
const call: Call = { name: '', line: node.startPosition.row + 1 };
|
|
349
|
+
if (funcNode.type === 'member_expression' || funcNode.type === 'member_access') {
|
|
350
|
+
const prop = funcNode.childForFieldName('property') || funcNode.childForFieldName('member');
|
|
351
|
+
const obj = funcNode.childForFieldName('object') || funcNode.childForFieldName('expression');
|
|
352
|
+
if (prop) call.name = prop.text;
|
|
353
|
+
if (obj) call.receiver = obj.text;
|
|
354
|
+
} else {
|
|
355
|
+
call.name = funcNode.text;
|
|
356
|
+
}
|
|
357
|
+
if (call.name) ctx.calls.push(call);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
361
|
+
|
|
362
|
+
function extractSolParams(funcNode: TreeSitterNode): SubDeclaration[] {
|
|
363
|
+
const params: SubDeclaration[] = [];
|
|
364
|
+
const paramList =
|
|
365
|
+
funcNode.childForFieldName('parameters') || findChild(funcNode, 'parameter_list');
|
|
366
|
+
if (!paramList) return params;
|
|
367
|
+
|
|
368
|
+
for (let i = 0; i < paramList.childCount; i++) {
|
|
369
|
+
const param = paramList.child(i);
|
|
370
|
+
if (!param || param.type !== 'parameter') continue;
|
|
371
|
+
const nameNode = param.childForFieldName('name');
|
|
372
|
+
if (nameNode) {
|
|
373
|
+
params.push({ name: nameNode.text, kind: 'parameter', line: param.startPosition.row + 1 });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return params;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function extractSolVisibility(
|
|
380
|
+
node: TreeSitterNode,
|
|
381
|
+
): 'public' | 'private' | 'protected' | undefined {
|
|
382
|
+
// Solidity visibility is embedded as child keywords or visibility nodes
|
|
383
|
+
const vis = extractModifierVisibility(node);
|
|
384
|
+
if (vis) return vis;
|
|
385
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
386
|
+
const child = node.child(i);
|
|
387
|
+
if (!child) continue;
|
|
388
|
+
const t = child.text;
|
|
389
|
+
if (t === 'public' || t === 'external') return 'public';
|
|
390
|
+
if (t === 'private') return 'private';
|
|
391
|
+
if (t === 'internal') return 'protected';
|
|
392
|
+
}
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
package/src/extractors/swift.ts
CHANGED
|
@@ -73,49 +73,7 @@ function handleSwiftClassDecl(node: TreeSitterNode, ctx: ExtractorOutput): void
|
|
|
73
73
|
|
|
74
74
|
const kind = isEnum ? 'enum' : isStruct ? 'struct' : 'class';
|
|
75
75
|
|
|
76
|
-
const children
|
|
77
|
-
|
|
78
|
-
if (isEnum) {
|
|
79
|
-
// Enum cases: enum_entry > simple_identifier, inside enum_class_body
|
|
80
|
-
const body = findChild(node, 'enum_class_body');
|
|
81
|
-
if (body) {
|
|
82
|
-
for (let i = 0; i < body.childCount; i++) {
|
|
83
|
-
const child = body.child(i);
|
|
84
|
-
if (child && child.type === 'enum_entry') {
|
|
85
|
-
const entryName = findChild(child, 'simple_identifier');
|
|
86
|
-
if (entryName) {
|
|
87
|
-
children.push({
|
|
88
|
-
name: entryName.text,
|
|
89
|
-
kind: 'constant',
|
|
90
|
-
line: child.startPosition.row + 1,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
// Extract properties from class_body
|
|
98
|
-
const body = findChild(node, 'class_body');
|
|
99
|
-
if (body) {
|
|
100
|
-
for (let i = 0; i < body.childCount; i++) {
|
|
101
|
-
const child = body.child(i);
|
|
102
|
-
if (child && child.type === 'property_declaration') {
|
|
103
|
-
const pattern = findChild(child, 'pattern');
|
|
104
|
-
if (pattern) {
|
|
105
|
-
const propName = findChild(pattern, 'simple_identifier');
|
|
106
|
-
if (propName) {
|
|
107
|
-
children.push({
|
|
108
|
-
name: propName.text,
|
|
109
|
-
kind: 'property',
|
|
110
|
-
line: child.startPosition.row + 1,
|
|
111
|
-
visibility: extractModifierVisibility(child),
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
76
|
+
const children = isEnum ? collectSwiftEnumEntries(node) : collectSwiftProperties(node);
|
|
119
77
|
|
|
120
78
|
ctx.definitions.push({
|
|
121
79
|
name,
|
|
@@ -125,52 +83,95 @@ function handleSwiftClassDecl(node: TreeSitterNode, ctx: ExtractorOutput): void
|
|
|
125
83
|
children: children.length > 0 ? children : undefined,
|
|
126
84
|
});
|
|
127
85
|
|
|
128
|
-
|
|
86
|
+
collectSwiftMethods(node, name, ctx);
|
|
87
|
+
collectSwiftInheritance(node, name, ctx);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Collect enum constant entries from an enum_class_body. */
|
|
91
|
+
function collectSwiftEnumEntries(node: TreeSitterNode): SubDeclaration[] {
|
|
92
|
+
const entries: SubDeclaration[] = [];
|
|
93
|
+
const body = findChild(node, 'enum_class_body');
|
|
94
|
+
if (!body) return entries;
|
|
95
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
96
|
+
const child = body.child(i);
|
|
97
|
+
if (!child || child.type !== 'enum_entry') continue;
|
|
98
|
+
const entryName = findChild(child, 'simple_identifier');
|
|
99
|
+
if (entryName) {
|
|
100
|
+
entries.push({
|
|
101
|
+
name: entryName.text,
|
|
102
|
+
kind: 'constant',
|
|
103
|
+
line: child.startPosition.row + 1,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return entries;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Collect property declarations from a class_body. */
|
|
111
|
+
function collectSwiftProperties(node: TreeSitterNode): SubDeclaration[] {
|
|
112
|
+
const props: SubDeclaration[] = [];
|
|
113
|
+
const body = findChild(node, 'class_body');
|
|
114
|
+
if (!body) return props;
|
|
115
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
116
|
+
const child = body.child(i);
|
|
117
|
+
if (!child || child.type !== 'property_declaration') continue;
|
|
118
|
+
const pattern = findChild(child, 'pattern');
|
|
119
|
+
if (!pattern) continue;
|
|
120
|
+
const propName = findChild(pattern, 'simple_identifier');
|
|
121
|
+
if (propName) {
|
|
122
|
+
props.push({
|
|
123
|
+
name: propName.text,
|
|
124
|
+
kind: 'property',
|
|
125
|
+
line: child.startPosition.row + 1,
|
|
126
|
+
visibility: extractModifierVisibility(child),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return props;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Collect method declarations from class_body or enum_class_body. */
|
|
134
|
+
function collectSwiftMethods(node: TreeSitterNode, className: string, ctx: ExtractorOutput): void {
|
|
129
135
|
const body = findChild(node, 'class_body') || findChild(node, 'enum_class_body');
|
|
130
|
-
if (body)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
}
|
|
136
|
+
if (!body) return;
|
|
137
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
138
|
+
const child = body.child(i);
|
|
139
|
+
if (!child || child.type !== 'function_declaration') continue;
|
|
140
|
+
const methName = findChild(child, 'simple_identifier');
|
|
141
|
+
if (methName) {
|
|
142
|
+
ctx.definitions.push({
|
|
143
|
+
name: `${className}.${methName.text}`,
|
|
144
|
+
kind: 'method',
|
|
145
|
+
line: child.startPosition.row + 1,
|
|
146
|
+
endLine: child.endPosition.row + 1,
|
|
147
|
+
visibility: extractModifierVisibility(child),
|
|
148
|
+
});
|
|
145
149
|
}
|
|
146
150
|
}
|
|
151
|
+
}
|
|
147
152
|
|
|
148
|
-
|
|
149
|
-
|
|
153
|
+
/** Collect inheritance from inheritance_specifier children. First = extends, rest = implements. */
|
|
154
|
+
function collectSwiftInheritance(
|
|
155
|
+
node: TreeSitterNode,
|
|
156
|
+
className: string,
|
|
157
|
+
ctx: ExtractorOutput,
|
|
158
|
+
): void {
|
|
150
159
|
let first = true;
|
|
151
160
|
for (let i = 0; i < node.childCount; i++) {
|
|
152
161
|
const child = node.child(i);
|
|
153
162
|
if (!child || child.type !== 'inheritance_specifier') continue;
|
|
154
|
-
// inheritance_specifier > user_type > type_identifier
|
|
155
163
|
const userType = findChild(child, 'user_type');
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
ctx.classes.push({
|
|
168
|
-
name,
|
|
169
|
-
implements: typeId.text,
|
|
170
|
-
line: node.startPosition.row + 1,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
164
|
+
const typeId = userType ? findChild(userType, 'type_identifier') : null;
|
|
165
|
+
if (!typeId) continue;
|
|
166
|
+
if (first) {
|
|
167
|
+
ctx.classes.push({ name: className, extends: typeId.text, line: node.startPosition.row + 1 });
|
|
168
|
+
first = false;
|
|
169
|
+
} else {
|
|
170
|
+
ctx.classes.push({
|
|
171
|
+
name: className,
|
|
172
|
+
implements: typeId.text,
|
|
173
|
+
line: node.startPosition.row + 1,
|
|
174
|
+
});
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
}
|