@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,315 @@
|
|
|
1
|
+
import type { ExtractorOutput, SubDeclaration, TreeSitterNode, TreeSitterTree } from '../types.js';
|
|
2
|
+
import { findChild, nodeEndLine } from './helpers.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extract symbols from Verilog/SystemVerilog files.
|
|
6
|
+
*
|
|
7
|
+
* The tree-sitter-verilog grammar covers modules, interfaces, packages,
|
|
8
|
+
* tasks, functions, classes, always blocks, and instantiations.
|
|
9
|
+
*/
|
|
10
|
+
export function extractVerilogSymbols(tree: TreeSitterTree, _filePath: string): ExtractorOutput {
|
|
11
|
+
const ctx: ExtractorOutput = {
|
|
12
|
+
definitions: [],
|
|
13
|
+
calls: [],
|
|
14
|
+
imports: [],
|
|
15
|
+
classes: [],
|
|
16
|
+
exports: [],
|
|
17
|
+
typeMap: new Map(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
walkVerilogNode(tree.rootNode, ctx);
|
|
21
|
+
return ctx;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function walkVerilogNode(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
25
|
+
switch (node.type) {
|
|
26
|
+
case 'module_declaration':
|
|
27
|
+
handleModuleDecl(node, ctx);
|
|
28
|
+
break;
|
|
29
|
+
case 'interface_declaration':
|
|
30
|
+
handleInterfaceDecl(node, ctx);
|
|
31
|
+
break;
|
|
32
|
+
case 'package_declaration':
|
|
33
|
+
handlePackageDecl(node, ctx);
|
|
34
|
+
break;
|
|
35
|
+
case 'class_declaration':
|
|
36
|
+
handleClassDecl(node, ctx);
|
|
37
|
+
break;
|
|
38
|
+
case 'function_declaration':
|
|
39
|
+
handleFunctionDecl(node, ctx);
|
|
40
|
+
break;
|
|
41
|
+
case 'task_declaration':
|
|
42
|
+
handleTaskDecl(node, ctx);
|
|
43
|
+
break;
|
|
44
|
+
case 'module_instantiation':
|
|
45
|
+
handleModuleInstantiation(node, ctx);
|
|
46
|
+
break;
|
|
47
|
+
case 'package_import_declaration':
|
|
48
|
+
handlePackageImport(node, ctx);
|
|
49
|
+
break;
|
|
50
|
+
case 'include_compiler_directive':
|
|
51
|
+
handleIncludeDirective(node, ctx);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
56
|
+
const child = node.child(i);
|
|
57
|
+
if (child) walkVerilogNode(child, ctx);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── Handlers ───────────────────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
function handleModuleDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
64
|
+
const nameNode = findModuleName(node);
|
|
65
|
+
if (!nameNode) return;
|
|
66
|
+
|
|
67
|
+
const ports = extractPorts(node);
|
|
68
|
+
ctx.definitions.push({
|
|
69
|
+
name: nameNode.text,
|
|
70
|
+
kind: 'module',
|
|
71
|
+
line: node.startPosition.row + 1,
|
|
72
|
+
endLine: nodeEndLine(node),
|
|
73
|
+
children: ports.length > 0 ? ports : undefined,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function handleInterfaceDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
78
|
+
const nameNode = findDeclName(node);
|
|
79
|
+
if (!nameNode) return;
|
|
80
|
+
|
|
81
|
+
ctx.definitions.push({
|
|
82
|
+
name: nameNode.text,
|
|
83
|
+
kind: 'interface',
|
|
84
|
+
line: node.startPosition.row + 1,
|
|
85
|
+
endLine: nodeEndLine(node),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function handlePackageDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
90
|
+
const nameNode = findDeclName(node);
|
|
91
|
+
if (!nameNode) return;
|
|
92
|
+
|
|
93
|
+
ctx.definitions.push({
|
|
94
|
+
name: nameNode.text,
|
|
95
|
+
kind: 'module',
|
|
96
|
+
line: node.startPosition.row + 1,
|
|
97
|
+
endLine: nodeEndLine(node),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function handleClassDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
102
|
+
const nameNode = node.childForFieldName('name');
|
|
103
|
+
if (!nameNode) return;
|
|
104
|
+
|
|
105
|
+
ctx.definitions.push({
|
|
106
|
+
name: nameNode.text,
|
|
107
|
+
kind: 'class',
|
|
108
|
+
line: node.startPosition.row + 1,
|
|
109
|
+
endLine: nodeEndLine(node),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Superclass via extends
|
|
113
|
+
const superclass = node.childForFieldName('superclass');
|
|
114
|
+
if (superclass) {
|
|
115
|
+
ctx.classes.push({
|
|
116
|
+
name: nameNode.text,
|
|
117
|
+
extends: superclass.text,
|
|
118
|
+
line: node.startPosition.row + 1,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function handleFunctionDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
124
|
+
const nameNode = findFunctionOrTaskName(node, 'function_identifier');
|
|
125
|
+
if (!nameNode) return;
|
|
126
|
+
|
|
127
|
+
const parentModule = findVerilogParent(node);
|
|
128
|
+
const fullName = parentModule ? `${parentModule}.${nameNode.text}` : nameNode.text;
|
|
129
|
+
|
|
130
|
+
ctx.definitions.push({
|
|
131
|
+
name: fullName,
|
|
132
|
+
kind: 'function',
|
|
133
|
+
line: node.startPosition.row + 1,
|
|
134
|
+
endLine: nodeEndLine(node),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function handleTaskDecl(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
139
|
+
const nameNode = findFunctionOrTaskName(node, 'task_identifier');
|
|
140
|
+
if (!nameNode) return;
|
|
141
|
+
|
|
142
|
+
const parentModule = findVerilogParent(node);
|
|
143
|
+
const fullName = parentModule ? `${parentModule}.${nameNode.text}` : nameNode.text;
|
|
144
|
+
|
|
145
|
+
ctx.definitions.push({
|
|
146
|
+
name: fullName,
|
|
147
|
+
kind: 'function',
|
|
148
|
+
line: node.startPosition.row + 1,
|
|
149
|
+
endLine: nodeEndLine(node),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function handleModuleInstantiation(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
154
|
+
// Module instantiations are like function calls: `ModuleName instance_name(...);`
|
|
155
|
+
const moduleType = node.childForFieldName('type') || node.child(0);
|
|
156
|
+
if (!moduleType) return;
|
|
157
|
+
|
|
158
|
+
ctx.calls.push({
|
|
159
|
+
name: moduleType.text,
|
|
160
|
+
line: node.startPosition.row + 1,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function handlePackageImport(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
165
|
+
// import pkg::item; or import pkg::*;
|
|
166
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
167
|
+
const child = node.child(i);
|
|
168
|
+
if (!child) continue;
|
|
169
|
+
if (child.type === 'package_import_item') {
|
|
170
|
+
const text = child.text;
|
|
171
|
+
const parts = text.split('::');
|
|
172
|
+
const pkg = parts[0] ?? text;
|
|
173
|
+
const item = parts[1] ?? '*';
|
|
174
|
+
ctx.imports.push({
|
|
175
|
+
source: pkg,
|
|
176
|
+
names: [item],
|
|
177
|
+
line: node.startPosition.row + 1,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function handleIncludeDirective(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
184
|
+
// `include "file.vh"
|
|
185
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
186
|
+
const child = node.child(i);
|
|
187
|
+
if (child && (child.type === 'string_literal' || child.type === 'quoted_string')) {
|
|
188
|
+
const source = child.text.replace(/^["']|["']$/g, '');
|
|
189
|
+
ctx.imports.push({
|
|
190
|
+
source,
|
|
191
|
+
names: [source.split('/').pop() ?? source],
|
|
192
|
+
line: node.startPosition.row + 1,
|
|
193
|
+
cInclude: true,
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
201
|
+
|
|
202
|
+
function findModuleName(node: TreeSitterNode): TreeSitterNode | null {
|
|
203
|
+
// Try field name first, then look for module_header > identifier
|
|
204
|
+
const nameNode = node.childForFieldName('name');
|
|
205
|
+
if (nameNode) return nameNode;
|
|
206
|
+
|
|
207
|
+
const header = findChild(node, 'module_header');
|
|
208
|
+
if (header) {
|
|
209
|
+
const id = findChild(header, 'simple_identifier') || findChild(header, 'identifier');
|
|
210
|
+
if (id) return id;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Direct child identifier after `module` keyword
|
|
214
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
215
|
+
const child = node.child(i);
|
|
216
|
+
if (child && (child.type === 'simple_identifier' || child.type === 'identifier')) return child;
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function findDeclName(node: TreeSitterNode): TreeSitterNode | null {
|
|
222
|
+
const nameNode = node.childForFieldName('name');
|
|
223
|
+
if (nameNode) return nameNode;
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
226
|
+
const child = node.child(i);
|
|
227
|
+
if (child && (child.type === 'simple_identifier' || child.type === 'identifier')) return child;
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Find a function or task name by searching for the dedicated identifier node
|
|
234
|
+
* type (e.g. `function_identifier`, `task_identifier`) recursively through
|
|
235
|
+
* body declarations. Falls back to `findDeclName` for grammars that use
|
|
236
|
+
* plain identifiers.
|
|
237
|
+
*/
|
|
238
|
+
function findFunctionOrTaskName(
|
|
239
|
+
node: TreeSitterNode,
|
|
240
|
+
identifierType: string,
|
|
241
|
+
): TreeSitterNode | null {
|
|
242
|
+
// Try the standard approach first
|
|
243
|
+
const simple = findDeclName(node);
|
|
244
|
+
if (simple) return simple;
|
|
245
|
+
|
|
246
|
+
// Search children (including body declarations) for the dedicated identifier node
|
|
247
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
248
|
+
const child = node.child(i);
|
|
249
|
+
if (!child) continue;
|
|
250
|
+
if (child.type === identifierType) return child;
|
|
251
|
+
// Look one level deeper into body declarations
|
|
252
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
253
|
+
const grandchild = child.child(j);
|
|
254
|
+
if (grandchild && grandchild.type === identifierType) return grandchild;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function findVerilogParent(node: TreeSitterNode): string | null {
|
|
261
|
+
let current = node.parent;
|
|
262
|
+
while (current) {
|
|
263
|
+
if (
|
|
264
|
+
current.type === 'module_declaration' ||
|
|
265
|
+
current.type === 'interface_declaration' ||
|
|
266
|
+
current.type === 'package_declaration' ||
|
|
267
|
+
current.type === 'class_declaration'
|
|
268
|
+
) {
|
|
269
|
+
const name = findDeclName(current) || findModuleName(current);
|
|
270
|
+
return name ? name.text : null;
|
|
271
|
+
}
|
|
272
|
+
current = current.parent;
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function extractPorts(moduleNode: TreeSitterNode): SubDeclaration[] {
|
|
278
|
+
const ports: SubDeclaration[] = [];
|
|
279
|
+
|
|
280
|
+
// Look for port declarations in the module header or body
|
|
281
|
+
const collectFromNode = (node: TreeSitterNode): void => {
|
|
282
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
283
|
+
const child = node.child(i);
|
|
284
|
+
if (!child) continue;
|
|
285
|
+
|
|
286
|
+
if (
|
|
287
|
+
child.type === 'ansi_port_declaration' ||
|
|
288
|
+
child.type === 'port_declaration' ||
|
|
289
|
+
child.type === 'input_declaration' ||
|
|
290
|
+
child.type === 'output_declaration' ||
|
|
291
|
+
child.type === 'inout_declaration'
|
|
292
|
+
) {
|
|
293
|
+
const nameNode =
|
|
294
|
+
child.childForFieldName('name') ||
|
|
295
|
+
findChild(child, 'simple_identifier') ||
|
|
296
|
+
findChild(child, 'identifier');
|
|
297
|
+
if (nameNode) {
|
|
298
|
+
ports.push({ name: nameNode.text, kind: 'property', line: child.startPosition.row + 1 });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Recurse into port list containers
|
|
303
|
+
if (
|
|
304
|
+
child.type === 'list_of_port_declarations' ||
|
|
305
|
+
child.type === 'module_header' ||
|
|
306
|
+
child.type === 'port_declaration_list'
|
|
307
|
+
) {
|
|
308
|
+
collectFromNode(child);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
collectFromNode(moduleNode);
|
|
314
|
+
return ports;
|
|
315
|
+
}
|
package/src/extractors/zig.ts
CHANGED
|
@@ -100,78 +100,75 @@ function handleZigVariable(node: TreeSitterNode, ctx: ExtractorOutput): void {
|
|
|
100
100
|
if (!nameNode) return;
|
|
101
101
|
const name = nameNode.text;
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
if (tryHandleZigContainerDecl(node, name, ctx)) return;
|
|
104
|
+
if (tryHandleZigImportDecl(node, name, ctx)) return;
|
|
105
|
+
|
|
106
|
+
// Regular constant/variable
|
|
107
|
+
const isConst = hasChildText(node, 'const');
|
|
108
|
+
ctx.definitions.push({
|
|
109
|
+
name,
|
|
110
|
+
kind: isConst ? 'constant' : 'variable',
|
|
111
|
+
line: node.startPosition.row + 1,
|
|
112
|
+
endLine: nodeEndLine(node),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Try to handle a variable_declaration as a struct/enum/union. Returns true if handled. */
|
|
117
|
+
function tryHandleZigContainerDecl(
|
|
118
|
+
node: TreeSitterNode,
|
|
119
|
+
name: string,
|
|
120
|
+
ctx: ExtractorOutput,
|
|
121
|
+
): boolean {
|
|
104
122
|
for (let i = 0; i < node.childCount; i++) {
|
|
105
123
|
const child = node.child(i);
|
|
106
124
|
if (!child) continue;
|
|
125
|
+
const containerKind = zigContainerKind(child.type);
|
|
126
|
+
if (!containerKind) continue;
|
|
107
127
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (child.type === 'enum_declaration') {
|
|
122
|
-
ctx.definitions.push({
|
|
123
|
-
name,
|
|
124
|
-
kind: 'enum',
|
|
125
|
-
line: node.startPosition.row + 1,
|
|
126
|
-
endLine: nodeEndLine(node),
|
|
127
|
-
visibility: isZigPub(node) ? 'public' : undefined,
|
|
128
|
-
});
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (child.type === 'union_declaration') {
|
|
132
|
-
ctx.definitions.push({
|
|
133
|
-
name,
|
|
134
|
-
kind: 'struct',
|
|
135
|
-
line: node.startPosition.row + 1,
|
|
136
|
-
endLine: nodeEndLine(node),
|
|
137
|
-
visibility: isZigPub(node) ? 'public' : undefined,
|
|
138
|
-
});
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
128
|
+
const members = child.type === 'struct_declaration' ? extractZigContainerFields(child) : [];
|
|
129
|
+
ctx.definitions.push({
|
|
130
|
+
name,
|
|
131
|
+
kind: containerKind,
|
|
132
|
+
line: node.startPosition.row + 1,
|
|
133
|
+
endLine: nodeEndLine(node),
|
|
134
|
+
children: members.length > 0 ? members : undefined,
|
|
135
|
+
visibility: isZigPub(node) ? 'public' : undefined,
|
|
136
|
+
});
|
|
137
|
+
if (child.type === 'struct_declaration') extractZigContainerMethods(child, name, ctx);
|
|
138
|
+
return true;
|
|
141
139
|
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
/** Map a Zig container node type to a definition kind, or undefined if not a container. */
|
|
144
|
+
function zigContainerKind(nodeType: string): 'struct' | 'enum' | undefined {
|
|
145
|
+
if (nodeType === 'struct_declaration' || nodeType === 'union_declaration') return 'struct';
|
|
146
|
+
if (nodeType === 'enum_declaration') return 'enum';
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Try to handle a variable_declaration as an @import. Returns true if handled. */
|
|
151
|
+
function tryHandleZigImportDecl(node: TreeSitterNode, name: string, ctx: ExtractorOutput): boolean {
|
|
144
152
|
for (let i = 0; i < node.childCount; i++) {
|
|
145
153
|
const child = node.child(i);
|
|
146
|
-
if (!child) continue;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (args) {
|
|
152
|
-
const strArg = findChild(args, 'string_literal') || findChild(args, 'string');
|
|
153
|
-
if (strArg) {
|
|
154
|
-
const source = strArg.text.replace(/^"|"$/g, '');
|
|
155
|
-
ctx.imports.push({
|
|
156
|
-
source,
|
|
157
|
-
names: [name],
|
|
158
|
-
line: node.startPosition.row + 1,
|
|
159
|
-
});
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
154
|
+
if (!child || child.type !== 'builtin_function') continue;
|
|
155
|
+
const source = extractZigImportSource(child);
|
|
156
|
+
if (source) {
|
|
157
|
+
ctx.imports.push({ source, names: [name], line: node.startPosition.row + 1 });
|
|
158
|
+
return true;
|
|
164
159
|
}
|
|
165
160
|
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
166
163
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
164
|
+
/** Extract the import source path from a builtin_function node if it is @import. */
|
|
165
|
+
function extractZigImportSource(builtinNode: TreeSitterNode): string | null {
|
|
166
|
+
const builtinId = findChild(builtinNode, 'builtin_identifier');
|
|
167
|
+
if (builtinId?.text !== '@import') return null;
|
|
168
|
+
const args = findChild(builtinNode, 'arguments');
|
|
169
|
+
if (!args) return null;
|
|
170
|
+
const strArg = findChild(args, 'string_literal') || findChild(args, 'string');
|
|
171
|
+
return strArg ? strArg.text.replace(/^"|"$/g, '') : null;
|
|
175
172
|
}
|
|
176
173
|
|
|
177
174
|
function extractZigContainerFields(container: TreeSitterNode): SubDeclaration[] {
|