@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,253 @@
|
|
|
1
|
+
import type { ExtractorOutput, SubDeclaration, TreeSitterNode, TreeSitterTree } from '../types.js';
|
|
2
|
+
import { findChild, nodeEndLine } from './helpers.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extract symbols from R files.
|
|
6
|
+
*
|
|
7
|
+
* tree-sitter-r grammar (r-lib/tree-sitter-r) notes:
|
|
8
|
+
* - Assignments: binary_operator with `<-` or `=` operator
|
|
9
|
+
* - Functions: function_definition as RHS of assignment
|
|
10
|
+
* - Calls: call node with function/arguments fields
|
|
11
|
+
* - Imports: library() and require() calls
|
|
12
|
+
* - S4 classes: setClass(), setRefClass()
|
|
13
|
+
*/
|
|
14
|
+
export function extractRSymbols(tree: TreeSitterTree, _filePath: string): ExtractorOutput {
|
|
15
|
+
const ctx: ExtractorOutput = {
|
|
16
|
+
definitions: [],
|
|
17
|
+
calls: [],
|
|
18
|
+
imports: [],
|
|
19
|
+
classes: [],
|
|
20
|
+
exports: [],
|
|
21
|
+
typeMap: new Map(),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
walkRNode(tree.rootNode, ctx);
|
|
25
|
+
return ctx;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function walkRNode(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
29
|
+
switch (node.type) {
|
|
30
|
+
case 'binary_operator':
|
|
31
|
+
handleBinaryOp(node, ctx);
|
|
32
|
+
break;
|
|
33
|
+
case 'call':
|
|
34
|
+
handleCall(node, ctx);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
39
|
+
const child = node.child(i);
|
|
40
|
+
if (child) walkRNode(child, ctx);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function handleBinaryOp(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
45
|
+
// binary_operator: child[0]=LHS, child[1]=operator (<- or =), child[2]=RHS
|
|
46
|
+
if (node.childCount < 3) return;
|
|
47
|
+
|
|
48
|
+
const lhs = node.child(0);
|
|
49
|
+
const op = node.child(1);
|
|
50
|
+
const rhs = node.child(2);
|
|
51
|
+
|
|
52
|
+
if (!lhs || !op || !rhs) return;
|
|
53
|
+
if (op.text !== '<-' && op.text !== '=' && op.text !== '<<-') return;
|
|
54
|
+
if (lhs.type !== 'identifier') return;
|
|
55
|
+
|
|
56
|
+
if (rhs.type === 'function_definition') {
|
|
57
|
+
const params = extractRParams(rhs);
|
|
58
|
+
ctx.definitions.push({
|
|
59
|
+
name: lhs.text,
|
|
60
|
+
kind: 'function',
|
|
61
|
+
line: node.startPosition.row + 1,
|
|
62
|
+
endLine: nodeEndLine(node),
|
|
63
|
+
children: params.length > 0 ? params : undefined,
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
// Variable assignment — only record top-level
|
|
67
|
+
if (node.parent?.type === 'program') {
|
|
68
|
+
ctx.definitions.push({
|
|
69
|
+
name: lhs.text,
|
|
70
|
+
kind: 'variable',
|
|
71
|
+
line: node.startPosition.row + 1,
|
|
72
|
+
endLine: nodeEndLine(node),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function extractRParams(funcDef: TreeSitterNode): SubDeclaration[] {
|
|
79
|
+
const params: SubDeclaration[] = [];
|
|
80
|
+
const paramsNode = findChild(funcDef, 'parameters');
|
|
81
|
+
if (!paramsNode) return params;
|
|
82
|
+
|
|
83
|
+
for (let i = 0; i < paramsNode.childCount; i++) {
|
|
84
|
+
const child = paramsNode.child(i);
|
|
85
|
+
if (!child) continue;
|
|
86
|
+
if (child.type === 'parameter') {
|
|
87
|
+
// parameter node has name and possibly default value
|
|
88
|
+
const nameNode = child.childForFieldName('name') || findChild(child, 'identifier');
|
|
89
|
+
if (nameNode) {
|
|
90
|
+
params.push({ name: nameNode.text, kind: 'parameter', line: child.startPosition.row + 1 });
|
|
91
|
+
} else if (child.text && child.text !== ',' && child.text !== '(' && child.text !== ')') {
|
|
92
|
+
// Some grammars have the param as plain text
|
|
93
|
+
params.push({ name: child.text, kind: 'parameter', line: child.startPosition.row + 1 });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (child.type === 'identifier') {
|
|
97
|
+
params.push({ name: child.text, kind: 'parameter', line: child.startPosition.row + 1 });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return params;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handleCall(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
104
|
+
// call: child[0]=function, then arguments
|
|
105
|
+
const funcNode = node.child(0);
|
|
106
|
+
if (!funcNode) return;
|
|
107
|
+
|
|
108
|
+
const funcName = funcNode.text;
|
|
109
|
+
|
|
110
|
+
// library() and require() are imports
|
|
111
|
+
if (funcName === 'library' || funcName === 'require') {
|
|
112
|
+
handleLibraryCall(node, ctx);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// source() is a file import
|
|
117
|
+
if (funcName === 'source') {
|
|
118
|
+
handleSourceCall(node, ctx);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// setClass / setRefClass for S4
|
|
123
|
+
if (funcName === 'setClass' || funcName === 'setRefClass') {
|
|
124
|
+
handleSetClass(node, ctx);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (funcName === 'setGeneric' || funcName === 'setMethod') {
|
|
129
|
+
handleSetGeneric(node, ctx);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Regular call
|
|
134
|
+
if (funcNode.type === 'identifier') {
|
|
135
|
+
ctx.calls.push({ name: funcName, line: node.startPosition.row + 1 });
|
|
136
|
+
} else if (funcNode.type === 'namespace_operator') {
|
|
137
|
+
// pkg::func
|
|
138
|
+
const parts = funcName.split('::');
|
|
139
|
+
if (parts.length >= 2) {
|
|
140
|
+
ctx.calls.push({
|
|
141
|
+
name: parts[parts.length - 1]!,
|
|
142
|
+
receiver: parts.slice(0, -1).join('::'),
|
|
143
|
+
line: node.startPosition.row + 1,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function handleLibraryCall(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
150
|
+
// Find the package name in arguments
|
|
151
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
152
|
+
const child = node.child(i);
|
|
153
|
+
if (!child) continue;
|
|
154
|
+
if (child.type === 'arguments') {
|
|
155
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
156
|
+
const arg = child.child(j);
|
|
157
|
+
if (!arg) continue;
|
|
158
|
+
if (arg.type === 'identifier') {
|
|
159
|
+
ctx.imports.push({
|
|
160
|
+
source: arg.text,
|
|
161
|
+
names: [arg.text],
|
|
162
|
+
line: node.startPosition.row + 1,
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (arg.type === 'string' || arg.type === 'string_content') {
|
|
167
|
+
const text = arg.text.replace(/^["']|["']$/g, '');
|
|
168
|
+
ctx.imports.push({
|
|
169
|
+
source: text,
|
|
170
|
+
names: [text],
|
|
171
|
+
line: node.startPosition.row + 1,
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// Argument might be wrapped
|
|
176
|
+
if (arg.type === 'argument') {
|
|
177
|
+
const id = findChild(arg, 'identifier') || findChild(arg, 'string');
|
|
178
|
+
if (id) {
|
|
179
|
+
const text = id.text.replace(/^["']|["']$/g, '');
|
|
180
|
+
ctx.imports.push({
|
|
181
|
+
source: text,
|
|
182
|
+
names: [text],
|
|
183
|
+
line: node.startPosition.row + 1,
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function handleSourceCall(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
194
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
195
|
+
const child = node.child(i);
|
|
196
|
+
if (!child || child.type !== 'arguments') continue;
|
|
197
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
198
|
+
const arg = child.child(j);
|
|
199
|
+
if (!arg) continue;
|
|
200
|
+
if (arg.type === 'string') {
|
|
201
|
+
const text = arg.text.replace(/^["']|["']$/g, '');
|
|
202
|
+
ctx.imports.push({
|
|
203
|
+
source: text,
|
|
204
|
+
names: ['source'],
|
|
205
|
+
line: node.startPosition.row + 1,
|
|
206
|
+
});
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function handleSetClass(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
214
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
215
|
+
const child = node.child(i);
|
|
216
|
+
if (!child || child.type !== 'arguments') continue;
|
|
217
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
218
|
+
const arg = child.child(j);
|
|
219
|
+
if (!arg) continue;
|
|
220
|
+
if (arg.type === 'string') {
|
|
221
|
+
const name = arg.text.replace(/^["']|["']$/g, '');
|
|
222
|
+
ctx.definitions.push({
|
|
223
|
+
name,
|
|
224
|
+
kind: 'class',
|
|
225
|
+
line: node.startPosition.row + 1,
|
|
226
|
+
endLine: nodeEndLine(node),
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function handleSetGeneric(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
235
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
236
|
+
const child = node.child(i);
|
|
237
|
+
if (!child || child.type !== 'arguments') continue;
|
|
238
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
239
|
+
const arg = child.child(j);
|
|
240
|
+
if (!arg) continue;
|
|
241
|
+
if (arg.type === 'string') {
|
|
242
|
+
const name = arg.text.replace(/^["']|["']$/g, '');
|
|
243
|
+
ctx.definitions.push({
|
|
244
|
+
name,
|
|
245
|
+
kind: 'function',
|
|
246
|
+
line: node.startPosition.row + 1,
|
|
247
|
+
endLine: nodeEndLine(node),
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
package/src/extractors/rust.ts
CHANGED
|
@@ -138,19 +138,22 @@ function handleRustTraitItem(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
|
138
138
|
endLine: nodeEndLine(node),
|
|
139
139
|
});
|
|
140
140
|
const body = node.childForFieldName('body');
|
|
141
|
-
if (body)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
141
|
+
if (body) extractTraitMethods(body, nameNode.text, ctx);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Extract method signatures/definitions from a trait body. */
|
|
145
|
+
function extractTraitMethods(body: TreeSitterNode, traitName: string, ctx: ExtractorOutput): void {
|
|
146
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
147
|
+
const child = body.child(i);
|
|
148
|
+
if (child && (child.type === 'function_signature_item' || child.type === 'function_item')) {
|
|
149
|
+
const methName = child.childForFieldName('name');
|
|
150
|
+
if (methName) {
|
|
151
|
+
ctx.definitions.push({
|
|
152
|
+
name: `${traitName}.${methName.text}`,
|
|
153
|
+
kind: 'method',
|
|
154
|
+
line: child.startPosition.row + 1,
|
|
155
|
+
endLine: child.endPosition.row + 1,
|
|
156
|
+
});
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
}
|
|
@@ -185,25 +188,30 @@ function handleRustUseDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
|
185
188
|
function handleRustCallExpr(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
186
189
|
const fn = node.childForFieldName('function');
|
|
187
190
|
if (!fn) return;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
+
const call = extractRustCallInfo(fn, node.startPosition.row + 1);
|
|
192
|
+
if (call) ctx.calls.push(call);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Extract call info from a Rust call function node. */
|
|
196
|
+
function extractRustCallInfo(fn: TreeSitterNode, line: number): Call | null {
|
|
197
|
+
if (fn.type === 'identifier') return { name: fn.text, line };
|
|
198
|
+
if (fn.type === 'field_expression') {
|
|
191
199
|
const field = fn.childForFieldName('field');
|
|
192
|
-
if (field)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
200
|
+
if (!field) return null;
|
|
201
|
+
const value = fn.childForFieldName('value');
|
|
202
|
+
const call: Call = { name: field.text, line };
|
|
203
|
+
if (value) call.receiver = value.text;
|
|
204
|
+
return call;
|
|
205
|
+
}
|
|
206
|
+
if (fn.type === 'scoped_identifier') {
|
|
199
207
|
const name = fn.childForFieldName('name');
|
|
200
|
-
if (name)
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
208
|
+
if (!name) return null;
|
|
209
|
+
const path = fn.childForFieldName('path');
|
|
210
|
+
const call: Call = { name: name.text, line };
|
|
211
|
+
if (path) call.receiver = path.text;
|
|
212
|
+
return call;
|
|
206
213
|
}
|
|
214
|
+
return null;
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
function handleRustMacroInvocation(node: TreeSitterNode, ctx: ExtractorOutput): void {
|