fix(extraction): land upstream declaration initializer walks (#1511) (#1802)

Squash danusha2345's PR #1511 at d282f9e8 onto main 8c9c4761,
preserving its nine non-merge commits and main's existing Unreleased notes.
Calls in Kotlin, Java, TS/JS, Scala, Rust and Python declaration initializers
now retain the owner established by the upstream regression expectations.
Include the upstream CFML, dynamic-dispatch summary and viewer follow-ups.

Linux fail-to-pass validation (Node 22.19.0, rebuilt dist and native kernel):
- Before: TS load belonged to file:app.ts; Python/Kotlin/Scala/Rust calls
  vanished; Java lost the field-lambda, anonymous override and eager calls.
- After: all six languages PASS; 12 native/WASM LF/CRLF parity checks PASS.
- Focused initializer regressions: 10 passed with CODEGRAPH_KERNEL=0 and
  10 passed with the kernel enabled; Kotlin's grammar fallback is recorded.
- Related regression suites: 879 passed, 1 skipped across 15 test files.
- Evidence: /workspace/cg-1510-repro/before and /workspace/cg-1510-repro/after
  (combined test output: after/vitest.log).

Fixes #1510
Supersedes #1511

Co-authored-by: Colby McHenry <colbymchenry@users.noreply.github.com>
Co-authored-by: danusha2345 <ewidusoc498@gmail.com>
This commit is contained in:
Colby Mchenry
2026-09-08 17:33:45 -05:00
committed by GitHub
co-authored by Colby McHenry danusha2345
parent 8c9c4761b0
commit 9181dd1ef3
25 changed files with 884 additions and 108 deletions
+25 -6
View File
@@ -2204,6 +2204,12 @@ export class QueryBuilder {
* build script does its work on the way down the file. `instantiates` counts
* the same way — `new Server(...)` at module scope is the same act.
*
* A call made while initializing a module-level `variable` / `constant` —
* `const service = new Service()`, `app = FastAPI()` — is attributed to the
* declared name (#693), not to the file, so the file's own edges alone would
* miss most of what a real entry point runs. Those names are the file's
* top-level code too, so `tops` counts them alongside the file node.
*
* Ranking multiplies the two things an entry point does: it runs (calls), and
* it wires the project together (distinct other files its symbols reach). One
* alone is misleading — a registration table makes hundreds of module-level
@@ -2216,12 +2222,25 @@ export class QueryBuilder {
if (limit <= 0) return [];
return this.db
.prepare(
`WITH runs AS (
SELECT e.source AS id, COUNT(*) AS calls
FROM edges e
JOIN nodes n ON n.id = e.source
WHERE n.kind = 'file' AND e.kind IN ('calls', 'instantiates')
GROUP BY e.source
`WITH tops AS (
SELECT n.id AS file_id, n.id AS src
FROM nodes n
WHERE n.kind = 'file'
UNION ALL
SELECT c.source AS file_id, c.target AS src
FROM edges c
JOIN nodes f ON f.id = c.source
JOIN nodes v ON v.id = c.target
WHERE c.kind = 'contains'
AND f.kind = 'file'
AND v.kind IN ('variable', 'constant')
),
runs AS (
SELECT t.file_id AS id, COUNT(*) AS calls
FROM tops t
JOIN edges e ON e.source = t.src
WHERE e.kind IN ('calls', 'instantiates')
GROUP BY t.file_id
),
cand AS (
SELECT r.id AS id, n.file_path AS fp, r.calls AS calls