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,40 +0,0 @@
|
|
|
1
|
-
// C# extractor. Symbols: class/interface/struct/enum (+record/delegate via optional queries) +
|
|
2
|
-
// method/constructor + properties/fields. Calls: `Foo()` / `x.Foo()` (name only). Heritage: base_list
|
|
3
|
-
// (C# merges extends+implements into one list). `using` directives name NAMESPACES, not files, and a
|
|
4
|
-
// namespace maps to a file only by convention — so no import edges are attempted; cross-file
|
|
5
|
-
// connectivity comes from the name-based calls pass, same as the other non-JS languages.
|
|
6
|
-
const SYMS_CORE = `
|
|
7
|
-
(class_declaration name: (identifier) @class)
|
|
8
|
-
(interface_declaration name: (identifier) @class)
|
|
9
|
-
(struct_declaration name: (identifier) @class)
|
|
10
|
-
(enum_declaration name: (identifier) @class)
|
|
11
|
-
(method_declaration name: (identifier) @method)
|
|
12
|
-
(constructor_declaration name: (identifier) @method)
|
|
13
|
-
(property_declaration name: (identifier) @field)`;
|
|
14
|
-
// Grammar-version-dependent node types, compiled SEPARATELY: one unknown node type voids the whole
|
|
15
|
-
// query it appears in, so these must never ride along with SYMS_CORE.
|
|
16
|
-
const SYMS_OPTIONAL = [
|
|
17
|
-
`(record_declaration name: (identifier) @class)`,
|
|
18
|
-
`(delegate_declaration name: (identifier) @method)`,
|
|
19
|
-
`(field_declaration (variable_declaration (variable_declarator (identifier) @field)))`,
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
export default {
|
|
23
|
-
family: "csharp",
|
|
24
|
-
grammars: ["c_sharp"],
|
|
25
|
-
exts: { ".cs": "c_sharp" },
|
|
26
|
-
isWeb: false,
|
|
27
|
-
calls: `
|
|
28
|
-
(invocation_expression function: (identifier) @callee)
|
|
29
|
-
(invocation_expression function: (member_access_expression name: (identifier) @callee))`,
|
|
30
|
-
heritage: [`(base_list (identifier) @super)`, `(base_list (generic_name (identifier) @super))`],
|
|
31
|
-
|
|
32
|
-
pass1(ctx) {
|
|
33
|
-
const { grammar, tree, caps, addSym } = ctx;
|
|
34
|
-
for (const src of [SYMS_CORE, ...SYMS_OPTIONAL]) {
|
|
35
|
-
for (const cap of caps(grammar, src, tree.rootNode)) {
|
|
36
|
-
addSym(cap.node.text, cap.node.startPosition.row + 1, cap.name === "method", { sourceNode: cap.node.parent });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// CSS / SCSS / LESS extractor (web reference graph, not a call graph — orchestrator skips pass 2 for it).
|
|
2
|
-
// Symbols: class/id selectors (indexed in selectorIndex so HTML class/id usage can reference the file).
|
|
3
|
-
// Imports: `@import "x.css"`. NOTE: no dedicated SCSS grammar in tree-sitter-wasms, so nested SCSS selectors
|
|
4
|
-
// are under-captured (files still appear as nodes + resolve JS `import styles from './x.scss'`).
|
|
5
|
-
export default {
|
|
6
|
-
family: "css",
|
|
7
|
-
grammars: ["css"],
|
|
8
|
-
exts: { ".css": "css", ".scss": "css", ".less": "css" },
|
|
9
|
-
isWeb: true,
|
|
10
|
-
calls: "",
|
|
11
|
-
heritage: [],
|
|
12
|
-
|
|
13
|
-
pass1(ctx) {
|
|
14
|
-
const { grammar, tree, fileRel, caps, addNode, links, nodeIds, syms, selectorIndex, addImportEdge, resolveHref } = ctx;
|
|
15
|
-
const addSel = (label, line) => {
|
|
16
|
-
const id = `${fileRel}#${label}@${line}`;
|
|
17
|
-
if (nodeIds.has(id)) return;
|
|
18
|
-
addNode({ id, label, file_type: "code", source_file: fileRel, source_location: `L${line}` });
|
|
19
|
-
links.push({ source: fileRel, target: id, relation: "contains", confidence: "EXTRACTED" });
|
|
20
|
-
syms.push({ id, name: label, start: line });
|
|
21
|
-
let s = selectorIndex.get(label); if (!s) selectorIndex.set(label, (s = new Set())); s.add(fileRel);
|
|
22
|
-
};
|
|
23
|
-
for (const cap of caps(grammar, `(class_selector (class_name) @c)`, tree.rootNode)) addSel("." + cap.node.text, cap.node.startPosition.row + 1);
|
|
24
|
-
for (const cap of caps(grammar, `(id_selector (id_name) @i)`, tree.rootNode)) addSel("#" + cap.node.text, cap.node.startPosition.row + 1);
|
|
25
|
-
for (const cap of caps(grammar, `(import_statement (string_value) @s)`, tree.rootNode)) {
|
|
26
|
-
const tgt = resolveHref(fileRel, cap.node.text.replace(/^["']|["']$/g, "")); if (tgt) addImportEdge(tgt);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
};
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// Go extractor. Symbols: func/method(receiver)/type(struct+interface)/top-level var+const.
|
|
2
|
-
// Imports: `import "mod/pkg"` → the package DIRECTORY's files (Go package = dir), resolved via go.mod prefix.
|
|
3
|
-
// Unresolved paths are RECORDED as external imports (stdlib → builtin, modules → ecosystem "Go") so
|
|
4
|
-
// dependency analysis can diff them against go.mod. Calls: bare `foo()` (same-file + same-package resolve
|
|
5
|
-
// in the orchestrator; cross-pkg `pkg.Func()` is a selector — see resolveGoPackage/pass2). No inheritance.
|
|
6
|
-
import { goSpecToPkg } from "./spec-pkg.js";
|
|
7
|
-
|
|
8
|
-
// Return the named Go type behind pointers/generics/parentheses. Qualified names are
|
|
9
|
-
// kept (`speaker.Speaker`) so pass 2 can route them through the import alias table.
|
|
10
|
-
export function goTypeName(node) {
|
|
11
|
-
if (!node) return null;
|
|
12
|
-
if (node.type === "type_identifier") return node.text;
|
|
13
|
-
if (node.type === "qualified_type") return node.text.replace(/\s+/g, "");
|
|
14
|
-
if (node.type === "generic_type") return goTypeName(node.childForFieldName?.("type") || node.namedChildren?.[0]);
|
|
15
|
-
if (["pointer_type", "parenthesized_type", "unary_expression"].includes(node.type)) {
|
|
16
|
-
return goTypeName(node.childForFieldName?.("type") || node.childForFieldName?.("operand") || node.namedChildren?.[0]);
|
|
17
|
-
}
|
|
18
|
-
if ((node.namedChildren?.length || 0) === 1) return goTypeName(node.namedChildren[0]);
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const namedFieldChildren = (node, name) => {
|
|
23
|
-
const children = node?.childrenForFieldName?.(name);
|
|
24
|
-
if (Array.isArray(children) && children.length) return children;
|
|
25
|
-
const child = node?.childForFieldName?.(name);
|
|
26
|
-
return child ? [child] : [];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function goStructFields(typeNode) {
|
|
30
|
-
if (typeNode?.type !== "struct_type") return null;
|
|
31
|
-
const fields = {};
|
|
32
|
-
const visit = (node) => {
|
|
33
|
-
if (!node) return;
|
|
34
|
-
if (node.type === "field_declaration") {
|
|
35
|
-
const type = goTypeName(node.childForFieldName?.("type"));
|
|
36
|
-
if (!type) return;
|
|
37
|
-
const names = namedFieldChildren(node, "name");
|
|
38
|
-
if (names.length) for (const name of names) fields[name.text] = type;
|
|
39
|
-
else {
|
|
40
|
-
// An embedded field is addressed by the base type name (`h.Speaker`).
|
|
41
|
-
const embedded = type.split(".").pop();
|
|
42
|
-
if (embedded) fields[embedded] = type;
|
|
43
|
-
}
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
for (const child of node.namedChildren || []) visit(child);
|
|
47
|
-
};
|
|
48
|
-
visit(typeNode);
|
|
49
|
-
return fields;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function goResultType(declaration) {
|
|
53
|
-
const result = declaration?.childForFieldName?.("result");
|
|
54
|
-
if (!result) return null;
|
|
55
|
-
if (result.type !== "parameter_list") return goTypeName(result);
|
|
56
|
-
const declarations = (result.namedChildren || []).filter((child) => child.type === "parameter_declaration");
|
|
57
|
-
// A call used in `value, err := New()` contributes its first result to the
|
|
58
|
-
// first binding. Preserve that receiver type instead of discarding every
|
|
59
|
-
// multi-result signature just because a trailing error is present.
|
|
60
|
-
return goTypeName(declarations[0]?.childForFieldName?.("type"));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export default {
|
|
64
|
-
family: "go",
|
|
65
|
-
grammars: ["go"],
|
|
66
|
-
exts: { ".go": "go" },
|
|
67
|
-
isWeb: false,
|
|
68
|
-
calls: `(call_expression function: (identifier) @callee)`,
|
|
69
|
-
// cross-package `pkg.Func()` — the orchestrator resolves @operand (imported package alias) → its dir, then
|
|
70
|
-
// finds the method there. Without this, funcs called only from other packages look falsely DEAD.
|
|
71
|
-
selectorCall: `(call_expression function: (selector_expression) @sel)`,
|
|
72
|
-
heritage: [],
|
|
73
|
-
|
|
74
|
-
pass1(ctx) {
|
|
75
|
-
const { grammar, tree, fileRel, caps, addSym, addImportEdge, addExternalImport, imports, resolveGoImport, dirFiles, goModule, goModules, goRequires } = ctx;
|
|
76
|
-
const owningModule = (goModules || []).filter((item) => !item.root || fileRel === item.root || fileRel.startsWith(`${item.root}/`))
|
|
77
|
-
.sort((left, right) => right.root.length - left.root.length)[0];
|
|
78
|
-
|
|
79
|
-
// ---- symbols ----
|
|
80
|
-
for (const cap of caps(grammar, `(function_declaration name: (identifier) @fn)`, tree.rootNode)) {
|
|
81
|
-
const declaration = cap.node.parent;
|
|
82
|
-
addSym(cap.node.text, cap.node.startPosition.row + 1, true, {
|
|
83
|
-
sourceNode: declaration,
|
|
84
|
-
selectionNode: cap.node,
|
|
85
|
-
symbolKind: "function",
|
|
86
|
-
returnType: goResultType(declaration),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
for (const cap of caps(grammar, `(method_declaration name: (field_identifier) @method)`, tree.rootNode)) {
|
|
90
|
-
const declaration = cap.node.parent;
|
|
91
|
-
const receiver = declaration.childForFieldName?.("receiver");
|
|
92
|
-
const receiverDeclaration = receiver?.namedChildren?.find((child) => child.type === "parameter_declaration");
|
|
93
|
-
const receiverType = goTypeName(receiverDeclaration?.childForFieldName?.("type"));
|
|
94
|
-
addSym(cap.node.text, cap.node.startPosition.row + 1, true, {
|
|
95
|
-
sourceNode: declaration,
|
|
96
|
-
selectionNode: cap.node,
|
|
97
|
-
symbolKind: "method",
|
|
98
|
-
memberOf: receiverType || undefined,
|
|
99
|
-
receiverType: receiverType || undefined,
|
|
100
|
-
returnType: goResultType(declaration),
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
for (const cap of caps(grammar, `(source_file (type_declaration (type_spec name: (type_identifier) @type)))`, tree.rootNode)) {
|
|
104
|
-
const specification = cap.node.parent;
|
|
105
|
-
const typeNode = specification.childForFieldName?.("type");
|
|
106
|
-
addSym(cap.node.text, cap.node.startPosition.row + 1, false, {
|
|
107
|
-
sourceNode: specification,
|
|
108
|
-
selectionNode: cap.node,
|
|
109
|
-
symbolKind: typeNode?.type === "interface_type" ? "interface" : "type",
|
|
110
|
-
symbolSpace: "type",
|
|
111
|
-
fieldTypes: goStructFields(typeNode),
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
for (const cap of caps(grammar, `(source_file (var_declaration (var_spec name: (identifier) @var))) (source_file (const_declaration (const_spec name: (identifier) @const)))`, tree.rootNode))
|
|
115
|
-
addSym(cap.node.text, cap.node.startPosition.row + 1, false, { sourceNode: cap.node.parent });
|
|
116
|
-
|
|
117
|
-
// ---- imports: package path → package directory → all its .go files ----
|
|
118
|
-
// Also record the package's local name (alias or last path segment) → dir, so cross-package `pkg.Func()`
|
|
119
|
-
// selector calls can resolve in pass 2 (see internal-builder resolveCall).
|
|
120
|
-
for (const cap of caps(grammar, `(import_spec) @spec`, tree.rootNode)) {
|
|
121
|
-
const spec = cap.node;
|
|
122
|
-
const pathNode = spec.namedChildren.find((c) => c.type === "interpreted_string_literal");
|
|
123
|
-
if (!pathNode) continue;
|
|
124
|
-
const importPath = pathNode.text.replace(/^["'`]|["'`]$/g, "");
|
|
125
|
-
const d = resolveGoImport(importPath);
|
|
126
|
-
if (!d) {
|
|
127
|
-
// not a repo package: stdlib (builtin) or an external module — record for dependency analysis
|
|
128
|
-
const line = pathNode.startPosition.row + 1;
|
|
129
|
-
const r = goSpecToPkg(importPath, { requires: owningModule?.requires || goRequires || [], ownModule: owningModule?.module || goModule || "" });
|
|
130
|
-
if (r) addExternalImport({ spec: importPath, pkg: r.pkg, builtin: r.builtin, ecosystem: "Go", kind: "go-import", line });
|
|
131
|
-
else addExternalImport({ spec: importPath, kind: "go-import", line, unresolved: true }); // own-module path with no matching dir
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
for (const f of dirFiles.get(d) || []) addImportEdge(f); // Go import = whole package (all files in the dir)
|
|
135
|
-
const aliasNode = spec.namedChildren.find((c) => c.type === "package_identifier");
|
|
136
|
-
const local = aliasNode ? aliasNode.text : importPath.split("/").pop();
|
|
137
|
-
if (local && local !== "_" && local !== ".") imports.set(local, { imported: "*", targetDir: d, goPackage: true });
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// HTML extractor (web reference graph, not a call graph — orchestrator skips pass 2 for it).
|
|
2
|
-
// Edges: `<link href>` / `<script src>` / `<img src>` → the referenced file (imports). Usage: class="…" / id="…"
|
|
3
|
-
// → recorded in htmlUsages, resolved (after all CSS parsed) to the CSS file(s) defining that selector.
|
|
4
|
-
export default {
|
|
5
|
-
family: "html",
|
|
6
|
-
grammars: ["html"],
|
|
7
|
-
exts: { ".html": "html", ".htm": "html" },
|
|
8
|
-
isWeb: true,
|
|
9
|
-
calls: "",
|
|
10
|
-
heritage: [],
|
|
11
|
-
|
|
12
|
-
pass1(ctx) {
|
|
13
|
-
const { grammar, tree, fileRel, caps, addImportEdge, resolveHref, htmlUsages } = ctx;
|
|
14
|
-
for (const cap of caps(grammar, `(attribute) @attr`, tree.rootNode)) {
|
|
15
|
-
const attr = cap.node;
|
|
16
|
-
const nameNode = attr.namedChildren.find((c) => c.type === "attribute_name"); if (!nameNode) continue;
|
|
17
|
-
const qv = attr.namedChildren.find((c) => c.type === "quoted_attribute_value");
|
|
18
|
-
const valNode = (qv && qv.namedChildren.find((c) => c.type === "attribute_value")) || attr.namedChildren.find((c) => c.type === "attribute_value");
|
|
19
|
-
const name = nameNode.text.toLowerCase(); const value = valNode ? valNode.text : "";
|
|
20
|
-
if (!value) continue;
|
|
21
|
-
const tagNode = attr.parent && attr.parent.namedChildren.find((c) => c.type === "tag_name");
|
|
22
|
-
const tag = tagNode ? tagNode.text.toLowerCase() : "";
|
|
23
|
-
if (name === "href" && tag === "link") { const t = resolveHref(fileRel, value); if (t) addImportEdge(t); }
|
|
24
|
-
else if (name === "src" && (tag === "script" || tag === "img")) { const t = resolveHref(fileRel, value); if (t) addImportEdge(t); }
|
|
25
|
-
else if (name === "class") { for (const cls of value.split(/\s+/).filter(Boolean)) htmlUsages.push({ htmlFile: fileRel, label: "." + cls }); }
|
|
26
|
-
else if (name === "id") { htmlUsages.push({ htmlFile: fileRel, label: "#" + value }); }
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// Java call resolution beyond bare same-file method names. Tree-sitter gives us the declared type of
|
|
2
|
-
// fields, parameters and locals; imports/same-package resolution then identifies the project type that
|
|
3
|
-
// owns a receiver method. This restores useful cross-file call flow without inventing external nodes or
|
|
4
|
-
// pretending to perform compiler-exact overload/dynamic-dispatch resolution.
|
|
5
|
-
const TYPE_DECLARATIONS = new Set([
|
|
6
|
-
"class_declaration", "interface_declaration", "enum_declaration",
|
|
7
|
-
"record_declaration", "annotation_type_declaration",
|
|
8
|
-
]);
|
|
9
|
-
const CALLABLE_DECLARATIONS = new Set([
|
|
10
|
-
"method_declaration", "constructor_declaration", "lambda_expression",
|
|
11
|
-
]);
|
|
12
|
-
const BINDING_DECLARATIONS = new Set([
|
|
13
|
-
"formal_parameter", "spread_parameter", "catch_formal_parameter",
|
|
14
|
-
"enhanced_for_statement", "resource",
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
const contains = (scope, node) => scope && node
|
|
18
|
-
&& scope.startIndex <= node.startIndex && scope.endIndex >= node.endIndex;
|
|
19
|
-
|
|
20
|
-
function nearest(node, accepted) {
|
|
21
|
-
for (let current = node?.parent, hops = 0; current && hops < 30; current = current.parent, hops++) {
|
|
22
|
-
if (accepted.has(current.type)) return current;
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function baseTypeName(typeNode, field) {
|
|
28
|
-
if (!typeNode) return null;
|
|
29
|
-
if (typeNode.type === "type_identifier") return typeNode.text;
|
|
30
|
-
if (typeNode.type === "scoped_type_identifier") return typeNode.text.split(".").pop() || null;
|
|
31
|
-
const nested = field(typeNode, "type") || field(typeNode, "element")
|
|
32
|
-
|| typeNode.namedChildren?.find((child) => [
|
|
33
|
-
"type_identifier", "scoped_type_identifier", "generic_type", "array_type", "annotated_type",
|
|
34
|
-
].includes(child.type));
|
|
35
|
-
return nested && nested !== typeNode ? baseTypeName(nested, field) : null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function collectBindings(root, field) {
|
|
39
|
-
const bindings = [];
|
|
40
|
-
const add = (nameNode, typeNode, declaration, scope, allowForward = false) => {
|
|
41
|
-
const typeName = baseTypeName(typeNode, field);
|
|
42
|
-
if (!nameNode?.text || !typeName || !scope) return;
|
|
43
|
-
bindings.push({
|
|
44
|
-
name: nameNode.text,
|
|
45
|
-
typeName,
|
|
46
|
-
declaration,
|
|
47
|
-
scope,
|
|
48
|
-
allowForward,
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
const stack = [root];
|
|
52
|
-
while (stack.length) {
|
|
53
|
-
const node = stack.pop();
|
|
54
|
-
if (!node) continue;
|
|
55
|
-
if (node.type === "field_declaration" || node.type === "local_variable_declaration") {
|
|
56
|
-
const type = field(node, "type");
|
|
57
|
-
const owner = node.type === "field_declaration"
|
|
58
|
-
? nearest(node, TYPE_DECLARATIONS)
|
|
59
|
-
: nearest(node, new Set(["block", ...CALLABLE_DECLARATIONS]));
|
|
60
|
-
for (const child of node.namedChildren || []) {
|
|
61
|
-
if (child.type !== "variable_declarator") continue;
|
|
62
|
-
add(field(child, "name"), type, node, owner, node.type === "field_declaration");
|
|
63
|
-
}
|
|
64
|
-
} else if (BINDING_DECLARATIONS.has(node.type)) {
|
|
65
|
-
const scope = node.type === "enhanced_for_statement"
|
|
66
|
-
? node
|
|
67
|
-
: nearest(node, CALLABLE_DECLARATIONS) || nearest(node, new Set(["catch_clause", "try_with_resources_statement"]));
|
|
68
|
-
add(field(node, "name"), field(node, "type"), node, scope);
|
|
69
|
-
}
|
|
70
|
-
for (const child of node.namedChildren || []) stack.push(child);
|
|
71
|
-
}
|
|
72
|
-
return bindings;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function receiverName(node, field) {
|
|
76
|
-
if (!node) return null;
|
|
77
|
-
if (node.type === "identifier" || node.type === "type_identifier") return node.text;
|
|
78
|
-
if (node.type === "scoped_type_identifier") return node.text.split(".").pop() || null;
|
|
79
|
-
if (node.type === "field_access") {
|
|
80
|
-
const object = field(node, "object");
|
|
81
|
-
if (["this", "super"].includes(object?.type)) return field(node, "field")?.text || null;
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function bindingAt(bindings, name, callNode) {
|
|
87
|
-
return bindings
|
|
88
|
-
.filter((item) => item.name === name && contains(item.scope, callNode)
|
|
89
|
-
&& (item.allowForward || item.declaration.startIndex <= callNode.startIndex))
|
|
90
|
-
.sort((left, right) => {
|
|
91
|
-
const leftSpan = left.scope.endIndex - left.scope.startIndex;
|
|
92
|
-
const rightSpan = right.scope.endIndex - right.scope.startIndex;
|
|
93
|
-
return leftSpan - rightSpan || right.declaration.startIndex - left.declaration.startIndex;
|
|
94
|
-
})[0] || null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function methodIn(file, name, argumentCount, symIdsByFileName, nodeById) {
|
|
98
|
-
const candidates = (symIdsByFileName.get(file)?.get(name) || [])
|
|
99
|
-
.map((id) => nodeById.get(id))
|
|
100
|
-
.filter((node) => ["method", "constructor"].includes(node?.symbol_kind));
|
|
101
|
-
if (candidates.length === 1) return candidates[0].id;
|
|
102
|
-
const exact = candidates.filter((node) => node.parameter_count === argumentCount);
|
|
103
|
-
return exact.length === 1 ? exact[0].id : null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function addJavaCalls({
|
|
107
|
-
grammar, tree, fileRel, caps, field, enclosing, links, nodeById,
|
|
108
|
-
symIdsByFileName, resolveCall, resolveJavaType,
|
|
109
|
-
}) {
|
|
110
|
-
const bindings = collectBindings(tree.rootNode, field);
|
|
111
|
-
for (const cap of caps(grammar, `(method_invocation) @call`, tree.rootNode)) {
|
|
112
|
-
const call = cap.node;
|
|
113
|
-
const name = field(call, "name")?.text;
|
|
114
|
-
const argumentCount = field(call, "arguments")?.namedChildren?.length ?? 0;
|
|
115
|
-
const caller = enclosing(fileRel, call.startPosition.row + 1);
|
|
116
|
-
if (!name || !caller) continue;
|
|
117
|
-
|
|
118
|
-
const receiver = field(call, "object");
|
|
119
|
-
let target = null;
|
|
120
|
-
let resolution = "unqualified";
|
|
121
|
-
if (!receiver || ["this", "super"].includes(receiver.type)) {
|
|
122
|
-
target = resolveCall(name, fileRel);
|
|
123
|
-
} else {
|
|
124
|
-
const localName = receiverName(receiver, field);
|
|
125
|
-
const binding = localName && bindingAt(bindings, localName, call);
|
|
126
|
-
const declaredType = binding?.typeName || localName;
|
|
127
|
-
const typeTarget = declaredType && resolveJavaType(declaredType, fileRel);
|
|
128
|
-
const targetFile = typeTarget && nodeById.get(typeTarget)?.source_file;
|
|
129
|
-
target = targetFile && methodIn(targetFile, name, argumentCount, symIdsByFileName, nodeById);
|
|
130
|
-
resolution = binding ? "receiver-declared-type" : "static-type";
|
|
131
|
-
}
|
|
132
|
-
if (!target || target === caller.id) continue;
|
|
133
|
-
links.push({
|
|
134
|
-
source: caller.id,
|
|
135
|
-
target,
|
|
136
|
-
relation: "calls",
|
|
137
|
-
confidence: "INFERRED",
|
|
138
|
-
line: call.startPosition.row + 1,
|
|
139
|
-
javaResolution: resolution,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
// Java extractor. Keeps file-level imports/calls while modelling the Java ownership and type system:
|
|
2
|
-
// classes/interfaces/enums/records own their methods, heritage distinguishes extends from implements,
|
|
3
|
-
// and project-local type references resolve to the declaration node (never to synthetic type-name nodes).
|
|
4
|
-
import { addJavaCalls } from "./lang-java-calls.js";
|
|
5
|
-
|
|
6
|
-
const TYPE_CORE = `
|
|
7
|
-
(class_declaration name: (identifier) @class)
|
|
8
|
-
(interface_declaration name: (identifier) @interface)
|
|
9
|
-
(enum_declaration name: (identifier) @enum)`;
|
|
10
|
-
// Keep grammar-version-dependent declarations separate: one unknown node type invalidates a whole query.
|
|
11
|
-
const TYPE_OPTIONAL = [
|
|
12
|
-
`(record_declaration name: (identifier) @record)`,
|
|
13
|
-
`(annotation_type_declaration name: (identifier) @annotation)`,
|
|
14
|
-
];
|
|
15
|
-
const MEMBERS = `
|
|
16
|
-
(method_declaration name: (identifier) @method)
|
|
17
|
-
(constructor_declaration name: (identifier) @constructor)
|
|
18
|
-
(field_declaration declarator: (variable_declarator name: (identifier) @field))`;
|
|
19
|
-
|
|
20
|
-
const TYPE_DECLARATIONS = new Set([
|
|
21
|
-
"class_declaration", "interface_declaration", "enum_declaration",
|
|
22
|
-
"record_declaration", "annotation_type_declaration",
|
|
23
|
-
]);
|
|
24
|
-
const FIELD_DECLARATIONS = new Set(["field_declaration"]);
|
|
25
|
-
|
|
26
|
-
const ancestor = (node, accepted) => {
|
|
27
|
-
let current = node?.parent;
|
|
28
|
-
for (let hops = 0; current && hops < 12; hops++, current = current.parent) {
|
|
29
|
-
if (accepted.has(current.type)) return current;
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const visibilityOf = (declaration, owner) => {
|
|
35
|
-
const modifiers = declaration?.namedChildren?.find((node) => node.type === "modifiers")?.text || "";
|
|
36
|
-
if (/\bprivate\b/.test(modifiers)) return "private";
|
|
37
|
-
if (/\bprotected\b/.test(modifiers)) return "protected";
|
|
38
|
-
if (/\bpublic\b/.test(modifiers)) return "public";
|
|
39
|
-
if (["interface_declaration", "annotation_type_declaration"].includes(owner?.type)) return "public";
|
|
40
|
-
return "package";
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const lineOf = (node) => node.startPosition.row + 1;
|
|
44
|
-
const parameterCountOf = (declaration) => {
|
|
45
|
-
const parameters = declaration?.childForFieldName?.("parameters");
|
|
46
|
-
if (!parameters) return null;
|
|
47
|
-
return (parameters.namedChildren || []).filter((node) => [
|
|
48
|
-
"formal_parameter", "spread_parameter", "receiver_parameter",
|
|
49
|
-
].includes(node.type)).length;
|
|
50
|
-
};
|
|
51
|
-
const symbolBaseId = (fileRel, nameNode) => `${fileRel}#${nameNode.text}@${lineOf(nameNode)}`;
|
|
52
|
-
const declarationKey = (node) => `${node?.startIndex ?? -1}:${node?.endIndex ?? -1}`;
|
|
53
|
-
const exactJavaTarget = (resolveJavaImport, parts) => {
|
|
54
|
-
const target = resolveJavaImport(parts);
|
|
55
|
-
const suffix = parts.join("/") + ".java";
|
|
56
|
-
return target && (target === suffix || target.endsWith("/" + suffix)) ? target : null;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default {
|
|
60
|
-
family: "java",
|
|
61
|
-
grammars: ["java"],
|
|
62
|
-
exts: { ".java": "java" },
|
|
63
|
-
isWeb: false,
|
|
64
|
-
customCalls: true,
|
|
65
|
-
calls: `(method_invocation name: (identifier) @callee)`,
|
|
66
|
-
// Capturing the base type_identifier (rather than the whole generic/scoped type) gives the shared
|
|
67
|
-
// resolver the imported/local declaration name. Each query is deliberately non-overlapping.
|
|
68
|
-
heritage: [
|
|
69
|
-
{ relation: "inherits", query: `(superclass (type_identifier) @super)` },
|
|
70
|
-
{ relation: "inherits", query: `(superclass (generic_type (type_identifier) @super))` },
|
|
71
|
-
{ relation: "inherits", query: `(superclass (scoped_type_identifier name: (type_identifier) @super))` },
|
|
72
|
-
{ relation: "inherits", query: `(superclass (generic_type (scoped_type_identifier name: (type_identifier) @super)))` },
|
|
73
|
-
{ relation: "inherits", query: `(extends_interfaces (type_list (type_identifier) @super))` },
|
|
74
|
-
{ relation: "inherits", query: `(extends_interfaces (type_list (generic_type (type_identifier) @super)))` },
|
|
75
|
-
{ relation: "inherits", query: `(extends_interfaces (type_list (scoped_type_identifier name: (type_identifier) @super)))` },
|
|
76
|
-
{ relation: "inherits", query: `(extends_interfaces (type_list (generic_type (scoped_type_identifier name: (type_identifier) @super))))` },
|
|
77
|
-
{ relation: "implements", query: `(super_interfaces (type_list (type_identifier) @super))` },
|
|
78
|
-
{ relation: "implements", query: `(super_interfaces (type_list (generic_type (type_identifier) @super)))` },
|
|
79
|
-
{ relation: "implements", query: `(super_interfaces (type_list (scoped_type_identifier name: (type_identifier) @super)))` },
|
|
80
|
-
{ relation: "implements", query: `(super_interfaces (type_list (generic_type (scoped_type_identifier name: (type_identifier) @super))))` },
|
|
81
|
-
],
|
|
82
|
-
|
|
83
|
-
pass1(ctx) {
|
|
84
|
-
const {
|
|
85
|
-
grammar, tree, fileRel, caps, field, addSym, addImportEdge, imports,
|
|
86
|
-
resolveJavaImport, fileSet, links, nodeIds, addExternalImport,
|
|
87
|
-
} = ctx;
|
|
88
|
-
const ownerIds = new Map();
|
|
89
|
-
const addJavaSym = (nameNode, callable, extra) => {
|
|
90
|
-
const base = symbolBaseId(fileRel, nameNode);
|
|
91
|
-
// Compact/generated Java can put an owner, constructor and overloads with the same name on one
|
|
92
|
-
// line. Preserve historical IDs normally; disambiguate only an actual collision by source column.
|
|
93
|
-
const id = nodeIds.has(base) ? `${base}:c${nameNode.startPosition.column + 1}` : base;
|
|
94
|
-
addSym(nameNode.text, lineOf(nameNode), callable, {
|
|
95
|
-
...extra,
|
|
96
|
-
selectionNode: nameNode,
|
|
97
|
-
...(id === base ? {} : { idSuffix: id.slice(base.length) }),
|
|
98
|
-
});
|
|
99
|
-
return nodeIds.has(id) ? id : null;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// Add owners first even though tree-sitter captures are source-ordered. This makes ownership edges
|
|
103
|
-
// deterministic for nested types and methods declared before/after other nested declarations.
|
|
104
|
-
for (const src of [TYPE_CORE, ...TYPE_OPTIONAL]) {
|
|
105
|
-
for (const cap of caps(grammar, src, tree.rootNode)) {
|
|
106
|
-
const declaration = cap.node.parent;
|
|
107
|
-
const id = addJavaSym(cap.node, false, {
|
|
108
|
-
sourceNode: cap.node.parent,
|
|
109
|
-
symbolKind: cap.name,
|
|
110
|
-
});
|
|
111
|
-
if (id) ownerIds.set(declarationKey(declaration), id);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
for (const cap of caps(grammar, MEMBERS, tree.rootNode)) {
|
|
116
|
-
const declaration = cap.name === "field" ? ancestor(cap.node, FIELD_DECLARATIONS) : cap.node.parent;
|
|
117
|
-
const owner = ancestor(cap.node, TYPE_DECLARATIONS);
|
|
118
|
-
const ownerNameNode = owner && field(owner, "name");
|
|
119
|
-
const memberKind = cap.name === "constructor" ? "constructor" : cap.name;
|
|
120
|
-
const memberId = addJavaSym(cap.node, cap.name !== "field", {
|
|
121
|
-
sourceNode: declaration,
|
|
122
|
-
symbolKind: memberKind,
|
|
123
|
-
...(["method", "constructor"].includes(memberKind) ? { parameterCount: parameterCountOf(declaration) } : {}),
|
|
124
|
-
...(ownerNameNode ? { memberOf: ownerNameNode.text } : {}),
|
|
125
|
-
visibility: visibilityOf(declaration, owner),
|
|
126
|
-
});
|
|
127
|
-
if (!ownerNameNode || cap.name === "field") continue;
|
|
128
|
-
const ownerId = ownerIds.get(declarationKey(owner));
|
|
129
|
-
if (ownerId && memberId && ownerId !== memberId) {
|
|
130
|
-
links.push({ source: ownerId, target: memberId, relation: "method", confidence: "EXTRACTED" });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const wildcardPackages = [];
|
|
135
|
-
const staticWildcardTargets = [];
|
|
136
|
-
const importStatements = caps(grammar, `(import_declaration) @imp`, tree.rootNode);
|
|
137
|
-
for (const cap of importStatements) {
|
|
138
|
-
const match = cap.node.text.match(/^\s*import\s+(static\s+)?([\w.]+?)(\.\*)?\s*;?\s*$/);
|
|
139
|
-
if (!match) continue;
|
|
140
|
-
const isStatic = !!match[1];
|
|
141
|
-
const parts = match[2].split(".").filter(Boolean);
|
|
142
|
-
const wildcard = !!match[3];
|
|
143
|
-
const line = lineOf(cap.node);
|
|
144
|
-
if (!isStatic && wildcard) {
|
|
145
|
-
wildcardPackages.push(parts);
|
|
146
|
-
const packagePath = `${parts.join("/")}/`;
|
|
147
|
-
const projectLocal = [...fileSet].some((file) => file.startsWith(packagePath) || file.includes(`/${packagePath}`));
|
|
148
|
-
if (!projectLocal) addExternalImport({ spec: `${parts.join(".")}.*`, pkg: parts.join("."), builtin: ["java", "jdk", "sun"].includes(parts[0]), ecosystem: "Maven", kind: "java-import", line });
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (!isStatic) {
|
|
152
|
-
const target = exactJavaTarget(resolveJavaImport, parts);
|
|
153
|
-
if (!target) {
|
|
154
|
-
addExternalImport({ spec: parts.join("."), pkg: parts.join("."), builtin: ["java", "jdk", "sun"].includes(parts[0]), ecosystem: "Maven", kind: "java-import", line });
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const local = parts[parts.length - 1];
|
|
158
|
-
addImportEdge(target, { line, specifier: parts.join("."), compileOnly: true });
|
|
159
|
-
imports.set(local, { imported: local, targetFile: target });
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Static imports end in a member name. Walk prefixes until the declaring project class resolves.
|
|
164
|
-
let target = null; let classParts = null;
|
|
165
|
-
const max = wildcard ? parts.length : parts.length - 1;
|
|
166
|
-
for (let take = max; take > 0 && !target; take--) {
|
|
167
|
-
const candidate = parts.slice(0, take);
|
|
168
|
-
target = exactJavaTarget(resolveJavaImport, candidate);
|
|
169
|
-
if (target) classParts = candidate;
|
|
170
|
-
}
|
|
171
|
-
if (!target) {
|
|
172
|
-
addExternalImport({ spec: parts.join("."), pkg: parts.join("."), builtin: ["java", "jdk", "sun"].includes(parts[0]), ecosystem: "Maven", kind: "java-static-import", line });
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
addImportEdge(target, { line, specifier: `${isStatic ? "static " : ""}${parts.join(".")}${wildcard ? ".*" : ""}`, compileOnly: true });
|
|
176
|
-
if (wildcard) staticWildcardTargets.push(target);
|
|
177
|
-
else {
|
|
178
|
-
const member = parts[classParts.length];
|
|
179
|
-
if (member) imports.set(member, { imported: member, targetFile: target });
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Seed the shared pass-2 resolver with Java's implicit same-package types and wildcard imports.
|
|
184
|
-
// Exact-path validation is important: the general basename fallback is useful for explicit imports,
|
|
185
|
-
// but must not bind an unimported Foo to an unrelated package's Foo.java.
|
|
186
|
-
const slash = fileRel.lastIndexOf("/");
|
|
187
|
-
const ownDir = slash < 0 ? "" : fileRel.slice(0, slash);
|
|
188
|
-
const bindType = (name) => {
|
|
189
|
-
if (!name || imports.has(name)) return;
|
|
190
|
-
const samePackage = `${ownDir ? ownDir + "/" : ""}${name}.java`;
|
|
191
|
-
if (fileSet.has(samePackage)) {
|
|
192
|
-
imports.set(name, { imported: name, targetFile: samePackage });
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
for (const pkg of wildcardPackages) {
|
|
196
|
-
const target = exactJavaTarget(resolveJavaImport, [...pkg, name]);
|
|
197
|
-
if (target) { imports.set(name, { imported: name, targetFile: target }); return; }
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
for (const cap of caps(grammar, `(type_identifier) @type`, tree.rootNode)) bindType(cap.node.text);
|
|
201
|
-
for (const cap of caps(grammar, `(scoped_type_identifier) @type`, tree.rootNode)) {
|
|
202
|
-
const parts = cap.node.text.split(".").filter(Boolean);
|
|
203
|
-
const target = exactJavaTarget(resolveJavaImport, parts);
|
|
204
|
-
const name = parts[parts.length - 1];
|
|
205
|
-
if (target && name && !imports.has(name)) imports.set(name, { imported: name, targetFile: target });
|
|
206
|
-
}
|
|
207
|
-
if (staticWildcardTargets.length === 1) {
|
|
208
|
-
for (const cap of caps(grammar, `(method_invocation name: (identifier) @callee)`, tree.rootNode)) {
|
|
209
|
-
if (!imports.has(cap.node.text)) imports.set(cap.node.text, { imported: cap.node.text, targetFile: staticWildcardTargets[0] });
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
pass2: addJavaCalls,
|
|
215
|
-
};
|