-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcontext.ts
More file actions
139 lines (130 loc) · 5.4 KB
/
Copy pathcontext.ts
File metadata and controls
139 lines (130 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* PipelineContext — shared mutable state threaded through all build stages.
*
* Each stage reads what it needs and writes what it produces.
* This replaces the closure-captured locals in the old monolithic buildGraph().
*/
import type {
BetterSqlite3Database,
BuildGraphOpts,
CodegraphConfig,
EngineOpts,
ExtractorOutput,
FileToParse,
MetadataUpdate,
NativeDatabase,
NodeRow,
ParseChange,
PathAliases,
} from '../../../types.js';
import type { BarrelExportResolution } from './stages/resolve-imports.js';
export class PipelineContext {
// ── Inputs (set during setup) ──────────────────────────────────────
rootDir!: string;
db!: BetterSqlite3Database;
dbPath!: string;
config!: CodegraphConfig;
opts!: BuildGraphOpts;
engineOpts!: EngineOpts;
engineName!: 'native' | 'wasm';
engineVersion!: string | null;
/**
* The version reported by the native binary itself (CARGO_PKG_VERSION at
* build time), as opposed to `engineVersion` which prefers the platform
* package.json. The Rust orchestrator's check_version_mismatch compares
* `build_meta.engine_version` against CARGO_PKG_VERSION, so build_meta
* writes must use this value to avoid a perpetual full-rebuild loop when
* the binary and platform package.json drift apart (e.g., CI hot-swap
* via ci-install-native.mjs — #1066).
*/
nativeBinaryVersion!: string | null;
aliases!: PathAliases;
incremental!: boolean;
forceFullRebuild: boolean = false;
schemaVersion!: number;
nativeDb?: NativeDatabase;
/** Whether native engine is available (deferred — DB opened only when needed). */
nativeAvailable: boolean = false;
/** True when ctx.db is a NativeDbProxy — single rusqlite connection for the entire pipeline. */
nativeFirstProxy: boolean = false;
// ── File collection (set by collectFiles stage) ────────────────────
allFiles!: string[];
discoveredDirs!: Set<string>;
// ── Change detection (set by detectChanges stage) ──────────────────
isFullBuild!: boolean;
parseChanges!: ParseChange[];
metadataUpdates!: MetadataUpdate[];
removed!: string[];
/**
* Forward+reverse import-neighbor files of `removed`, captured before
* `purgeFilesFromGraph`/`purgeFilesData` deletes those files' edges. Lets
* `refreshAffectedDirectoryMetrics` still discover a removed file's
* cross-directory neighbor even though the live edge evidence for it is
* gone by the time the structure stage runs (#1839).
*/
removedFileNeighbors: string[] = [];
earlyExit: boolean = false;
// ── Parsing (set by parseFiles stage) ──────────────────────────────
allSymbols!: Map<string, ExtractorOutput>;
fileSymbols!: Map<string, ExtractorOutput>;
filesToParse!: FileToParse[];
// ── Import resolution (set by resolveImports stage) ────────────────
batchResolved!: Map<string, string> | null;
reexportMap!: Map<string, unknown[]>;
barrelOnlyFiles!: Set<string>;
/** Phase 8.4: cache for resolveBarrelExport results keyed as "barrelPath|symbolName". */
barrelExportCache: Map<string, BarrelExportResolution | null> = new Map();
// ── Node lookup (set by insertNodes / buildEdges stages) ───────────
nodesByName!: Map<string, NodeRow[]>;
nodesByNameAndFile!: Map<string, NodeRow[]>;
// ── Reverse-dep edge reconnection (set by detectChanges) ───────────
/**
* Edges from reverse-dep files to changed files, saved before purge so they
* can be reconnected to new node IDs after insertNodes (#932, #933).
* Eliminates the need to reparse reverse-dep files entirely.
*/
savedReverseDepEdges: Array<{
sourceId: number;
tgtName: string;
tgtKind: string;
tgtFile: string;
tgtLine: number;
/**
* 1-based rank of the target (by ascending line) among nodes sharing its
* (name, kind) within `tgtFile`, computed at save time. Lets
* `reconnectReverseDepEdges` map an old target to its correct new node
* even when multiple distinct symbols in the file share the same name
* and kind (e.g. several object-literal `close() {}` methods) — see #1752.
*/
tgtOrdinal: number;
/** Size of that (name, kind) sibling group at save time. */
tgtSiblingCount: number;
edgeKind: string;
confidence: number;
dynamic: number;
technique: string | null;
dynamicKind: string | null;
}> = [];
// ── Misc state ─────────────────────────────────────────────────────
hasEmbeddings: boolean = false;
lineCountMap!: Map<string, number>;
// ── Phase timing ───────────────────────────────────────────────────
timing: {
setupMs?: number;
collectMs?: number;
detectMs?: number;
parseMs?: number;
insertMs?: number;
resolveMs?: number;
edgesMs?: number;
structureMs?: number;
rolesMs?: number;
astMs?: number;
complexityMs?: number;
cfgMs?: number;
dataflowMs?: number;
finalizeMs?: number;
[key: string]: number | undefined;
} = {};
buildStart!: number;
}