gitnexus 1.6.2 → 1.6.3-rc.10
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/dist/_shared/index.d.ts +45 -0
- package/dist/_shared/index.d.ts.map +1 -1
- package/dist/_shared/index.js +33 -0
- package/dist/_shared/index.js.map +1 -1
- package/dist/_shared/scope-resolution/def-index.d.ts +36 -0
- package/dist/_shared/scope-resolution/def-index.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/def-index.js +51 -0
- package/dist/_shared/scope-resolution/def-index.js.map +1 -0
- package/dist/_shared/scope-resolution/evidence-weights.d.ts +69 -0
- package/dist/_shared/scope-resolution/evidence-weights.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/evidence-weights.js +84 -0
- package/dist/_shared/scope-resolution/evidence-weights.js.map +1 -0
- package/dist/_shared/scope-resolution/finalize-algorithm.d.ts +139 -0
- package/dist/_shared/scope-resolution/finalize-algorithm.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/finalize-algorithm.js +479 -0
- package/dist/_shared/scope-resolution/finalize-algorithm.js.map +1 -0
- package/dist/_shared/scope-resolution/language-classification.d.ts +26 -0
- package/dist/_shared/scope-resolution/language-classification.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/language-classification.js +44 -0
- package/dist/_shared/scope-resolution/language-classification.js.map +1 -0
- package/dist/_shared/scope-resolution/method-dispatch-index.d.ts +80 -0
- package/dist/_shared/scope-resolution/method-dispatch-index.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/method-dispatch-index.js +79 -0
- package/dist/_shared/scope-resolution/method-dispatch-index.js.map +1 -0
- package/dist/_shared/scope-resolution/module-scope-index.d.ts +46 -0
- package/dist/_shared/scope-resolution/module-scope-index.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/module-scope-index.js +58 -0
- package/dist/_shared/scope-resolution/module-scope-index.js.map +1 -0
- package/dist/_shared/scope-resolution/origin-priority.d.ts +14 -0
- package/dist/_shared/scope-resolution/origin-priority.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/origin-priority.js +21 -0
- package/dist/_shared/scope-resolution/origin-priority.js.map +1 -0
- package/dist/_shared/scope-resolution/position-index.d.ts +62 -0
- package/dist/_shared/scope-resolution/position-index.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/position-index.js +134 -0
- package/dist/_shared/scope-resolution/position-index.js.map +1 -0
- package/dist/_shared/scope-resolution/qualified-name-index.d.ts +44 -0
- package/dist/_shared/scope-resolution/qualified-name-index.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/qualified-name-index.js +75 -0
- package/dist/_shared/scope-resolution/qualified-name-index.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/class-registry.d.ts +27 -0
- package/dist/_shared/scope-resolution/registries/class-registry.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/class-registry.js +30 -0
- package/dist/_shared/scope-resolution/registries/class-registry.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/context.d.ts +69 -0
- package/dist/_shared/scope-resolution/registries/context.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/context.js +44 -0
- package/dist/_shared/scope-resolution/registries/context.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/evidence.d.ts +56 -0
- package/dist/_shared/scope-resolution/registries/evidence.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/evidence.js +150 -0
- package/dist/_shared/scope-resolution/registries/evidence.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/field-registry.d.ts +26 -0
- package/dist/_shared/scope-resolution/registries/field-registry.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/field-registry.js +31 -0
- package/dist/_shared/scope-resolution/registries/field-registry.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/lookup-core.d.ts +81 -0
- package/dist/_shared/scope-resolution/registries/lookup-core.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/lookup-core.js +332 -0
- package/dist/_shared/scope-resolution/registries/lookup-core.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts +33 -0
- package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/lookup-qualified.js +56 -0
- package/dist/_shared/scope-resolution/registries/lookup-qualified.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/method-registry.d.ts +36 -0
- package/dist/_shared/scope-resolution/registries/method-registry.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/method-registry.js +32 -0
- package/dist/_shared/scope-resolution/registries/method-registry.js.map +1 -0
- package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts +43 -0
- package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/registries/tie-breaks.js +60 -0
- package/dist/_shared/scope-resolution/registries/tie-breaks.js.map +1 -0
- package/dist/_shared/scope-resolution/resolve-type-ref.d.ts +53 -0
- package/dist/_shared/scope-resolution/resolve-type-ref.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/resolve-type-ref.js +126 -0
- package/dist/_shared/scope-resolution/resolve-type-ref.js.map +1 -0
- package/dist/_shared/scope-resolution/scope-id.d.ts +43 -0
- package/dist/_shared/scope-resolution/scope-id.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/scope-id.js +46 -0
- package/dist/_shared/scope-resolution/scope-id.js.map +1 -0
- package/dist/_shared/scope-resolution/scope-tree.d.ts +61 -0
- package/dist/_shared/scope-resolution/scope-tree.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/scope-tree.js +186 -0
- package/dist/_shared/scope-resolution/scope-tree.js.map +1 -0
- package/dist/_shared/scope-resolution/shadow/aggregate.d.ts +63 -0
- package/dist/_shared/scope-resolution/shadow/aggregate.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/shadow/aggregate.js +122 -0
- package/dist/_shared/scope-resolution/shadow/aggregate.js.map +1 -0
- package/dist/_shared/scope-resolution/shadow/diff.d.ts +59 -0
- package/dist/_shared/scope-resolution/shadow/diff.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/shadow/diff.js +79 -0
- package/dist/_shared/scope-resolution/shadow/diff.js.map +1 -0
- package/dist/_shared/scope-resolution/symbol-definition.d.ts +34 -0
- package/dist/_shared/scope-resolution/symbol-definition.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/symbol-definition.js +12 -0
- package/dist/_shared/scope-resolution/symbol-definition.js.map +1 -0
- package/dist/_shared/scope-resolution/types.d.ts +356 -0
- package/dist/_shared/scope-resolution/types.d.ts.map +1 -0
- package/dist/_shared/scope-resolution/types.js +17 -0
- package/dist/_shared/scope-resolution/types.js.map +1 -0
- package/dist/core/ingestion/call-processor.d.ts +2 -1
- package/dist/core/ingestion/language-provider.d.ts +172 -1
- package/dist/core/ingestion/model/field-registry.d.ts +1 -1
- package/dist/core/ingestion/model/index.d.ts +1 -1
- package/dist/core/ingestion/model/index.js +2 -0
- package/dist/core/ingestion/model/method-registry.d.ts +1 -1
- package/dist/core/ingestion/model/registration-table.d.ts +1 -2
- package/dist/core/ingestion/model/resolution-context.d.ts +1 -1
- package/dist/core/ingestion/model/resolve.d.ts +1 -1
- package/dist/core/ingestion/model/symbol-table.d.ts +1 -23
- package/dist/core/ingestion/model/type-registry.d.ts +1 -1
- package/dist/core/search/phase-timer.d.ts +72 -0
- package/dist/core/search/phase-timer.js +106 -0
- package/dist/mcp/local/local-backend.d.ts +48 -1
- package/dist/mcp/local/local-backend.js +345 -135
- package/dist/mcp/tools.js +19 -1
- package/package.json +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MethodDispatchIndex` — materialized view of class hierarchies keyed by
|
|
3
|
+
* `DefId` (RFC §3.1; Ring 2 SHARED #914).
|
|
4
|
+
*
|
|
5
|
+
* Two O(1)-access maps used by `Registry.lookupMethod` and interface-
|
|
6
|
+
* dispatch callers:
|
|
7
|
+
*
|
|
8
|
+
* - `mroByOwnerDefId` : owner class → full MRO ancestor chain
|
|
9
|
+
* (excludes the owner itself, in per-language
|
|
10
|
+
* strategy order).
|
|
11
|
+
* - `implsByInterfaceDefId` : interface/trait → classes that implement it.
|
|
12
|
+
*
|
|
13
|
+
* **Not an MRO implementation.** The build function is a pure aggregator: it
|
|
14
|
+
* asks the caller (via `computeMro` and `implementsOf` callbacks) for the
|
|
15
|
+
* per-language answers and materializes the two-way index. MRO strategies
|
|
16
|
+
* live where they already do today (`model/resolve.ts § c3Linearize`,
|
|
17
|
+
* `languages/ruby.ts § selectDispatch`, etc.) — this index does not
|
|
18
|
+
* reimplement them.
|
|
19
|
+
*
|
|
20
|
+
* Why callbacks and not a shared strategy registry: the five strategies
|
|
21
|
+
* (Python C3, Ruby kind-aware, Java/Kotlin linear, Rust qualified-syntax,
|
|
22
|
+
* COBOL none) already exist in the CLI package and depend on the CLI's
|
|
23
|
+
* `HeritageMap` + `SemanticModel`. Pulling them into `gitnexus-shared` would
|
|
24
|
+
* require migrating both — out of scope for #914. Callbacks let the shared
|
|
25
|
+
* build stay pure while honoring existing strategies verbatim.
|
|
26
|
+
*
|
|
27
|
+
* Consumed by: #917 (`Registry.lookupMethod` MRO fast path, interface
|
|
28
|
+
* dispatch resolver).
|
|
29
|
+
*/
|
|
30
|
+
// ─── Builder ────────────────────────────────────────────────────────────────
|
|
31
|
+
export function buildMethodDispatchIndex(input) {
|
|
32
|
+
const mroByOwnerDefId = new Map();
|
|
33
|
+
const implsBuilding = new Map();
|
|
34
|
+
const implsSeen = new Map();
|
|
35
|
+
for (const ownerId of input.owners) {
|
|
36
|
+
// First-write-wins on duplicate owner ids: a stable policy consistent
|
|
37
|
+
// with sibling indexes (#913 DefIndex / ModuleScopeIndex).
|
|
38
|
+
if (!mroByOwnerDefId.has(ownerId)) {
|
|
39
|
+
const chain = input.computeMro(ownerId);
|
|
40
|
+
mroByOwnerDefId.set(ownerId, Object.freeze(chain.slice()));
|
|
41
|
+
}
|
|
42
|
+
for (const ifaceId of input.implementsOf(ownerId)) {
|
|
43
|
+
let seen = implsSeen.get(ifaceId);
|
|
44
|
+
if (seen === undefined) {
|
|
45
|
+
seen = new Set();
|
|
46
|
+
implsSeen.set(ifaceId, seen);
|
|
47
|
+
}
|
|
48
|
+
if (seen.has(ownerId))
|
|
49
|
+
continue;
|
|
50
|
+
seen.add(ownerId);
|
|
51
|
+
let bucket = implsBuilding.get(ifaceId);
|
|
52
|
+
if (bucket === undefined) {
|
|
53
|
+
bucket = [];
|
|
54
|
+
implsBuilding.set(ifaceId, bucket);
|
|
55
|
+
}
|
|
56
|
+
bucket.push(ownerId);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const implsByInterfaceDefId = new Map();
|
|
60
|
+
for (const [ifaceId, owners] of implsBuilding) {
|
|
61
|
+
implsByInterfaceDefId.set(ifaceId, Object.freeze(owners.slice()));
|
|
62
|
+
}
|
|
63
|
+
return wrapIndex(mroByOwnerDefId, implsByInterfaceDefId);
|
|
64
|
+
}
|
|
65
|
+
// ─── Internal ───────────────────────────────────────────────────────────────
|
|
66
|
+
const EMPTY = Object.freeze([]);
|
|
67
|
+
function wrapIndex(mroByOwnerDefId, implsByInterfaceDefId) {
|
|
68
|
+
return {
|
|
69
|
+
mroByOwnerDefId,
|
|
70
|
+
implsByInterfaceDefId,
|
|
71
|
+
mroFor(ownerDefId) {
|
|
72
|
+
return mroByOwnerDefId.get(ownerDefId) ?? EMPTY;
|
|
73
|
+
},
|
|
74
|
+
implementorsOf(interfaceDefId) {
|
|
75
|
+
return implsByInterfaceDefId.get(interfaceDefId) ?? EMPTY;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=method-dispatch-index.js.map
|
|
@@ -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,MA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BAAqB,GAAG,IAAI,GAAG,EAA2B,CAAC;IACjE,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC;QAC9C,qBAAqB,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,SAAS,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;AAC3D,CAAC;AAED,+EAA+E;AAE/E,MAAM,KAAK,GAAqB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAElD,SAAS,SAAS,CAChB,eAA6C,EAC7C,qBAAmD;IAEnD,OAAO;QACL,eAAe;QACf,qBAAqB;QACrB,MAAM,CAAC,UAAiB;YACtB,OAAO,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC;QAClD,CAAC;QACD,cAAc,CAAC,cAAqB;YAClC,OAAO,qBAAqB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC;QAC5D,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,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ORIGIN_PRIORITY` — RFC Appendix B (authoritative values).
|
|
3
|
+
*
|
|
4
|
+
* Tie-break ordering applied inside `Registry.lookup` Step 7 when
|
|
5
|
+
* `|Δconfidence| < 0.001` between two `Resolution` candidates. Lower number
|
|
6
|
+
* = stronger (wins the tie).
|
|
7
|
+
*
|
|
8
|
+
* Full tie-break order (§4.2 Step 7):
|
|
9
|
+
* confidence DESC → scope depth ASC → MRO depth ASC → ORIGIN_PRIORITY ASC
|
|
10
|
+
* → DefId.localeCompare
|
|
11
|
+
*/
|
|
12
|
+
export type OriginForTieBreak = 'local' | 'import' | 'reexport' | 'namespace' | 'wildcard' | 'global-qualified' | 'global-name';
|
|
13
|
+
export declare const ORIGIN_PRIORITY: Readonly<Record<OriginForTieBreak, number>>;
|
|
14
|
+
//# sourceMappingURL=origin-priority.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin-priority.d.ts","sourceRoot":"","sources":["../../src/scope-resolution/origin-priority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP,QAAQ,GACR,UAAU,GACV,WAAW,GACX,UAAU,GACV,kBAAkB,GAClB,aAAa,CAAC;AAElB,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAQvE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ORIGIN_PRIORITY` — RFC Appendix B (authoritative values).
|
|
3
|
+
*
|
|
4
|
+
* Tie-break ordering applied inside `Registry.lookup` Step 7 when
|
|
5
|
+
* `|Δconfidence| < 0.001` between two `Resolution` candidates. Lower number
|
|
6
|
+
* = stronger (wins the tie).
|
|
7
|
+
*
|
|
8
|
+
* Full tie-break order (§4.2 Step 7):
|
|
9
|
+
* confidence DESC → scope depth ASC → MRO depth ASC → ORIGIN_PRIORITY ASC
|
|
10
|
+
* → DefId.localeCompare
|
|
11
|
+
*/
|
|
12
|
+
export const ORIGIN_PRIORITY = {
|
|
13
|
+
local: 0,
|
|
14
|
+
import: 1,
|
|
15
|
+
reexport: 2,
|
|
16
|
+
namespace: 3,
|
|
17
|
+
wildcard: 4,
|
|
18
|
+
'global-qualified': 5,
|
|
19
|
+
'global-name': 6,
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=origin-priority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin-priority.js","sourceRoot":"","sources":["../../src/scope-resolution/origin-priority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,MAAM,CAAC,MAAM,eAAe,GAAgD;IAC1E,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;IACX,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC;IACX,kBAAkB,EAAE,CAAC;IACrB,aAAa,EAAE,CAAC;CACjB,CAAC"}
|
|
@@ -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,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,SAAS;QACjC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAEnB,IAAI,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;Y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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,GAAG,KAAK,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;QAC1C,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,SAAS;QACrC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAEvB,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,4DAA4D;IAC5D,MAAM,MAAM,GAAG,IAAI,GAAG,EAA4B,CAAC;IACnD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,eAAe,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,+EAA+E;AAE/E,MAAM,KAAK,GAAqB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAElD,SAAS,SAAS,CAAC,eAA8C;IAC/D,OAAO;QACL,eAAe;QACf,IAAI,IAAI;YACN,OAAO,eAAe,CAAC,IAAI,CAAC;QAC9B,CAAC;QACD,GAAG,CAAC,aAAqB;YACvB,OAAO,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC;QACrD,CAAC;QACD,GAAG,CAAC,aAAqB;YACvB,OAAO,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ClassRegistry` — scope-aware lookup for class-like symbols
|
|
3
|
+
* (RFC §4.4; Ring 2 SHARED #917).
|
|
4
|
+
*
|
|
5
|
+
* Thin wrapper over `lookupCore`, specialized for class kinds:
|
|
6
|
+
*
|
|
7
|
+
* - `acceptedKinds` = Class / Interface / Enum / Struct / Union /
|
|
8
|
+
* Trait / TypeAlias / Typedef / Record / Delegate / Annotation /
|
|
9
|
+
* Template / Namespace.
|
|
10
|
+
* - `useReceiverTypeBinding` is **false** — classes are resolved by
|
|
11
|
+
* name through the lexical chain + global qualified fallback, not
|
|
12
|
+
* via a receiver type.
|
|
13
|
+
* - Arity filter is not applicable (classes are not called with
|
|
14
|
+
* argument counts at lookup time).
|
|
15
|
+
*/
|
|
16
|
+
import type { Resolution, ScopeId } from '../types.js';
|
|
17
|
+
import { type RegistryContext } from './context.js';
|
|
18
|
+
export interface ClassRegistry {
|
|
19
|
+
/**
|
|
20
|
+
* Look up a class-like symbol by simple or dotted name anchored at
|
|
21
|
+
* `scope`. Returns a confidence-ranked `Resolution[]`; consume `[0]`
|
|
22
|
+
* for the best answer.
|
|
23
|
+
*/
|
|
24
|
+
lookup(name: string, scope: ScopeId): readonly Resolution[];
|
|
25
|
+
}
|
|
26
|
+
export declare function buildClassRegistry(ctx: RegistryContext): ClassRegistry;
|
|
27
|
+
//# sourceMappingURL=class-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-registry.d.ts","sourceRoot":"","sources":["../../../src/scope-resolution/registries/class-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,UAAU,EAAE,CAAC;CAC7D;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,GAAG,aAAa,CAWtE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ClassRegistry` — scope-aware lookup for class-like symbols
|
|
3
|
+
* (RFC §4.4; Ring 2 SHARED #917).
|
|
4
|
+
*
|
|
5
|
+
* Thin wrapper over `lookupCore`, specialized for class kinds:
|
|
6
|
+
*
|
|
7
|
+
* - `acceptedKinds` = Class / Interface / Enum / Struct / Union /
|
|
8
|
+
* Trait / TypeAlias / Typedef / Record / Delegate / Annotation /
|
|
9
|
+
* Template / Namespace.
|
|
10
|
+
* - `useReceiverTypeBinding` is **false** — classes are resolved by
|
|
11
|
+
* name through the lexical chain + global qualified fallback, not
|
|
12
|
+
* via a receiver type.
|
|
13
|
+
* - Arity filter is not applicable (classes are not called with
|
|
14
|
+
* argument counts at lookup time).
|
|
15
|
+
*/
|
|
16
|
+
import { lookupCore } from './lookup-core.js';
|
|
17
|
+
import { CLASS_KINDS } from './context.js';
|
|
18
|
+
export function buildClassRegistry(ctx) {
|
|
19
|
+
const params = {
|
|
20
|
+
acceptedKinds: CLASS_KINDS,
|
|
21
|
+
useReceiverTypeBinding: false,
|
|
22
|
+
ownerScopedContributor: null,
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
lookup(name, scope) {
|
|
26
|
+
return lookupCore(name, scope, params, ctx);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=class-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-registry.js","sourceRoot":"","sources":["../../../src/scope-resolution/registries/class-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,UAAU,EAAyB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAwB,MAAM,cAAc,CAAC;AAWjE,MAAM,UAAU,kBAAkB,CAAC,GAAoB;IACrD,MAAM,MAAM,GAAqB;QAC/B,aAAa,EAAE,WAAW;QAC1B,sBAAsB,EAAE,KAAK;QAC7B,sBAAsB,EAAE,IAAI;KAC7B,CAAC;IACF,OAAO;QACL,MAAM,CAAC,IAAY,EAAE,KAAc;YACjC,OAAO,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC"}
|