weavatrix 0.3.14 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +132 -200
- package/bin/native/darwin-arm64/weavatrix +0 -0
- package/bin/native/darwin-x64/weavatrix +0 -0
- package/bin/native/linux-arm64/weavatrix +0 -0
- package/bin/native/linux-x64/weavatrix +0 -0
- package/bin/native/win32-arm64/weavatrix.exe +0 -0
- package/bin/native/win32-x64/weavatrix.exe +0 -0
- package/bin/resolve-binary.mjs +73 -0
- package/bin/run-native.mjs +26 -0
- package/bin/weavatrix-mcp.mjs +7 -6
- package/bin/weavatrix.mjs +5 -0
- package/package.json +10 -67
- package/server.json +38 -0
- package/skill/SKILL.md +62 -374
- package/skill/agents/openai.yaml +4 -0
- package/skill/references/tool-routing.md +45 -0
- package/SECURITY.md +0 -101
- package/docs/adr/0001-v0.3-offline-online-split.md +0 -60
- package/docs/agent-task-benchmark.md +0 -58
- package/docs/releases/v0.2.19.md +0 -33
- package/docs/releases/v0.3.0.md +0 -43
- package/docs/releases/v0.3.1.md +0 -30
- package/docs/releases/v0.3.10.md +0 -76
- package/docs/releases/v0.3.11.md +0 -55
- package/docs/releases/v0.3.12.md +0 -44
- package/docs/releases/v0.3.13.md +0 -34
- package/docs/releases/v0.3.14.md +0 -37
- package/docs/releases/v0.3.2.md +0 -15
- package/docs/releases/v0.3.3.md +0 -25
- package/docs/releases/v0.3.4.md +0 -40
- package/docs/releases/v0.3.5.md +0 -50
- package/docs/releases/v0.3.6.md +0 -44
- package/docs/releases/v0.3.7.md +0 -37
- package/docs/releases/v0.3.8.md +0 -21
- package/docs/releases/v0.3.9.md +0 -36
- package/scripts/run-agent-task-benchmark.mjs +0 -118
- package/src/analysis/allowed-test-runner.js +0 -70
- package/src/analysis/architecture/contract-graph.js +0 -119
- package/src/analysis/architecture/contract-schema.js +0 -110
- package/src/analysis/architecture/contract-storage.js +0 -35
- package/src/analysis/architecture/contract-verification.js +0 -168
- package/src/analysis/architecture-contract.js +0 -16
- package/src/analysis/audit-debt.js +0 -94
- package/src/analysis/audit-extensions.js +0 -60
- package/src/analysis/cargo-dependency-evidence.js +0 -108
- package/src/analysis/cargo-manifests.js +0 -81
- package/src/analysis/change-classification/diff-parser.js +0 -103
- package/src/analysis/change-classification/options.js +0 -40
- package/src/analysis/change-classification/symbol-classifier.js +0 -177
- package/src/analysis/change-classification.js +0 -188
- package/src/analysis/coverage-reports-tarpaulin.js +0 -112
- package/src/analysis/coverage-reports.js +0 -246
- package/src/analysis/cycle-route.js +0 -14
- package/src/analysis/data-flow-evidence.js +0 -114
- package/src/analysis/dead-check.js +0 -300
- package/src/analysis/dead-code-review/candidates.js +0 -194
- package/src/analysis/dead-code-review/policy.js +0 -23
- package/src/analysis/dead-code-review.js +0 -119
- package/src/analysis/dep-check-ecosystems.js +0 -205
- package/src/analysis/dep-check.js +0 -290
- package/src/analysis/dep-rules.js +0 -10
- package/src/analysis/dependency/conventions.js +0 -16
- package/src/analysis/dependency/scoped-dependencies.js +0 -51
- package/src/analysis/dependency/source-references.js +0 -21
- package/src/analysis/duplicate-groups.js +0 -104
- package/src/analysis/duplicates-worker.js +0 -11
- package/src/analysis/duplicates.compute.js +0 -269
- package/src/analysis/duplicates.js +0 -15
- package/src/analysis/duplicates.run.js +0 -52
- package/src/analysis/duplicates.tokenize.js +0 -199
- package/src/analysis/endpoints/common.js +0 -79
- package/src/analysis/endpoints/extract.js +0 -120
- package/src/analysis/endpoints/inventory.js +0 -84
- package/src/analysis/endpoints/mounts.js +0 -129
- package/src/analysis/endpoints-java.js +0 -260
- package/src/analysis/endpoints-rust.js +0 -124
- package/src/analysis/endpoints.js +0 -3
- package/src/analysis/findings.js +0 -70
- package/src/analysis/git-history/analytics.js +0 -177
- package/src/analysis/git-history/collector.js +0 -67
- package/src/analysis/git-history/options.js +0 -66
- package/src/analysis/git-history.js +0 -143
- package/src/analysis/git-ref-graph.js +0 -76
- package/src/analysis/go-dependency-evidence.js +0 -62
- package/src/analysis/graph-analysis.aggregate.js +0 -296
- package/src/analysis/graph-analysis.edges.js +0 -24
- package/src/analysis/graph-analysis.js +0 -7
- package/src/analysis/graph-analysis.refs.js +0 -202
- package/src/analysis/graph-analysis.summaries.js +0 -65
- package/src/analysis/health-capabilities.js +0 -83
- package/src/analysis/hot-path-review.js +0 -266
- package/src/analysis/http-contract-wrappers.js +0 -241
- package/src/analysis/http-contracts/analysis.js +0 -179
- package/src/analysis/http-contracts/client-call-detection.js +0 -82
- package/src/analysis/http-contracts/client-call-parser.js +0 -273
- package/src/analysis/http-contracts/graph-context.js +0 -143
- package/src/analysis/http-contracts/matching.js +0 -61
- package/src/analysis/http-contracts/shared.js +0 -85
- package/src/analysis/http-contracts.js +0 -6
- package/src/analysis/internal-audit/dependency-health.js +0 -113
- package/src/analysis/internal-audit/python-manifests.js +0 -78
- package/src/analysis/internal-audit/repo-files.js +0 -50
- package/src/analysis/internal-audit/supply-chain.js +0 -149
- package/src/analysis/internal-audit.collect.js +0 -213
- package/src/analysis/internal-audit.js +0 -9
- package/src/analysis/internal-audit.reach.js +0 -201
- package/src/analysis/internal-audit.run.js +0 -256
- package/src/analysis/java-source.js +0 -36
- package/src/analysis/jvm-artifact-index.js +0 -87
- package/src/analysis/jvm-dependency-evidence.js +0 -138
- package/src/analysis/jvm-manifests.js +0 -114
- package/src/analysis/manifests.js +0 -123
- package/src/analysis/package-reachability.js +0 -39
- package/src/analysis/source-complexity.ast.js +0 -97
- package/src/analysis/source-complexity.constants.js +0 -55
- package/src/analysis/source-complexity.js +0 -14
- package/src/analysis/source-complexity.report.js +0 -81
- package/src/analysis/source-complexity.walk.js +0 -228
- package/src/analysis/source-correctness/retry-patterns.js +0 -93
- package/src/analysis/source-correctness.js +0 -222
- package/src/analysis/static-test-reachability.js +0 -150
- package/src/analysis/structure/dependency-graph.js +0 -151
- package/src/analysis/structure/findings.js +0 -162
- package/src/analysis/task-retrieval.js +0 -107
- package/src/analysis/transport-contracts.js +0 -224
- package/src/analysis/transport-runtime-evidence.js +0 -155
- package/src/analysis-kit.mjs +0 -17
- package/src/bounds.js +0 -4
- package/src/build-graph.js +0 -209
- package/src/child-env.js +0 -7
- package/src/config.js +0 -5
- package/src/extension/local-services.mjs +0 -75
- package/src/git-exec.js +0 -67
- package/src/graph/build-worker.js +0 -49
- package/src/graph/builder/go-receiver-resolution.js +0 -112
- package/src/graph/builder/js/dynamic-import.js +0 -26
- package/src/graph/builder/js/queries.js +0 -48
- package/src/graph/builder/lang-csharp.js +0 -40
- package/src/graph/builder/lang-css.js +0 -29
- package/src/graph/builder/lang-go.js +0 -140
- package/src/graph/builder/lang-html.js +0 -29
- package/src/graph/builder/lang-java-calls.js +0 -142
- package/src/graph/builder/lang-java.js +0 -215
- package/src/graph/builder/lang-js.js +0 -291
- package/src/graph/builder/lang-python.js +0 -235
- package/src/graph/builder/lang-rust-calls.js +0 -63
- package/src/graph/builder/lang-rust.js +0 -299
- package/src/graph/builder/lang-solidity.js +0 -126
- package/src/graph/builder/lang-sql.js +0 -263
- package/src/graph/builder/pass2-resolution.js +0 -81
- package/src/graph/builder/spec-pkg.js +0 -87
- package/src/graph/community.js +0 -27
- package/src/graph/edge-provenance.js +0 -31
- package/src/graph/file-lock.js +0 -69
- package/src/graph/freshness-probe.js +0 -142
- package/src/graph/graph-filter.js +0 -63
- package/src/graph/incremental-refresh.js +0 -235
- package/src/graph/internal-builder.barrels.js +0 -235
- package/src/graph/internal-builder.build.js +0 -300
- package/src/graph/internal-builder.java.js +0 -33
- package/src/graph/internal-builder.js +0 -12
- package/src/graph/internal-builder.langs.js +0 -157
- package/src/graph/internal-builder.pass2.js +0 -163
- package/src/graph/internal-builder.resolvers.js +0 -286
- package/src/graph/layout.js +0 -51
- package/src/graph/node-id.js +0 -7
- package/src/graph/parser-artifact-boundary.js +0 -55
- package/src/graph/relations.js +0 -4
- package/src/graph/repo-registry.js +0 -124
- package/src/graph/resolvers/rust.js +0 -117
- package/src/infra/infra-items.js +0 -255
- package/src/infra/infra-registry.js +0 -184
- package/src/infra/infra.detect.js +0 -119
- package/src/infra/infra.js +0 -38
- package/src/infra/infra.match.js +0 -102
- package/src/infra/infra.scan.js +0 -93
- package/src/mcp/actions/graph-lifecycle.mjs +0 -148
- package/src/mcp/architecture-bootstrap.mjs +0 -168
- package/src/mcp/architecture-starter.mjs +0 -234
- package/src/mcp/catalog.mjs +0 -233
- package/src/mcp/company-contract-page.mjs +0 -142
- package/src/mcp/company-contract-reconcile.mjs +0 -87
- package/src/mcp/company-contract-verdict.mjs +0 -42
- package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
- package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
- package/src/mcp/evidence/package-graph-common.mjs +0 -115
- package/src/mcp/evidence/package-lock-graph.mjs +0 -92
- package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
- package/src/mcp/evidence-snapshot.common.mjs +0 -158
- package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
- package/src/mcp/evidence-snapshot.health.mjs +0 -102
- package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
- package/src/mcp/evidence-snapshot.mjs +0 -50
- package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
- package/src/mcp/evidence-snapshot.structure.mjs +0 -84
- package/src/mcp/extension-api.mjs +0 -77
- package/src/mcp/git-output.mjs +0 -7
- package/src/mcp/graph/context-core.mjs +0 -111
- package/src/mcp/graph/context-seeds.mjs +0 -207
- package/src/mcp/graph/context-state.mjs +0 -85
- package/src/mcp/graph/reverse-reach.mjs +0 -42
- package/src/mcp/graph/tools-core.mjs +0 -143
- package/src/mcp/graph/tools-query.mjs +0 -276
- package/src/mcp/graph-context.mjs +0 -5
- package/src/mcp/graph-diff.mjs +0 -218
- package/src/mcp/health/audit-format.mjs +0 -199
- package/src/mcp/health/audit.mjs +0 -199
- package/src/mcp/health/dead-code.mjs +0 -110
- package/src/mcp/health/duplicates.mjs +0 -121
- package/src/mcp/health/endpoints.mjs +0 -71
- package/src/mcp/health/structure.mjs +0 -220
- package/src/mcp/runtime-version.mjs +0 -31
- package/src/mcp/server/auto-refresh.mjs +0 -66
- package/src/mcp/server/runtime-config.mjs +0 -43
- package/src/mcp/server/shutdown.mjs +0 -40
- package/src/mcp/staleness-notice.mjs +0 -20
- package/src/mcp/sync/evidence-architecture.mjs +0 -54
- package/src/mcp/sync/evidence-common.mjs +0 -88
- package/src/mcp/sync/evidence-duplicates.mjs +0 -97
- package/src/mcp/sync/evidence-health.mjs +0 -56
- package/src/mcp/sync/evidence-packages.mjs +0 -95
- package/src/mcp/sync/payload-common.mjs +0 -97
- package/src/mcp/sync/payload-v2.mjs +0 -54
- package/src/mcp/sync/payload-v3.mjs +0 -79
- package/src/mcp/sync-evidence.mjs +0 -23
- package/src/mcp/sync-payload.mjs +0 -70
- package/src/mcp/tool-result.mjs +0 -54
- package/src/mcp/tools-actions.mjs +0 -11
- package/src/mcp/tools-architecture.mjs +0 -177
- package/src/mcp/tools-company.mjs +0 -251
- package/src/mcp/tools-context.mjs +0 -222
- package/src/mcp/tools-endpoints.mjs +0 -207
- package/src/mcp/tools-graph-hubs.mjs +0 -78
- package/src/mcp/tools-graph.mjs +0 -17
- package/src/mcp/tools-health.mjs +0 -24
- package/src/mcp/tools-history.mjs +0 -28
- package/src/mcp/tools-impact-change.mjs +0 -220
- package/src/mcp/tools-impact-precision.mjs +0 -89
- package/src/mcp/tools-impact.mjs +0 -169
- package/src/mcp/tools-source.mjs +0 -238
- package/src/mcp/tools-verified-change.mjs +0 -200
- package/src/mcp-rg.mjs +0 -50
- package/src/mcp-runtime.mjs +0 -2
- package/src/mcp-server.mjs +0 -298
- package/src/mcp-source-tools.mjs +0 -163
- package/src/path-classification.js +0 -226
- package/src/path-ignore.js +0 -69
- package/src/precision/lsp-client/constants.js +0 -12
- package/src/precision/lsp-client/environment.js +0 -20
- package/src/precision/lsp-client/errors.js +0 -15
- package/src/precision/lsp-client/lifecycle.js +0 -114
- package/src/precision/lsp-client/message-parser.js +0 -81
- package/src/precision/lsp-client/protocol.js +0 -212
- package/src/precision/lsp-client/registry.js +0 -59
- package/src/precision/lsp-client/repo-uri.js +0 -60
- package/src/precision/lsp-client/stdio-client.js +0 -140
- package/src/precision/lsp-client.js +0 -10
- package/src/precision/lsp-overlay/budget-policy.js +0 -78
- package/src/precision/lsp-overlay/build.js +0 -261
- package/src/precision/lsp-overlay/contract.js +0 -61
- package/src/precision/lsp-overlay/reference-results.js +0 -108
- package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
- package/src/precision/lsp-overlay/source-session.js +0 -142
- package/src/precision/lsp-overlay/store.js +0 -150
- package/src/precision/lsp-overlay/target-index.js +0 -152
- package/src/precision/lsp-overlay/target-query.js +0 -55
- package/src/precision/lsp-overlay.js +0 -11
- package/src/precision/symbol-query.js +0 -224
- package/src/precision/typescript-lsp-provider.js +0 -12
- package/src/precision/typescript-provider/client.js +0 -89
- package/src/precision/typescript-provider/discovery.js +0 -124
- package/src/precision/typescript-provider/isolated-runtime.js +0 -39
- package/src/precision/typescript-provider/project-host.js +0 -254
- package/src/precision/typescript-provider/project-safety.js +0 -166
- package/src/precision/typescript-provider/reference-usage.js +0 -53
- package/src/process.js +0 -95
- package/src/repo-path.js +0 -53
- package/src/scan/discover.inventory.js +0 -78
- package/src/scan/discover.js +0 -5
- package/src/scan/discover.list.js +0 -79
- package/src/scan/discover.stack.js +0 -227
- package/src/scan/search.core.js +0 -24
- package/src/scan/search.git.js +0 -102
- package/src/scan/search.js +0 -9
- package/src/scan/search.node.js +0 -83
- package/src/scan/search.preview.js +0 -49
- package/src/scan/search.rg.js +0 -145
- package/src/security/advisory-store.js +0 -172
- package/src/security/installed-jvm-rust.js +0 -46
- package/src/security/installed.js +0 -280
- package/src/security/malware-file-heuristics.js +0 -121
- package/src/security/malware-heuristics.exclusions.js +0 -134
- package/src/security/malware-heuristics.js +0 -15
- package/src/security/malware-heuristics.roots.js +0 -145
- package/src/security/malware-heuristics.scan.js +0 -89
- package/src/security/malware-heuristics.sweep.js +0 -122
- package/src/security/malware-scoring.js +0 -105
- package/src/security/match.js +0 -85
- package/src/security/registry-sig.classify.js +0 -137
- package/src/security/registry-sig.js +0 -18
- package/src/security/registry-sig.rules.js +0 -192
- package/src/security/rust-advisory-report.js +0 -60
- package/src/security/typosquat.js +0 -81
- package/src/util.js +0 -40
- package/src/version.js +0 -7
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
// Rust extractor. Symbols: fn (incl. impl methods) + struct/enum/trait/type/mod + const/static
|
|
2
|
-
// (+ macro_rules!/union via optional queries). Calls: `foo()` / `x.foo()` / `path::foo()` (name only).
|
|
3
|
-
// File dependencies follow Rust's module tree: outlined `mod`, `use` trees, public re-exports, and anchored
|
|
4
|
-
// `crate/self/super` paths resolve to repo-local .rs or */mod.rs files. External crates deliberately stay out
|
|
5
|
-
// of this adapter; Cargo dependency analysis owns them.
|
|
6
|
-
import { rustScopedCalls } from "./lang-rust-calls.js";
|
|
7
|
-
|
|
8
|
-
const SYMS_CORE = `
|
|
9
|
-
(function_item name: (identifier) @function)
|
|
10
|
-
(struct_item name: (type_identifier) @struct)
|
|
11
|
-
(enum_item name: (type_identifier) @enum)
|
|
12
|
-
(trait_item name: (type_identifier) @trait)
|
|
13
|
-
(type_item name: (type_identifier) @type)
|
|
14
|
-
(mod_item name: (identifier) @module)
|
|
15
|
-
(const_item name: (identifier) @constant)
|
|
16
|
-
(static_item name: (identifier) @static)`;
|
|
17
|
-
// Grammar-version-dependent node types, compiled SEPARATELY (one unknown type voids its whole query).
|
|
18
|
-
const SYMS_OPTIONAL = [
|
|
19
|
-
`(function_signature_item name: (identifier) @function)`,
|
|
20
|
-
`(macro_definition name: (identifier) @macro)`,
|
|
21
|
-
`(union_item name: (type_identifier) @union)`,
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
const cleanSegment = (part) => String(part || "").trim().replace(/^r#/, "");
|
|
25
|
-
// Rust primitive types are language builtins, never crate dependencies: `f64::from(..)`, `u8::MAX`,
|
|
26
|
-
// `str::len` and friends must not be recorded as external crate imports.
|
|
27
|
-
const RUST_PRIMITIVES = new Set(["bool", "char", "str", "f32", "f64", "i8", "i16", "i32", "i64", "i128", "isize", "u8", "u16", "u32", "u64", "u128", "usize"]);
|
|
28
|
-
const RUST_NON_CRATE_HEADS = ["crate", "self", "super", "std", "core", "alloc"];
|
|
29
|
-
// A path head is an external crate only when it is not an anchor keyword, a std root, a primitive type,
|
|
30
|
-
// or a name already bound into local scope by a `use` (a module alias or imported item).
|
|
31
|
-
const isExternalCrate = (head, localBindings) => Boolean(head) && !RUST_NON_CRATE_HEADS.includes(head) && !RUST_PRIMITIVES.has(head) && !localBindings.has(head) && /^[a-z_][\w]*$/.test(head);
|
|
32
|
-
const pathParts = (node) => String(node?.text || "").split("::").map(cleanSegment).filter(Boolean);
|
|
33
|
-
const under = (node, type) => { for (let p = node?.parent; p; p = p.parent) if (p.type === type) return true; return false; };
|
|
34
|
-
const ancestor = (node, types) => {
|
|
35
|
-
for (let parent = node?.parent; parent; parent = parent.parent) if (types.has(parent.type)) return parent;
|
|
36
|
-
return null;
|
|
37
|
-
};
|
|
38
|
-
const memberOwners = new Set(["impl_item", "trait_item"]);
|
|
39
|
-
const publicVisibility = (declaration, owner) => {
|
|
40
|
-
if (owner?.type === "trait_item") return "public";
|
|
41
|
-
const source = String(declaration?.text || "").trimStart();
|
|
42
|
-
if (/^pub\s/.test(source)) return "public";
|
|
43
|
-
if (/^pub\s*\(/.test(source)) return "protected";
|
|
44
|
-
return "private";
|
|
45
|
-
};
|
|
46
|
-
const ownerName = (owner, field) => {
|
|
47
|
-
if (!owner) return "";
|
|
48
|
-
if (owner.type === "trait_item") return field(owner, "name")?.text || "";
|
|
49
|
-
const type = field(owner, "type")?.text || "";
|
|
50
|
-
const withoutGenerics = type.replace(/<[^<>]*>/g, "");
|
|
51
|
-
return (withoutGenerics.match(/[A-Za-z_]\w*/g) || []).at(-1) || "";
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function pathAttribute(modNode) {
|
|
55
|
-
for (let prev = modNode?.previousNamedSibling; prev?.type === "attribute_item"; prev = prev.previousNamedSibling) {
|
|
56
|
-
const hashedRaw = prev.text.match(/\bpath\s*=\s*r(#+)"([^"]+)"\1/);
|
|
57
|
-
if (hashedRaw) return hashedRaw[2] || "";
|
|
58
|
-
const plain = prev.text.match(/\bpath\s*=\s*(?:r)?"([^"]+)"/);
|
|
59
|
-
if (plain) return plain[1] || "";
|
|
60
|
-
}
|
|
61
|
-
return "";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Test-only classification must mean "compiled exclusively under `cargo test`": #[cfg(test)] and
|
|
65
|
-
// #[cfg(all(test, ...))] guarantee that; #[cfg(any(test, ...))] also compiles into production builds
|
|
66
|
-
// and deliberately stays unclassified. #[test]/#[bench] (incl. #[tokio::test]-style harness paths)
|
|
67
|
-
// mark the annotated function itself.
|
|
68
|
-
const CFG_TEST_RE = /#\s*!?\s*\[\s*cfg\s*\(\s*(?:test\s*\)|all\s*\(\s*test\b)/;
|
|
69
|
-
const TEST_FN_ATTR_RE = /#\s*\[\s*(?:[\w]+(?:\s*::\s*[\w]+)*\s*::\s*)?(?:test|bench)\s*(?:\]|\()/;
|
|
70
|
-
const CFG_TEST_CARRIERS = new Set(["mod_item", "impl_item", "trait_item", "function_item"]);
|
|
71
|
-
const COMMENT_TYPES = new Set(["line_comment", "block_comment"]);
|
|
72
|
-
const itemAttributeText = (item) => {
|
|
73
|
-
// Comments are NAMED siblings in tree-sitter-rust — `#[test]` + `// note` + `fn` must still classify.
|
|
74
|
-
let text = "";
|
|
75
|
-
for (let prev = item?.previousNamedSibling; prev; prev = prev.previousNamedSibling) {
|
|
76
|
-
if (COMMENT_TYPES.has(prev.type)) continue;
|
|
77
|
-
if (prev.type !== "attribute_item") break;
|
|
78
|
-
text += prev.text + "\n";
|
|
79
|
-
}
|
|
80
|
-
return text;
|
|
81
|
-
};
|
|
82
|
-
// `#![cfg(test)]` at the top of a file or module body gates everything below it. tree-sitter-rust
|
|
83
|
-
// tokenizes a file-leading `#!...` as `shebang`; a real shebang line never matches CFG_TEST_RE.
|
|
84
|
-
const innerCfgTest = (body) => (body?.namedChildren || [])
|
|
85
|
-
.some((child) => (child.type === "inner_attribute_item" || child.type === "shebang") && CFG_TEST_RE.test(child.text));
|
|
86
|
-
const underCfgTest = (node) => {
|
|
87
|
-
for (let parent = node?.parent; parent; parent = parent.parent) {
|
|
88
|
-
if (parent.type === "declaration_list" && innerCfgTest(parent)) return true;
|
|
89
|
-
if (CFG_TEST_CARRIERS.has(parent.type) && CFG_TEST_RE.test(itemAttributeText(parent))) return true;
|
|
90
|
-
if (!parent.parent && innerCfgTest(parent)) return true; // source_file root
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
function inlineAncestors(node) {
|
|
96
|
-
const result = [];
|
|
97
|
-
for (let p = node?.parent; p; p = p.parent) {
|
|
98
|
-
if (p.type !== "declaration_list" || p.parent?.type !== "mod_item") continue;
|
|
99
|
-
const mod = p.parent;
|
|
100
|
-
const name = mod.namedChildren.find((child) => child.type === "identifier")?.text;
|
|
101
|
-
if (name) result.unshift({ name: cleanSegment(name), path: pathAttribute(mod) });
|
|
102
|
-
}
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Expand a Rust use tree into its leaf paths while retaining aliases. Examples:
|
|
107
|
-
// `crate::api::{self, Client as C, types::*}` -> api, api::Client, api::types.
|
|
108
|
-
function useLeaves(node, prefix = []) {
|
|
109
|
-
if (!node) return [];
|
|
110
|
-
if (node.type === "use_declaration") {
|
|
111
|
-
const body = node.namedChildren.find((child) => child.type !== "visibility_modifier");
|
|
112
|
-
return useLeaves(body, prefix);
|
|
113
|
-
}
|
|
114
|
-
if (node.type === "use_list") return node.namedChildren.flatMap((child) => useLeaves(child, prefix));
|
|
115
|
-
if (node.type === "scoped_use_list") {
|
|
116
|
-
const list = node.namedChildren.find((child) => child.type === "use_list");
|
|
117
|
-
const head = node.namedChildren.find((child) => child !== list);
|
|
118
|
-
return useLeaves(list, [...prefix, ...pathParts(head)]);
|
|
119
|
-
}
|
|
120
|
-
if (node.type === "use_as_clause") {
|
|
121
|
-
const named = node.namedChildren;
|
|
122
|
-
const alias = cleanSegment(named[named.length - 1]?.text);
|
|
123
|
-
return useLeaves(named[0], prefix).map((leaf) => ({ ...leaf, local: alias }));
|
|
124
|
-
}
|
|
125
|
-
if (node.type === "use_wildcard") {
|
|
126
|
-
return [{ segments: [...prefix, ...pathParts(node.namedChildren[0])], wildcard: true, local: null }];
|
|
127
|
-
}
|
|
128
|
-
if (node.type === "self") {
|
|
129
|
-
const local = [...prefix].reverse().find((part) => !["crate", "self", "super"].includes(part)) || null;
|
|
130
|
-
return [{ segments: prefix.length ? [...prefix] : ["self"], moduleSelf: true, local }];
|
|
131
|
-
}
|
|
132
|
-
if (["identifier", "scoped_identifier", "scoped_type_identifier", "crate", "super"].includes(node.type)) {
|
|
133
|
-
const own = pathParts(node);
|
|
134
|
-
const segments = [...prefix, ...own];
|
|
135
|
-
const local = [...own].reverse().find((part) => !["crate", "self", "super"].includes(part)) || null;
|
|
136
|
-
return [{ segments, local }];
|
|
137
|
-
}
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export default {
|
|
142
|
-
family: "rust",
|
|
143
|
-
grammars: ["rust"],
|
|
144
|
-
exts: { ".rs": "rust" },
|
|
145
|
-
isWeb: false,
|
|
146
|
-
// Bare `foo()` and method `x.foo()` calls resolve by name in the generic pass-2 loop. Scoped
|
|
147
|
-
// `Path::foo()` calls are handled in pass2() below with the full qualifier in hand, so an external
|
|
148
|
-
// `OpenOptions::new()` cannot bind its bare `new` to an unrelated same-named function in the folder.
|
|
149
|
-
calls: `
|
|
150
|
-
(call_expression function: (identifier) @callee)
|
|
151
|
-
(call_expression function: (field_expression field: (field_identifier) @callee))`,
|
|
152
|
-
heritage: [
|
|
153
|
-
`(impl_item trait: (type_identifier) @super)`,
|
|
154
|
-
`(impl_item trait: (generic_type type: (type_identifier) @super))`,
|
|
155
|
-
],
|
|
156
|
-
|
|
157
|
-
pass1(ctx) {
|
|
158
|
-
const { grammar, tree, fileRel, caps, field, addSym, addImportEdge, addExternalImport, imports, resolveRustMod, resolveRustPath, resolveRustCratePath, links, nameToId } = ctx;
|
|
159
|
-
const owned = [];
|
|
160
|
-
for (const src of [SYMS_CORE, ...SYMS_OPTIONAL]) {
|
|
161
|
-
for (const cap of caps(grammar, src, tree.rootNode)) {
|
|
162
|
-
const declaration = cap.node.parent;
|
|
163
|
-
const owner = cap.name === "function" ? ancestor(cap.node, memberOwners) : null;
|
|
164
|
-
const memberOf = ownerName(owner, field);
|
|
165
|
-
const symbolKind = cap.name === "function" ? (memberOf ? "method" : "function") : cap.name;
|
|
166
|
-
const visibility = publicVisibility(declaration, owner);
|
|
167
|
-
const attrs = itemAttributeText(declaration);
|
|
168
|
-
const testSurface = CFG_TEST_RE.test(attrs)
|
|
169
|
-
|| (cap.name === "function" && TEST_FN_ATTR_RE.test(attrs))
|
|
170
|
-
|| underCfgTest(declaration);
|
|
171
|
-
const id = addSym(cap.node.text, cap.node.startPosition.row + 1, cap.name === "function", {
|
|
172
|
-
sourceNode: declaration,
|
|
173
|
-
selectionNode: cap.node,
|
|
174
|
-
symbolKind,
|
|
175
|
-
...(testSurface ? { testSurface: true } : {}),
|
|
176
|
-
...(memberOf ? { memberOf, visibility } : { moduleDeclaration: true }),
|
|
177
|
-
...(!memberOf && visibility === "public" ? { exported: true } : {}),
|
|
178
|
-
});
|
|
179
|
-
if (id && memberOf) owned.push({owner: memberOf, id});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
for (const member of owned) {
|
|
183
|
-
const ownerId = nameToId.get(member.owner);
|
|
184
|
-
if (ownerId && ownerId !== member.id) links.push({source: ownerId, target: member.id, relation: "method", confidence: "EXTRACTED"});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// File dependency edges are intentionally unique per source/target/relation. A qualified path can be
|
|
188
|
-
// nested in another qualified path and often repeats an existing `mod`/`use`; counting occurrences would
|
|
189
|
-
// inflate module coupling without adding structure.
|
|
190
|
-
const emitted = new Set();
|
|
191
|
-
// Names bound into this file's scope by `use` (module aliases and imported items), tracked even when the
|
|
192
|
-
// used path did not resolve to a repo file, so later `alias::item` paths are not re-read as external crates.
|
|
193
|
-
const localBindings = new Set();
|
|
194
|
-
const emit = (target, meta = {}) => {
|
|
195
|
-
if (!target || target === fileRel) return;
|
|
196
|
-
const relation = meta.relation || "imports";
|
|
197
|
-
const key = relation + ">" + target;
|
|
198
|
-
if (emitted.has(key)) return;
|
|
199
|
-
emitted.add(key);
|
|
200
|
-
// Rust `mod`/`use`/`pub use` relationships are resolved by the compiler. They describe real
|
|
201
|
-
// architectural coupling, but they are not runtime module loading and therefore must not create
|
|
202
|
-
// JavaScript-style initialization cycles or runtime boundary/blast-radius findings.
|
|
203
|
-
addImportEdge(target, { ...meta, relation, compileOnly: true });
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// `mod foo;` loads foo.rs or foo/mod.rs. Inline `mod foo { ... }` stays in the current file, but any
|
|
207
|
-
// outlined modules declared inside it are captured separately with their inline ancestor path.
|
|
208
|
-
for (const cap of caps(grammar, `(mod_item) @mod`, tree.rootNode)) {
|
|
209
|
-
const mod = cap.node;
|
|
210
|
-
const name = mod.namedChildren.find((child) => child.type === "identifier")?.text;
|
|
211
|
-
if (name) localBindings.add(cleanSegment(name)); // a declared child module shadows any same-named crate
|
|
212
|
-
if (mod.namedChildren.some((child) => child.type === "declaration_list")) continue;
|
|
213
|
-
if (!name) continue;
|
|
214
|
-
const target = resolveRustMod(fileRel, cleanSegment(name), {
|
|
215
|
-
inlineModules: inlineAncestors(mod),
|
|
216
|
-
explicitPath: pathAttribute(mod),
|
|
217
|
-
});
|
|
218
|
-
emit(target, { line: mod.startPosition.row + 1, specifier: `mod ${name}` });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Imports/re-exports may be nested trees and aliases. Besides the file edge, retain direct item aliases
|
|
222
|
-
// so the existing pass-2 call resolver can connect `use crate::worker::run; run()` across folders.
|
|
223
|
-
for (const cap of caps(grammar, `(use_declaration) @use`, tree.rootNode)) {
|
|
224
|
-
const use = cap.node;
|
|
225
|
-
const relation = use.namedChildren.some((child) => child.type === "visibility_modifier") ? "re_exports" : "imports";
|
|
226
|
-
const ancestors = inlineAncestors(use);
|
|
227
|
-
for (const leaf of useLeaves(use)) {
|
|
228
|
-
// A `use` alias or imported item name shadows any same-named crate for the rest of this file. The
|
|
229
|
-
// crate's OWN root name (e.g. `use anyhow::{self}`) is excluded so it still counts as a dependency.
|
|
230
|
-
if (leaf.local && leaf.local !== "_" && cleanSegment(leaf.local) !== cleanSegment(leaf.segments[0])) localBindings.add(cleanSegment(leaf.local));
|
|
231
|
-
const crate = cleanSegment(leaf.segments[0]);
|
|
232
|
-
let resolved = resolveRustPath(fileRel, leaf.segments, { inlineModules: ancestors, unqualified: true });
|
|
233
|
-
// A head that is not a local module may be a sibling workspace crate (`use radiochron::wlan`):
|
|
234
|
-
// resolve it INTO that crate so its items bind here and cross-crate calls resolve in pass 2. It is
|
|
235
|
-
// still recorded as a dependency import so the sibling crate is not flagged an unused Cargo dep.
|
|
236
|
-
if (!resolved && resolveRustCratePath && isExternalCrate(crate, localBindings)) {
|
|
237
|
-
resolved = resolveRustCratePath(crate, leaf.segments.slice(1));
|
|
238
|
-
if (resolved) addExternalImport({ spec: leaf.segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-use", line: use.startPosition.row + 1 });
|
|
239
|
-
}
|
|
240
|
-
if (!resolved) {
|
|
241
|
-
if (isExternalCrate(crate, localBindings)) {
|
|
242
|
-
addExternalImport({ spec: leaf.segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-use", line: use.startPosition.row + 1 });
|
|
243
|
-
}
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
emit(resolved.targetFile, { relation, line: use.startPosition.row + 1, specifier: use.text.replace(/;\s*$/, "") });
|
|
247
|
-
if (!leaf.wildcard && leaf.local && leaf.local !== "_") {
|
|
248
|
-
const imported = resolved.remaining.length ? cleanSegment(resolved.remaining.at(-1)) : "*";
|
|
249
|
-
imports.set(cleanSegment(leaf.local), { imported, targetFile: resolved.targetFile, rustModule: imported === "*" });
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Fully-qualified paths need no `use` declaration but still prove a dependency. Restrict this pass to
|
|
255
|
-
// explicit crate/self/super anchors so associated paths such as `Type::method` cannot be mistaken for a
|
|
256
|
-
// same-named module file. Inner prefixes are skipped; only the maximal path emits an edge.
|
|
257
|
-
for (const cap of caps(grammar, `[(scoped_identifier) (scoped_type_identifier)] @path`, tree.rootNode)) {
|
|
258
|
-
const node = cap.node;
|
|
259
|
-
if (under(node, "use_declaration")) continue;
|
|
260
|
-
if (["scoped_identifier", "scoped_type_identifier"].includes(node.parent?.type)) continue;
|
|
261
|
-
const segments = pathParts(node);
|
|
262
|
-
if (!["crate", "self", "super"].includes(segments[0])) {
|
|
263
|
-
const crate = cleanSegment(segments[0]);
|
|
264
|
-
// A fully-qualified sibling-crate path (`radiochron::events::recent`) is a real cross-crate
|
|
265
|
-
// dependency: emit the file edge AND record the dependency import so the sibling crate still
|
|
266
|
-
// counts as used, rather than being logged as an external crates.io crate.
|
|
267
|
-
const crateResolved = resolveRustCratePath && isExternalCrate(crate, localBindings)
|
|
268
|
-
? resolveRustCratePath(crate, segments.slice(1))
|
|
269
|
-
: null;
|
|
270
|
-
if (crateResolved) {
|
|
271
|
-
emit(crateResolved.targetFile, { line: node.startPosition.row + 1, specifier: node.text });
|
|
272
|
-
addExternalImport({ spec: segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-path", line: node.startPosition.row + 1 });
|
|
273
|
-
} else if (isExternalCrate(crate, localBindings)) {
|
|
274
|
-
addExternalImport({ spec: segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-path", line: node.startPosition.row + 1 });
|
|
275
|
-
}
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
const resolved = resolveRustPath(fileRel, segments, { inlineModules: inlineAncestors(node), unqualified: false });
|
|
279
|
-
if (!resolved) continue;
|
|
280
|
-
emit(resolved.targetFile, { line: node.startPosition.row + 1, specifier: node.text });
|
|
281
|
-
const finalName = cleanSegment(segments.at(-1));
|
|
282
|
-
if (resolved.remaining.length && finalName && !imports.has(finalName)) {
|
|
283
|
-
imports.set(finalName, { imported: finalName, targetFile: resolved.targetFile, rustQualified: true });
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
for (const cap of caps(grammar, `(extern_crate_declaration name: (identifier) @crate)`, tree.rootNode)) {
|
|
288
|
-
const crate = cleanSegment(cap.node.text);
|
|
289
|
-
if (crate && !["std", "core", "alloc"].includes(crate)) {
|
|
290
|
-
addExternalImport({ spec: crate, pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-extern-crate", line: cap.node.startPosition.row + 1 });
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
// Scoped `Path::method()` calls are resolved in lang-rust-calls.js with the full qualifier in hand.
|
|
296
|
-
pass2(ctx) {
|
|
297
|
-
rustScopedCalls(ctx, { pathParts, inlineAncestors });
|
|
298
|
-
},
|
|
299
|
-
};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// Solidity extractor. Symbols: contract/interface/library (space "both" so `is Base` heritage and
|
|
2
|
-
// `new Vault()` both resolve through the value-space resolver), functions/constructors/modifiers/
|
|
3
|
-
// events/errors/structs/enums/state vars (members carry memberOf + visibility). Imports: relative
|
|
4
|
-
// paths, Foundry remappings (remappings.txt / foundry.toml), and root-anchored specs resolve to repo
|
|
5
|
-
// files; everything else (npm-style @openzeppelin/…, absent lib/ submodules) is RECORDED as an
|
|
6
|
-
// external import for dependency analysis. Calls: bare `f()`, modifier invocations, `emit Event(…)`,
|
|
7
|
-
// `new Contract(…)`, and `using Lib for T` all feed the calls resolver. Same-dir symbols share scope
|
|
8
|
-
// (see sharesDirScope): Solidity's flat project namespace makes plain `import "./Base.sol"` — which
|
|
9
|
-
// names no symbols — resolvable for siblings without guessing; cross-dir plain imports still produce
|
|
10
|
-
// the file-level import edge, so blast radius stays correct even where symbol edges are unknowable.
|
|
11
|
-
import { specToPkg } from "./spec-pkg.js";
|
|
12
|
-
|
|
13
|
-
const CONTAINERS = new Set(["contract_declaration", "interface_declaration", "library_declaration"]);
|
|
14
|
-
const KIND_BY_CONTAINER = {
|
|
15
|
-
contract_declaration: "contract",
|
|
16
|
-
interface_declaration: "interface",
|
|
17
|
-
library_declaration: "library",
|
|
18
|
-
};
|
|
19
|
-
// external/public functions are the deployed ABI — callable by any transaction, not just repo code.
|
|
20
|
-
const VISIBILITY = { external: "public", public: "public", internal: "protected", private: "private" };
|
|
21
|
-
|
|
22
|
-
function enclosingContainer(node) {
|
|
23
|
-
for (let parent = node?.parent; parent; parent = parent.parent) {
|
|
24
|
-
if (CONTAINERS.has(parent.type)) return parent;
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const identifierOf = (node) => node?.namedChildren?.find((child) => child.type === "identifier") || null;
|
|
30
|
-
const childOfType = (node, type) => node?.namedChildren?.find((child) => child.type === type) || null;
|
|
31
|
-
const parameterCount = (node) => (node?.namedChildren || []).filter((child) => child.type === "parameter").length;
|
|
32
|
-
|
|
33
|
-
export default {
|
|
34
|
-
family: "solidity",
|
|
35
|
-
grammars: ["solidity"],
|
|
36
|
-
exts: { ".sol": "solidity" },
|
|
37
|
-
isWeb: false,
|
|
38
|
-
calls: `[(call_expression (identifier) @callee) (modifier_invocation (identifier) @callee) (emit_statement (identifier) @callee) (new_expression (type_name (user_defined_type (identifier) @callee))) (using_directive (type_alias (identifier) @callee))]`,
|
|
39
|
-
heritage: [`(inheritance_specifier (user_defined_type (identifier) @base))`],
|
|
40
|
-
|
|
41
|
-
pass1(ctx) {
|
|
42
|
-
const { grammar, tree, fileRel, caps, addSym, addImportEdge, addExternalImport, imports, links, nameToId, resolveSolidityImport } = ctx;
|
|
43
|
-
|
|
44
|
-
// ---- containers (contract/interface/library) ----
|
|
45
|
-
for (const cap of caps(grammar, `[(contract_declaration (identifier) @c) (interface_declaration (identifier) @c) (library_declaration (identifier) @c)]`, tree.rootNode)) {
|
|
46
|
-
addSym(cap.node.text, cap.node.startPosition.row + 1, false, {
|
|
47
|
-
sourceNode: cap.node.parent,
|
|
48
|
-
selectionNode: cap.node,
|
|
49
|
-
symbolKind: KIND_BY_CONTAINER[cap.node.parent.type],
|
|
50
|
-
symbolSpace: "both",
|
|
51
|
-
exported: true,
|
|
52
|
-
moduleDeclaration: true,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ---- functions (free + members), constructors, modifiers ----
|
|
57
|
-
const ownedMembers = [];
|
|
58
|
-
const addMember = (name, node, selection, extra) => {
|
|
59
|
-
const container = enclosingContainer(node);
|
|
60
|
-
const ownerName = container ? identifierOf(container)?.text || null : null;
|
|
61
|
-
const id = addSym(name, (selection || node).startPosition.row + 1, extra.callable !== false, {
|
|
62
|
-
sourceNode: node,
|
|
63
|
-
selectionNode: selection || undefined,
|
|
64
|
-
...(ownerName ? { memberOf: ownerName } : { exported: true, moduleDeclaration: true }),
|
|
65
|
-
...extra,
|
|
66
|
-
});
|
|
67
|
-
if (ownerName && id) ownedMembers.push({ ownerName, id });
|
|
68
|
-
return id;
|
|
69
|
-
};
|
|
70
|
-
for (const cap of caps(grammar, `(function_definition (identifier) @fn)`, tree.rootNode)) {
|
|
71
|
-
const definition = cap.node.parent;
|
|
72
|
-
const visibility = VISIBILITY[childOfType(definition, "visibility")?.text || ""];
|
|
73
|
-
addMember(cap.node.text, definition, cap.node, {
|
|
74
|
-
symbolKind: enclosingContainer(definition) ? "method" : "function",
|
|
75
|
-
...(visibility ? { visibility } : {}),
|
|
76
|
-
parameterCount: parameterCount(definition),
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
for (const cap of caps(grammar, `(constructor_definition) @ctor`, tree.rootNode))
|
|
80
|
-
addMember("constructor", cap.node, null, { symbolKind: "constructor", parameterCount: parameterCount(cap.node) });
|
|
81
|
-
for (const cap of caps(grammar, `(modifier_definition (identifier) @m)`, tree.rootNode))
|
|
82
|
-
addMember(cap.node.text, cap.node.parent, cap.node, { symbolKind: "modifier", parameterCount: parameterCount(cap.node.parent) });
|
|
83
|
-
|
|
84
|
-
// ---- data/type declarations ----
|
|
85
|
-
for (const cap of caps(grammar, `[(event_definition (identifier) @n) (error_declaration (identifier) @n)]`, tree.rootNode))
|
|
86
|
-
addMember(cap.node.text, cap.node.parent, cap.node, { callable: false, symbolKind: cap.node.parent.type === "event_definition" ? "event" : "error" });
|
|
87
|
-
for (const cap of caps(grammar, `[(struct_declaration (identifier) @n) (enum_declaration (identifier) @n)]`, tree.rootNode))
|
|
88
|
-
addMember(cap.node.text, cap.node.parent, cap.node, { callable: false, symbolKind: cap.node.parent.type === "struct_declaration" ? "struct" : "enum", symbolSpace: "both" });
|
|
89
|
-
// capture the DECLARATION and take its first identifier child (the name): an initializer such as
|
|
90
|
-
// `uint x = OTHER_CONST;` can place a second bare identifier under the same declaration node.
|
|
91
|
-
for (const cap of caps(grammar, `(constant_variable_declaration) @d`, tree.rootNode)) {
|
|
92
|
-
const name = identifierOf(cap.node);
|
|
93
|
-
if (name) addMember(name.text, cap.node, name, { callable: false, symbolKind: "constant" });
|
|
94
|
-
}
|
|
95
|
-
for (const cap of caps(grammar, `(state_variable_declaration) @d`, tree.rootNode)) {
|
|
96
|
-
const name = identifierOf(cap.node);
|
|
97
|
-
const visibility = VISIBILITY[childOfType(cap.node, "visibility")?.text || ""] || "protected"; // Solidity default: internal
|
|
98
|
-
if (name) addMember(name.text, cap.node, name, { callable: false, symbolKind: "variable", visibility });
|
|
99
|
-
}
|
|
100
|
-
for (const member of ownedMembers) {
|
|
101
|
-
const ownerId = nameToId.get(member.ownerName);
|
|
102
|
-
if (ownerId) links.push({ source: ownerId, target: member.id, relation: "contains", confidence: "EXTRACTED" });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ---- imports ----
|
|
106
|
-
for (const cap of caps(grammar, `(import_directive) @imp`, tree.rootNode)) {
|
|
107
|
-
const specNode = childOfType(cap.node, "string");
|
|
108
|
-
if (!specNode) continue;
|
|
109
|
-
const spec = specNode.text.replace(/^["']|["']$/g, "");
|
|
110
|
-
const line = specNode.startPosition.row + 1;
|
|
111
|
-
const target = resolveSolidityImport(fileRel, spec);
|
|
112
|
-
if (target) {
|
|
113
|
-
addImportEdge(target, { specifier: spec, line });
|
|
114
|
-
// `import {A, B} from "./x.sol"` — bind each named symbol. A lone identifier may instead be a
|
|
115
|
-
// `* as Alias` namespace name; binding it the same way is harmless (no same-named symbol → no edge).
|
|
116
|
-
for (const named of cap.node.namedChildren.filter((child) => child.type === "identifier"))
|
|
117
|
-
imports.set(named.text, { imported: named.text, targetFile: target });
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (spec.startsWith(".")) { addExternalImport({ spec, kind: "sol-import", line, unresolved: true }); continue; }
|
|
121
|
-
const r = specToPkg(spec);
|
|
122
|
-
if (r) addExternalImport({ spec, pkg: r.pkg, builtin: false, kind: "sol-import", line });
|
|
123
|
-
else addExternalImport({ spec, kind: "sol-import", line, unresolved: true });
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
};
|