gitnexus 1.6.3-rc.2 → 1.6.3-rc.21

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.
Files changed (130) hide show
  1. package/dist/_shared/graph/types.d.ts +16 -0
  2. package/dist/_shared/graph/types.d.ts.map +1 -1
  3. package/dist/_shared/index.d.ts +41 -1
  4. package/dist/_shared/index.d.ts.map +1 -1
  5. package/dist/_shared/index.js +28 -0
  6. package/dist/_shared/index.js.map +1 -1
  7. package/dist/_shared/scope-resolution/def-index.d.ts +36 -0
  8. package/dist/_shared/scope-resolution/def-index.d.ts.map +1 -0
  9. package/dist/_shared/scope-resolution/def-index.js +51 -0
  10. package/dist/_shared/scope-resolution/def-index.js.map +1 -0
  11. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts +139 -0
  12. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts.map +1 -0
  13. package/dist/_shared/scope-resolution/finalize-algorithm.js +479 -0
  14. package/dist/_shared/scope-resolution/finalize-algorithm.js.map +1 -0
  15. package/dist/_shared/scope-resolution/method-dispatch-index.d.ts +80 -0
  16. package/dist/_shared/scope-resolution/method-dispatch-index.d.ts.map +1 -0
  17. package/dist/_shared/scope-resolution/method-dispatch-index.js +79 -0
  18. package/dist/_shared/scope-resolution/method-dispatch-index.js.map +1 -0
  19. package/dist/_shared/scope-resolution/module-scope-index.d.ts +46 -0
  20. package/dist/_shared/scope-resolution/module-scope-index.d.ts.map +1 -0
  21. package/dist/_shared/scope-resolution/module-scope-index.js +58 -0
  22. package/dist/_shared/scope-resolution/module-scope-index.js.map +1 -0
  23. package/dist/_shared/scope-resolution/parsed-file.d.ts +64 -0
  24. package/dist/_shared/scope-resolution/parsed-file.d.ts.map +1 -0
  25. package/dist/_shared/scope-resolution/parsed-file.js +42 -0
  26. package/dist/_shared/scope-resolution/parsed-file.js.map +1 -0
  27. package/dist/_shared/scope-resolution/position-index.d.ts +62 -0
  28. package/dist/_shared/scope-resolution/position-index.d.ts.map +1 -0
  29. package/dist/_shared/scope-resolution/position-index.js +134 -0
  30. package/dist/_shared/scope-resolution/position-index.js.map +1 -0
  31. package/dist/_shared/scope-resolution/qualified-name-index.d.ts +44 -0
  32. package/dist/_shared/scope-resolution/qualified-name-index.d.ts.map +1 -0
  33. package/dist/_shared/scope-resolution/qualified-name-index.js +75 -0
  34. package/dist/_shared/scope-resolution/qualified-name-index.js.map +1 -0
  35. package/dist/_shared/scope-resolution/reference-site.d.ts +67 -0
  36. package/dist/_shared/scope-resolution/reference-site.d.ts.map +1 -0
  37. package/dist/_shared/scope-resolution/reference-site.js +24 -0
  38. package/dist/_shared/scope-resolution/reference-site.js.map +1 -0
  39. package/dist/_shared/scope-resolution/registries/class-registry.d.ts +27 -0
  40. package/dist/_shared/scope-resolution/registries/class-registry.d.ts.map +1 -0
  41. package/dist/_shared/scope-resolution/registries/class-registry.js +30 -0
  42. package/dist/_shared/scope-resolution/registries/class-registry.js.map +1 -0
  43. package/dist/_shared/scope-resolution/registries/context.d.ts +69 -0
  44. package/dist/_shared/scope-resolution/registries/context.d.ts.map +1 -0
  45. package/dist/_shared/scope-resolution/registries/context.js +44 -0
  46. package/dist/_shared/scope-resolution/registries/context.js.map +1 -0
  47. package/dist/_shared/scope-resolution/registries/evidence.d.ts +56 -0
  48. package/dist/_shared/scope-resolution/registries/evidence.d.ts.map +1 -0
  49. package/dist/_shared/scope-resolution/registries/evidence.js +150 -0
  50. package/dist/_shared/scope-resolution/registries/evidence.js.map +1 -0
  51. package/dist/_shared/scope-resolution/registries/field-registry.d.ts +26 -0
  52. package/dist/_shared/scope-resolution/registries/field-registry.d.ts.map +1 -0
  53. package/dist/_shared/scope-resolution/registries/field-registry.js +31 -0
  54. package/dist/_shared/scope-resolution/registries/field-registry.js.map +1 -0
  55. package/dist/_shared/scope-resolution/registries/lookup-core.d.ts +81 -0
  56. package/dist/_shared/scope-resolution/registries/lookup-core.d.ts.map +1 -0
  57. package/dist/_shared/scope-resolution/registries/lookup-core.js +332 -0
  58. package/dist/_shared/scope-resolution/registries/lookup-core.js.map +1 -0
  59. package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts +33 -0
  60. package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts.map +1 -0
  61. package/dist/_shared/scope-resolution/registries/lookup-qualified.js +56 -0
  62. package/dist/_shared/scope-resolution/registries/lookup-qualified.js.map +1 -0
  63. package/dist/_shared/scope-resolution/registries/method-registry.d.ts +36 -0
  64. package/dist/_shared/scope-resolution/registries/method-registry.d.ts.map +1 -0
  65. package/dist/_shared/scope-resolution/registries/method-registry.js +32 -0
  66. package/dist/_shared/scope-resolution/registries/method-registry.js.map +1 -0
  67. package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts +43 -0
  68. package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts.map +1 -0
  69. package/dist/_shared/scope-resolution/registries/tie-breaks.js +60 -0
  70. package/dist/_shared/scope-resolution/registries/tie-breaks.js.map +1 -0
  71. package/dist/_shared/scope-resolution/resolve-type-ref.d.ts +53 -0
  72. package/dist/_shared/scope-resolution/resolve-type-ref.d.ts.map +1 -0
  73. package/dist/_shared/scope-resolution/resolve-type-ref.js +126 -0
  74. package/dist/_shared/scope-resolution/resolve-type-ref.js.map +1 -0
  75. package/dist/_shared/scope-resolution/scope-id.d.ts +43 -0
  76. package/dist/_shared/scope-resolution/scope-id.d.ts.map +1 -0
  77. package/dist/_shared/scope-resolution/scope-id.js +46 -0
  78. package/dist/_shared/scope-resolution/scope-id.js.map +1 -0
  79. package/dist/_shared/scope-resolution/scope-tree.d.ts +61 -0
  80. package/dist/_shared/scope-resolution/scope-tree.d.ts.map +1 -0
  81. package/dist/_shared/scope-resolution/scope-tree.js +186 -0
  82. package/dist/_shared/scope-resolution/scope-tree.js.map +1 -0
  83. package/dist/_shared/scope-resolution/shadow/aggregate.d.ts +63 -0
  84. package/dist/_shared/scope-resolution/shadow/aggregate.d.ts.map +1 -0
  85. package/dist/_shared/scope-resolution/shadow/aggregate.js +122 -0
  86. package/dist/_shared/scope-resolution/shadow/aggregate.js.map +1 -0
  87. package/dist/_shared/scope-resolution/shadow/diff.d.ts +59 -0
  88. package/dist/_shared/scope-resolution/shadow/diff.d.ts.map +1 -0
  89. package/dist/_shared/scope-resolution/shadow/diff.js +79 -0
  90. package/dist/_shared/scope-resolution/shadow/diff.js.map +1 -0
  91. package/dist/_shared/scope-resolution/types.d.ts +156 -0
  92. package/dist/_shared/scope-resolution/types.d.ts.map +1 -1
  93. package/dist/cli/analyze.d.ts +15 -0
  94. package/dist/cli/analyze.js +22 -1
  95. package/dist/cli/index.js +4 -0
  96. package/dist/cli/list.js +11 -1
  97. package/dist/core/ingestion/emit-references.d.ts +88 -0
  98. package/dist/core/ingestion/emit-references.js +229 -0
  99. package/dist/core/ingestion/finalize-orchestrator.d.ts +63 -0
  100. package/dist/core/ingestion/finalize-orchestrator.js +139 -0
  101. package/dist/core/ingestion/framework-detection.js +6 -2
  102. package/dist/core/ingestion/import-target-adapter.d.ts +73 -0
  103. package/dist/core/ingestion/import-target-adapter.js +95 -0
  104. package/dist/core/ingestion/language-provider.d.ts +187 -1
  105. package/dist/core/ingestion/model/scope-resolution-indexes.d.ts +59 -0
  106. package/dist/core/ingestion/model/scope-resolution-indexes.js +42 -0
  107. package/dist/core/ingestion/model/semantic-model.d.ts +25 -0
  108. package/dist/core/ingestion/model/semantic-model.js +16 -0
  109. package/dist/core/ingestion/parsing-processor.d.ts +9 -0
  110. package/dist/core/ingestion/parsing-processor.js +10 -0
  111. package/dist/core/ingestion/registry-primary-flag.d.ts +59 -0
  112. package/dist/core/ingestion/registry-primary-flag.js +78 -0
  113. package/dist/core/ingestion/scope-extractor-bridge.d.ts +32 -0
  114. package/dist/core/ingestion/scope-extractor-bridge.js +44 -0
  115. package/dist/core/ingestion/scope-extractor.d.ts +87 -0
  116. package/dist/core/ingestion/scope-extractor.js +603 -0
  117. package/dist/core/ingestion/shadow-harness.d.ts +113 -0
  118. package/dist/core/ingestion/shadow-harness.js +148 -0
  119. package/dist/core/ingestion/workers/parse-worker.d.ts +9 -0
  120. package/dist/core/ingestion/workers/parse-worker.js +20 -1
  121. package/dist/core/run-analyze.d.ts +21 -0
  122. package/dist/core/run-analyze.js +15 -4
  123. package/dist/core/search/phase-timer.d.ts +72 -0
  124. package/dist/core/search/phase-timer.js +106 -0
  125. package/dist/mcp/local/local-backend.js +70 -8
  126. package/dist/storage/git.d.ts +25 -0
  127. package/dist/storage/git.js +52 -0
  128. package/dist/storage/repo-manager.d.ts +70 -1
  129. package/dist/storage/repo-manager.js +107 -5
  130. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method-dispatch-index.js","sourceRoot":"","sources":["../../src/scope-resolution/method-dispatch-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAyDH,+EAA+E;AAE/E,MAAM,UAAU,wBAAwB,CAAC,KAA0B;IACjE,MAAM,eAAe,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC3D,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAChD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAqB,CAAC;IAE/C,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACnC,sEAAsE;QACtE,2DAA2D;QAC3D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACxC,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC7D,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;YAClD,IAAI,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAA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AC5D,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `ModuleScopeIndex` — O(1) `filePath → moduleScopeId` lookup.
3
+ *
4
+ * Every file parsed produces exactly one `Module` scope at its root. The
5
+ * finalize algorithm needs to resolve `ImportEdge.targetFile` to a concrete
6
+ * module scope id in constant time during the link pass; this index is that
7
+ * mapping.
8
+ *
9
+ * Part of RFC #909 Ring 2 SHARED — #913.
10
+ *
11
+ * Consumed by: #915 (SCC finalize link pass), #923 (shadow harness when
12
+ * resolving callsite file → enclosing module).
13
+ */
14
+ import type { ScopeId } from './types.js';
15
+ export interface ModuleScopeIndex {
16
+ readonly byFilePath: ReadonlyMap<string, ScopeId>;
17
+ readonly size: number;
18
+ get(filePath: string): ScopeId | undefined;
19
+ has(filePath: string): boolean;
20
+ }
21
+ export interface ModuleScopeEntry {
22
+ readonly filePath: string;
23
+ readonly moduleScopeId: ScopeId;
24
+ }
25
+ /**
26
+ * Build a `ModuleScopeIndex` from a flat list of `{ filePath, moduleScopeId }`
27
+ * pairs.
28
+ *
29
+ * **Collision policy: first-write-wins.** A file should appear exactly once
30
+ * in a single ingestion run; collisions indicate the same file was parsed
31
+ * twice or a `filePath` normalization bug upstream. Dropping the later
32
+ * entry preserves the first-stable id the rest of the pipeline may already
33
+ * have registered against.
34
+ *
35
+ * **Caller contract: filePath keys must be pre-normalized.** This index
36
+ * keys on the raw `filePath` string and does NOT canonicalize separators,
37
+ * case, or trailing slashes. Callers upstream of this function must agree
38
+ * on a canonical form (typically repo-root-relative, POSIX separators,
39
+ * no trailing slash) before constructing entries — otherwise `C:\foo\bar.ts`,
40
+ * `C:/foo/bar.ts`, and `foo/bar.ts` will all hash to distinct buckets and
41
+ * `get()` will miss.
42
+ *
43
+ * Pure function — safe to call repeatedly; no side effects.
44
+ */
45
+ export declare function buildModuleScopeIndex(entries: readonly ModuleScopeEntry[]): ModuleScopeIndex;
46
+ //# sourceMappingURL=module-scope-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-scope-index.d.ts","sourceRoot":"","sources":["../../src/scope-resolution/module-scope-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAC3C,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,gBAAgB,CAO5F"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * `ModuleScopeIndex` — O(1) `filePath → moduleScopeId` lookup.
3
+ *
4
+ * Every file parsed produces exactly one `Module` scope at its root. The
5
+ * finalize algorithm needs to resolve `ImportEdge.targetFile` to a concrete
6
+ * module scope id in constant time during the link pass; this index is that
7
+ * mapping.
8
+ *
9
+ * Part of RFC #909 Ring 2 SHARED — #913.
10
+ *
11
+ * Consumed by: #915 (SCC finalize link pass), #923 (shadow harness when
12
+ * resolving callsite file → enclosing module).
13
+ */
14
+ /**
15
+ * Build a `ModuleScopeIndex` from a flat list of `{ filePath, moduleScopeId }`
16
+ * pairs.
17
+ *
18
+ * **Collision policy: first-write-wins.** A file should appear exactly once
19
+ * in a single ingestion run; collisions indicate the same file was parsed
20
+ * twice or a `filePath` normalization bug upstream. Dropping the later
21
+ * entry preserves the first-stable id the rest of the pipeline may already
22
+ * have registered against.
23
+ *
24
+ * **Caller contract: filePath keys must be pre-normalized.** This index
25
+ * keys on the raw `filePath` string and does NOT canonicalize separators,
26
+ * case, or trailing slashes. Callers upstream of this function must agree
27
+ * on a canonical form (typically repo-root-relative, POSIX separators,
28
+ * no trailing slash) before constructing entries — otherwise `C:\foo\bar.ts`,
29
+ * `C:/foo/bar.ts`, and `foo/bar.ts` will all hash to distinct buckets and
30
+ * `get()` will miss.
31
+ *
32
+ * Pure function — safe to call repeatedly; no side effects.
33
+ */
34
+ export function buildModuleScopeIndex(entries) {
35
+ const byFilePath = new Map();
36
+ for (const { filePath, moduleScopeId } of entries) {
37
+ if (byFilePath.has(filePath))
38
+ continue; // first-write-wins
39
+ byFilePath.set(filePath, moduleScopeId);
40
+ }
41
+ return wrapIndex(byFilePath);
42
+ }
43
+ // ─── Internal ───────────────────────────────────────────────────────────────
44
+ function wrapIndex(byFilePath) {
45
+ return {
46
+ byFilePath,
47
+ get size() {
48
+ return byFilePath.size;
49
+ },
50
+ get(filePath) {
51
+ return byFilePath.get(filePath);
52
+ },
53
+ has(filePath) {
54
+ return byFilePath.has(filePath);
55
+ },
56
+ };
57
+ }
58
+ //# sourceMappingURL=module-scope-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-scope-index.js","sourceRoot":"","sources":["../../src/scope-resolution/module-scope-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgBH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAoC;IACxE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC9C,KAAK,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,OAAO,EAAE,CAAC;QAClD,IAAI,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,SAAS,CAAC,mBAAmB;QAC3D,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC;AAED,+EAA+E;AAE/E,SAAS,SAAS,CAAC,UAAgC;IACjD,OAAO;QACL,UAAU;QACV,IAAI,IAAI;YACN,OAAO,UAAU,CAAC,IAAI,CAAC;QACzB,CAAC;QACD,GAAG,CAAC,QAAgB;YAClB,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;QACD,GAAG,CAAC,QAAgB;YAClB,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `ParsedFile` — the per-file artifact produced by `ScopeExtractor`
3
+ * (RFC §3.2 Phase 1; Ring 2 PKG #919).
4
+ *
5
+ * The boundary between Phase 1 (extraction, per-file, parallelizable) and
6
+ * Phase 2 (finalize, cross-file). One `ParsedFile` is emitted per source
7
+ * file; the finalize orchestrator (#921) collects them into a workspace-
8
+ * wide set and feeds them to the shared `finalize` algorithm (#915).
9
+ *
10
+ * ## Shape
11
+ *
12
+ * - `scopes` — every `Scope` created for this file, in tree-
13
+ * topological order (module first, then children).
14
+ * `Scope.bindings` carry **local-only** bindings at
15
+ * this stage; finalize merges imports/wildcards on top.
16
+ * - `parsedImports` — raw `ParsedImport[]` for this file; finalize
17
+ * resolves each to a concrete `ImportEdge`.
18
+ * - `localDefs` — defs structurally declared in this file. A
19
+ * superset of every `Scope.ownedDefs` union.
20
+ * Listed separately so `finalize` can dedup-index
21
+ * without re-walking scopes.
22
+ * - `referenceSites` — pre-resolution usage facts; populated by the
23
+ * resolution phase into `ReferenceIndex`.
24
+ *
25
+ * ## What `ParsedFile` deliberately does NOT carry
26
+ *
27
+ * - Linked `ImportEdge`s. Those are finalize output.
28
+ * - A `ScopeTree` instance. Callers build one from `scopes` (cheap —
29
+ * `buildScopeTree(parsedFile.scopes)`). Keeping the ParsedFile flat
30
+ * makes IPC serialization from worker threads straightforward.
31
+ * - Merged module-scope bindings. Finalize owns that materialization.
32
+ *
33
+ * ## Compatibility with `FinalizeFile`
34
+ *
35
+ * `FinalizeFile` (defined in `./finalize-algorithm.ts`) is a structural
36
+ * subset of `ParsedFile` — `filePath`, `moduleScope`, `parsedImports`,
37
+ * `localDefs`. A `ParsedFile` is trivially convertible to a `FinalizeFile`
38
+ * by picking those four fields, so the finalize orchestrator threads
39
+ * ParsedFile through to the shared algorithm without shape-shifting.
40
+ */
41
+ import type { Scope, ScopeId } from './types.js';
42
+ import type { ParsedImport } from './types.js';
43
+ import type { SymbolDefinition } from './symbol-definition.js';
44
+ import type { ReferenceSite } from './reference-site.js';
45
+ export interface ParsedFile {
46
+ readonly filePath: string;
47
+ /** `Scope.id` of the file's root `Module` scope. */
48
+ readonly moduleScope: ScopeId;
49
+ /**
50
+ * All scopes in this file, typically emitted in tree-topological order.
51
+ * Caller reconstructs a `ScopeTree` via `buildScopeTree(scopes)` when
52
+ * navigation or invariant re-validation is needed.
53
+ */
54
+ readonly scopes: readonly Scope[];
55
+ readonly parsedImports: readonly ParsedImport[];
56
+ /**
57
+ * All defs structurally declared in this file (classes, methods, fields,
58
+ * variables). Mirrors the union of `Scope.ownedDefs` across `scopes`,
59
+ * pre-flattened for O(N) consumption by finalize.
60
+ */
61
+ readonly localDefs: readonly SymbolDefinition[];
62
+ readonly referenceSites: readonly ReferenceSite[];
63
+ }
64
+ //# sourceMappingURL=parsed-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed-file.d.ts","sourceRoot":"","sources":["../../src/scope-resolution/parsed-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oDAAoD;IACpD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;IAChD;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAChD,QAAQ,CAAC,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;CACnD"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * `ParsedFile` — the per-file artifact produced by `ScopeExtractor`
3
+ * (RFC §3.2 Phase 1; Ring 2 PKG #919).
4
+ *
5
+ * The boundary between Phase 1 (extraction, per-file, parallelizable) and
6
+ * Phase 2 (finalize, cross-file). One `ParsedFile` is emitted per source
7
+ * file; the finalize orchestrator (#921) collects them into a workspace-
8
+ * wide set and feeds them to the shared `finalize` algorithm (#915).
9
+ *
10
+ * ## Shape
11
+ *
12
+ * - `scopes` — every `Scope` created for this file, in tree-
13
+ * topological order (module first, then children).
14
+ * `Scope.bindings` carry **local-only** bindings at
15
+ * this stage; finalize merges imports/wildcards on top.
16
+ * - `parsedImports` — raw `ParsedImport[]` for this file; finalize
17
+ * resolves each to a concrete `ImportEdge`.
18
+ * - `localDefs` — defs structurally declared in this file. A
19
+ * superset of every `Scope.ownedDefs` union.
20
+ * Listed separately so `finalize` can dedup-index
21
+ * without re-walking scopes.
22
+ * - `referenceSites` — pre-resolution usage facts; populated by the
23
+ * resolution phase into `ReferenceIndex`.
24
+ *
25
+ * ## What `ParsedFile` deliberately does NOT carry
26
+ *
27
+ * - Linked `ImportEdge`s. Those are finalize output.
28
+ * - A `ScopeTree` instance. Callers build one from `scopes` (cheap —
29
+ * `buildScopeTree(parsedFile.scopes)`). Keeping the ParsedFile flat
30
+ * makes IPC serialization from worker threads straightforward.
31
+ * - Merged module-scope bindings. Finalize owns that materialization.
32
+ *
33
+ * ## Compatibility with `FinalizeFile`
34
+ *
35
+ * `FinalizeFile` (defined in `./finalize-algorithm.ts`) is a structural
36
+ * subset of `ParsedFile` — `filePath`, `moduleScope`, `parsedImports`,
37
+ * `localDefs`. A `ParsedFile` is trivially convertible to a `FinalizeFile`
38
+ * by picking those four fields, so the finalize orchestrator threads
39
+ * ParsedFile through to the shared algorithm without shape-shifting.
40
+ */
41
+ export {};
42
+ //# sourceMappingURL=parsed-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed-file.js","sourceRoot":"","sources":["../../src/scope-resolution/parsed-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `PositionIndex` — O(log N_file) scope-at-position lookup
3
+ * (RFC §3.1; Ring 2 SHARED #912).
4
+ *
5
+ * Per-file sorted array of `(range, scopeId)` entries, sorted by start
6
+ * position ASC (`startLine`, then `startCol`). `atPosition(filePath, line,
7
+ * col)` binary-searches for the last entry whose start ≤ (line, col), then
8
+ * scans backward through the sorted prefix and returns the first entry
9
+ * whose range contains the query position.
10
+ *
11
+ * **Why this works.** `ScopeTree`'s invariants (parent strictly contains
12
+ * child; siblings don't overlap) guarantee that the scopes containing a
13
+ * given point form an **ancestor chain**. When scanning backward through
14
+ * entries sorted by start position ASC, the first scope we find that
15
+ * contains the query is the innermost one — any deeper-starting scope
16
+ * that also contained the query would appear *later* in the sorted array,
17
+ * but we're only scanning entries with start ≤ query, so anything later
18
+ * necessarily starts after the query and can't contain it.
19
+ *
20
+ * Expected complexity: `O(log N_file + D)` where `D` is the lexical depth
21
+ * at the query position (typically ≤ 10). Worst-case degrades to `O(N_file)`
22
+ * only under pathological inputs (many scopes starting at the same line).
23
+ *
24
+ * **Line/column conventions.** Matches `Range` in `types.ts`: lines are
25
+ * 1-based, columns are 0-based. Ranges are **inclusive on both ends** —
26
+ * a scope whose `endLine:endCol` equals the query position still contains
27
+ * it. That matches how tree-sitter captures bodies (closing brace
28
+ * included) and how closed PR #902's `enclosingFunctions` behaved.
29
+ */
30
+ import type { Scope, ScopeId } from './types.js';
31
+ export interface PositionIndex {
32
+ /** Total scope entries indexed across all files. */
33
+ readonly size: number;
34
+ /**
35
+ * Innermost scope containing `(line, col)` in `filePath`, or `undefined`
36
+ * when nothing contains it (position before file start, after file end,
37
+ * or filePath not indexed).
38
+ *
39
+ * **Touching-boundary semantics.** Ranges are inclusive on both ends.
40
+ * When two sibling scopes share a boundary point — e.g.
41
+ * `[5:0, 10:0]` and `[10:0, 15:0]`, which is legal under `ScopeTree`'s
42
+ * non-overlap invariant — a query at the shared point `(10, 0)` is
43
+ * contained by **both**. The innermost-wins tie-break rule applies as
44
+ * usual: since neither is nested inside the other, the one that
45
+ * **starts latest** wins, i.e. the **right** sibling. The mechanism
46
+ * is the backward scan through the start-position-sorted array (see
47
+ * `findLastStartLteIndex` below) — both siblings land before the
48
+ * upper-bound cursor, and the right sibling is scanned first. Queries at non-boundary positions between them naturally
49
+ * fall to the unique containing scope.
50
+ */
51
+ atPosition(filePath: string, line: number, col: number): ScopeId | undefined;
52
+ }
53
+ /**
54
+ * Build a `PositionIndex` from a flat list of `Scope` records.
55
+ *
56
+ * Duplicate `id`s are tolerated and deduplicated — the caller's
57
+ * `ScopeTree.buildScopeTree` is the authoritative validator of scope
58
+ * identity, and the position index does not need to re-check that
59
+ * invariant.
60
+ */
61
+ export declare function buildPositionIndex(scopes: readonly Scope[]): PositionIndex;
62
+ //# sourceMappingURL=position-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position-index.d.ts","sourceRoot":"","sources":["../../src/scope-resolution/position-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAS,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CAC9E;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,aAAa,CAqB1E"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * `PositionIndex` — O(log N_file) scope-at-position lookup
3
+ * (RFC §3.1; Ring 2 SHARED #912).
4
+ *
5
+ * Per-file sorted array of `(range, scopeId)` entries, sorted by start
6
+ * position ASC (`startLine`, then `startCol`). `atPosition(filePath, line,
7
+ * col)` binary-searches for the last entry whose start ≤ (line, col), then
8
+ * scans backward through the sorted prefix and returns the first entry
9
+ * whose range contains the query position.
10
+ *
11
+ * **Why this works.** `ScopeTree`'s invariants (parent strictly contains
12
+ * child; siblings don't overlap) guarantee that the scopes containing a
13
+ * given point form an **ancestor chain**. When scanning backward through
14
+ * entries sorted by start position ASC, the first scope we find that
15
+ * contains the query is the innermost one — any deeper-starting scope
16
+ * that also contained the query would appear *later* in the sorted array,
17
+ * but we're only scanning entries with start ≤ query, so anything later
18
+ * necessarily starts after the query and can't contain it.
19
+ *
20
+ * Expected complexity: `O(log N_file + D)` where `D` is the lexical depth
21
+ * at the query position (typically ≤ 10). Worst-case degrades to `O(N_file)`
22
+ * only under pathological inputs (many scopes starting at the same line).
23
+ *
24
+ * **Line/column conventions.** Matches `Range` in `types.ts`: lines are
25
+ * 1-based, columns are 0-based. Ranges are **inclusive on both ends** —
26
+ * a scope whose `endLine:endCol` equals the query position still contains
27
+ * it. That matches how tree-sitter captures bodies (closing brace
28
+ * included) and how closed PR #902's `enclosingFunctions` behaved.
29
+ */
30
+ /**
31
+ * Build a `PositionIndex` from a flat list of `Scope` records.
32
+ *
33
+ * Duplicate `id`s are tolerated and deduplicated — the caller's
34
+ * `ScopeTree.buildScopeTree` is the authoritative validator of scope
35
+ * identity, and the position index does not need to re-check that
36
+ * invariant.
37
+ */
38
+ export function buildPositionIndex(scopes) {
39
+ const entriesByFile = new Map();
40
+ const seen = new Set();
41
+ for (const scope of scopes) {
42
+ if (seen.has(scope.id))
43
+ continue;
44
+ seen.add(scope.id);
45
+ let bucket = entriesByFile.get(scope.filePath);
46
+ if (bucket === undefined) {
47
+ bucket = [];
48
+ entriesByFile.set(scope.filePath, bucket);
49
+ }
50
+ bucket.push({ id: scope.id, range: scope.range });
51
+ }
52
+ for (const bucket of entriesByFile.values()) {
53
+ bucket.sort(compareEntry);
54
+ }
55
+ return wrapIndex(entriesByFile, seen.size);
56
+ }
57
+ /**
58
+ * Sort by start position ASC, breaking ties by end position DESC so that
59
+ * larger (outer) scopes appear before their smaller (inner) co-starting
60
+ * siblings in the array. Makes the backward-scan contract crisp: the
61
+ * first containing hit from the end of the scanned prefix is the
62
+ * innermost scope.
63
+ */
64
+ function compareEntry(a, b) {
65
+ if (a.range.startLine !== b.range.startLine)
66
+ return a.range.startLine - b.range.startLine;
67
+ if (a.range.startCol !== b.range.startCol)
68
+ return a.range.startCol - b.range.startCol;
69
+ if (a.range.endLine !== b.range.endLine)
70
+ return b.range.endLine - a.range.endLine;
71
+ return b.range.endCol - a.range.endCol;
72
+ }
73
+ /** Whether `(line, col)` is at or after `range`'s start. */
74
+ function startIsAtOrBefore(range, line, col) {
75
+ if (range.startLine < line)
76
+ return true;
77
+ if (range.startLine > line)
78
+ return false;
79
+ return range.startCol <= col;
80
+ }
81
+ /** Whether `(line, col)` is at or before `range`'s end (inclusive). */
82
+ function endIsAtOrAfter(range, line, col) {
83
+ if (range.endLine > line)
84
+ return true;
85
+ if (range.endLine < line)
86
+ return false;
87
+ return range.endCol >= col;
88
+ }
89
+ /**
90
+ * Return the largest index `i` in `arr` where `arr[i].range` starts at or
91
+ * before `(line, col)`. Returns `-1` if no entry starts ≤ the query.
92
+ *
93
+ * Classic "upper bound - 1" binary search: find the first entry that
94
+ * starts *after* the query, then step back one.
95
+ */
96
+ function findLastStartLteIndex(arr, line, col) {
97
+ let lo = 0;
98
+ let hi = arr.length;
99
+ while (lo < hi) {
100
+ const mid = (lo + hi) >>> 1;
101
+ if (startIsAtOrBefore(arr[mid].range, line, col)) {
102
+ lo = mid + 1;
103
+ }
104
+ else {
105
+ hi = mid;
106
+ }
107
+ }
108
+ return lo - 1;
109
+ }
110
+ function wrapIndex(entriesByFile, size) {
111
+ return {
112
+ get size() {
113
+ return size;
114
+ },
115
+ atPosition(filePath, line, col) {
116
+ const bucket = entriesByFile.get(filePath);
117
+ if (bucket === undefined || bucket.length === 0)
118
+ return undefined;
119
+ const endIdx = findLastStartLteIndex(bucket, line, col);
120
+ if (endIdx < 0)
121
+ return undefined;
122
+ // Scan backward; first containing hit is innermost (see file header).
123
+ for (let i = endIdx; i >= 0; i--) {
124
+ const entry = bucket[i];
125
+ if (endIsAtOrAfter(entry.range, line, col)) {
126
+ // `startIsAtOrBefore` is guaranteed true by the binary search.
127
+ return entry.id;
128
+ }
129
+ }
130
+ return undefined;
131
+ },
132
+ };
133
+ }
134
+ //# sourceMappingURL=position-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position-index.js","sourceRoot":"","sources":["../../src/scope-resolution/position-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AA2BH;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAwB;IACzD,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmB,CAAC;IACjD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAW,CAAC;IAEhC,KAAK,MAAM,KAAK,I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AS,CAAC,aAAmC,EAAE,IAAY;IAClE,OAAO;QACL,IAAI,IAAI;YACN,OAAO,IAAI,CAAC;QACd,CAAC;QACD,UAAU,CAAC,QAAgB,EAAE,IAAY,EAAE,GAAW;YACpD,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC3C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,SAAS,CAAC;YAElE,MAAM,MAAM,GAAG,qBAAqB,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YACxD,IAAI,MAAM,GAAG,CAAC;gBAAE,OAAO,SAAS,CAAC;YAEjC,sEAAsE;YACtE,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACjC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC;gBACzB,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;oBAC3C,+DAA+D;oBAC/D,OAAO,KAAK,CAAC,EAAE,CAAC;gBAClB,CAAC;YACH,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `QualifiedNameIndex` — O(1) `qualifiedName → DefId[]` lookup across all kinds.
3
+ *
4
+ * Cross-kind fast path for qualified-name resolution
5
+ * (`lookupQualified(qname, scope, params)` in RFC §4.5). Class, method,
6
+ * field, and namespace defs all contribute to a single index here; consumers
7
+ * filter the returned `DefId[]` by `p.acceptedKinds` at the call site.
8
+ *
9
+ * Returns `DefId[]` (not a single `DefId`) because multiple defs can legally
10
+ * share a qualified name — partial classes in C#, method overloads, or
11
+ * accidental cross-kind collisions. The lookup caller filters to the expected
12
+ * kind(s) and ranks the survivors.
13
+ *
14
+ * Part of RFC #909 Ring 2 SHARED — #913.
15
+ *
16
+ * Consumed by: #917 (`Registry.lookup` qualified fast path, `resolveTypeRef`
17
+ * dotted fallback via #916).
18
+ */
19
+ import type { SymbolDefinition } from './symbol-definition.js';
20
+ import type { DefId } from './types.js';
21
+ export interface QualifiedNameIndex {
22
+ readonly byQualifiedName: ReadonlyMap<string, readonly DefId[]>;
23
+ readonly size: number;
24
+ /** Returns all `DefId`s registered under this qualified name; empty frozen
25
+ * array on miss so callers can iterate without null checks. */
26
+ get(qualifiedName: string): readonly DefId[];
27
+ has(qualifiedName: string): boolean;
28
+ }
29
+ /**
30
+ * Build a `QualifiedNameIndex` from a flat list of `SymbolDefinition` records.
31
+ *
32
+ * Only defs with a non-empty `qualifiedName` contribute; defs without one are
33
+ * silently skipped (not every kind carries a qualified name — anonymous or
34
+ * top-level symbols, dynamic-unresolved imports, etc.).
35
+ *
36
+ * **Duplicate policy: appended in input order.** Each unique `(qname, DefId)`
37
+ * pair contributes at most once — repeated entries for the same pair are
38
+ * deduplicated. Distinct `DefId`s sharing a `qname` accumulate in insertion
39
+ * order (stable output for deterministic lookup ranking at the call site).
40
+ *
41
+ * Pure function — safe to call repeatedly; no side effects.
42
+ */
43
+ export declare function buildQualifiedNameIndex(defs: readonly SymbolDefinition[]): QualifiedNameIndex;
44
+ //# sourceMappingURL=qualified-name-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qualified-name-index.d.ts","sourceRoot":"","sources":["../../src/scope-resolution/qualified-name-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC,CAAC;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;oEACgE;IAChE,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,KAAK,EAAE,CAAC;IAC7C,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;CACrC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,SAAS,gBAAgB,EAAE,GAAG,kBAAkB,CA2B7F"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * `QualifiedNameIndex` — O(1) `qualifiedName → DefId[]` lookup across all kinds.
3
+ *
4
+ * Cross-kind fast path for qualified-name resolution
5
+ * (`lookupQualified(qname, scope, params)` in RFC §4.5). Class, method,
6
+ * field, and namespace defs all contribute to a single index here; consumers
7
+ * filter the returned `DefId[]` by `p.acceptedKinds` at the call site.
8
+ *
9
+ * Returns `DefId[]` (not a single `DefId`) because multiple defs can legally
10
+ * share a qualified name — partial classes in C#, method overloads, or
11
+ * accidental cross-kind collisions. The lookup caller filters to the expected
12
+ * kind(s) and ranks the survivors.
13
+ *
14
+ * Part of RFC #909 Ring 2 SHARED — #913.
15
+ *
16
+ * Consumed by: #917 (`Registry.lookup` qualified fast path, `resolveTypeRef`
17
+ * dotted fallback via #916).
18
+ */
19
+ /**
20
+ * Build a `QualifiedNameIndex` from a flat list of `SymbolDefinition` records.
21
+ *
22
+ * Only defs with a non-empty `qualifiedName` contribute; defs without one are
23
+ * silently skipped (not every kind carries a qualified name — anonymous or
24
+ * top-level symbols, dynamic-unresolved imports, etc.).
25
+ *
26
+ * **Duplicate policy: appended in input order.** Each unique `(qname, DefId)`
27
+ * pair contributes at most once — repeated entries for the same pair are
28
+ * deduplicated. Distinct `DefId`s sharing a `qname` accumulate in insertion
29
+ * order (stable output for deterministic lookup ranking at the call site).
30
+ *
31
+ * Pure function — safe to call repeatedly; no side effects.
32
+ */
33
+ export function buildQualifiedNameIndex(defs) {
34
+ const byQualifiedName = new Map();
35
+ const seenPairs = new Set();
36
+ for (const def of defs) {
37
+ const qname = def.qualifiedName;
38
+ if (qname === undefined || qname.length === 0)
39
+ continue;
40
+ const pairKey = `${qname}\0${def.nodeId}`;
41
+ if (seenPairs.has(pairKey))
42
+ continue;
43
+ seenPairs.add(pairKey);
44
+ const bucket = byQualifiedName.get(qname);
45
+ if (bucket === undefined) {
46
+ byQualifiedName.set(qname, [def.nodeId]);
47
+ }
48
+ else {
49
+ bucket.push(def.nodeId);
50
+ }
51
+ }
52
+ // Freeze bucket arrays so consumers can't mutate the index.
53
+ const frozen = new Map();
54
+ for (const [k, v] of byQualifiedName) {
55
+ frozen.set(k, Object.freeze(v.slice()));
56
+ }
57
+ return wrapIndex(frozen);
58
+ }
59
+ // ─── Internal ───────────────────────────────────────────────────────────────
60
+ const EMPTY = Object.freeze([]);
61
+ function wrapIndex(byQualifiedName) {
62
+ return {
63
+ byQualifiedName,
64
+ get size() {
65
+ return byQualifiedName.size;
66
+ },
67
+ get(qualifiedName) {
68
+ return byQualifiedName.get(qualifiedName) ?? EMPTY;
69
+ },
70
+ has(qualifiedName) {
71
+ return byQualifiedName.has(qualifiedName);
72
+ },
73
+ };
74
+ }
75
+ //# sourceMappingURL=qualified-name-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qualified-name-index.js","sourceRoot":"","sources":["../../src/scope-resolution/qualified-name-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAcH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiC;IACvE,MAAM,eAAe,GAAG,IAAI,GAAG,EAAmB,CAAC;IACnD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IAEpC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,GAAG,CAAC,aAAa,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAExD,MAAM,OAAO,GAAG,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enceSite` — a pre-resolution usage fact collected by `ScopeExtractor`
3
+ * (RFC §3.2 Phase 1; Ring 2 PKG #919).
4
+ *
5
+ * One record per `@reference.*` capture. The extractor records:
6
+ * - the name being referenced (method/field/class name),
7
+ * - the source range,
8
+ * - the innermost lexical scope containing the reference,
9
+ * - the reference kind (call, read, write, inherits, etc.),
10
+ * - optional call-form classification from `provider.classifyCallForm`,
11
+ * - optional explicit-receiver hint for dotted calls (`user.save()`),
12
+ * - optional arity for call sites.
13
+ *
14
+ * Reference sites are consumed by the resolution phase (RFC §3.2 Phase 4)
15
+ * which routes each through `Registry.lookup` / `resolveTypeRef` and
16
+ * emits the final `Reference` record into `ReferenceIndex`.
17
+ *
18
+ * **Pre-resolution only.** `ReferenceSite` intentionally carries no
19
+ * `toDef`, `confidence`, or `evidence`. Those are populated by the
20
+ * resolution step that reads this record and produces a `Reference`
21
+ * (defined in `./types.ts`).
22
+ */
23
+ import type { Range, ScopeId } from './types.js';
24
+ /**
25
+ * What kind of usage this reference represents — the graph-edge kind
26
+ * emitted after resolution (`CALLS`, `READS`, `WRITES`, etc.).
27
+ *
28
+ * Matches the `kind` field on `Reference` in `./types.ts` so the
29
+ * resolution phase can pass it through without re-classification.
30
+ */
31
+ export type ReferenceKind = 'call' | 'read' | 'write' | 'type-reference' | 'inherits' | 'import-use';
32
+ /**
33
+ * How a call site binds its target. Informs `Registry.lookup` Step 2
34
+ * (type-binding path):
35
+ * - `'free'` — bare call (no receiver); resolution via lexical chain.
36
+ * - `'member'` — dotted call (`x.foo()`); resolution via receiver type.
37
+ * - `'constructor'` — `new Foo()`; receiver is the class itself.
38
+ * - `'index'` — index expression (`arr[0]`); rare as a dispatch site.
39
+ *
40
+ * Only meaningful for `kind === 'call'`; ignored for reads/writes.
41
+ */
42
+ export type CallForm = 'free' | 'member' | 'constructor' | 'index';
43
+ export interface ReferenceSite {
44
+ /** The name being referenced (e.g., `'save'`, `'User'`, `'count'`). */
45
+ readonly name: string;
46
+ /** Source-text range of this reference. */
47
+ readonly atRange: Range;
48
+ /**
49
+ * Innermost lexical scope that contains `atRange`. Resolved by the
50
+ * extractor via position lookup and frozen here so the resolution
51
+ * phase doesn't re-compute it per call.
52
+ */
53
+ readonly inScope: ScopeId;
54
+ readonly kind: ReferenceKind;
55
+ /** Set when `kind === 'call'`. */
56
+ readonly callForm?: CallForm;
57
+ /**
58
+ * Explicit receiver for dotted calls (`user.save()` → `{ name: 'user' }`).
59
+ * Passed through to `Registry.lookup.explicitReceiver`.
60
+ */
61
+ readonly explicitReceiver?: {
62
+ readonly name: string;
63
+ };
64
+ /** Argument count at the call site; used by `provider.arityCompatibility`. */
65
+ readonly arity?: number;
66
+ }
67
+ //# sourceMappingURL=reference-site.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-site.d.ts","sourceRoot":"","sources":["../../src/scope-resolution/reference-site.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,MAAM,GACN,OAAO,GACP,gBAAgB,GAChB,UAAU,GACV,YAAY,CAAC;AAEjB;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,kCAAkC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB"}