MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / getAmbientDeclarationPathsAmong

Method getAmbientDeclarationPathsAmong

src/db/queries.ts:4268–4325  ·  view source on GitHub ↗

* Which of `filePaths` are AMBIENT DECLARATION files — they declare nothing * but types, and nothing in the index depends on them (CG-28). A hand-written * ambient `.d.ts` of global shims, a vendored typings file, module * augmentation: reachable only by name, structurally attached to nothi

(filePaths: Iterable<string>)

Source from the content-addressed store, hash-verified

4266 * candidate list, so this is a partial-index probe over a handful of paths.
4267 */
4268 getAmbientDeclarationPathsAmong(filePaths: Iterable<string>): Set<string> {
4269 const unique = [...new Set(filePaths)];
4270 const found = new Set<string>();
4271 if (unique.length === 0) return found;
4272
4273 for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
4274 const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
4275 const placeholders = chunk.map(() => '?').join(',');
4276 // `file`/`import`/`export`/`parameter` are structural bookkeeping, not
4277 // things the file declares, so they neither qualify nor disqualify.
4278 const rows = this.db
4279 .prepare(`
4280 SELECT n.file_path AS file_path,
4281 SUM(CASE WHEN n.kind NOT IN ('file','import','export','parameter')
4282 AND NOT ${IS_INTERFACE_MEMBER('n')}
4283 THEN 1 ELSE 0 END) AS declared,
4284 SUM(CASE WHEN n.kind IN ('interface','type_alias','enum','enum_member','namespace')
4285 THEN 1 ELSE 0 END) AS typeDeclared
4286 FROM nodes n
4287 WHERE n.file_path IN (${placeholders})
4288 GROUP BY n.file_path
4289 `)
4290 .all(...chunk) as Array<{ file_path: string; declared: number; typeDeclared: number }>;
4291 let candidates = rows
4292 .filter((r) => r.declared > 0 && r.declared === r.typeDeclared)
4293 .map((r) => r.file_path);
4294 if (candidates.length === 0) continue;
4295
4296 const disqualify = (sql: string): void => {
4297 if (candidates.length === 0) return;
4298 const hit = new Set(
4299 (this.db
4300 .prepare(sql.replace('$IN$', candidates.map(() => '?').join(',')))
4301 .all(...candidates) as Array<{ file_path: string }>).map((r) => r.file_path),
4302 );
4303 candidates = candidates.filter((p) => !hit.has(p));
4304 };
4305 // (3) originates behaviour — a signature has no body to originate from,
4306 // so an edge attributed to one is not evidence about this file.
4307 disqualify(`
4308 SELECT DISTINCT n.file_path AS file_path
4309 FROM edges e JOIN nodes n ON n.id = e.source
4310 WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
4311 AND NOT ${IS_INTERFACE_MEMBER('n')}
4312 `);
4313 // (4) something outside the file depends on it — but a call that lands on
4314 // an interface's own signature is a use of the API, not a dependency on
4315 // this file's structure. The edges aimed at the interface still count.
4316 disqualify(`
4317 SELECT DISTINCT t.file_path AS file_path
4318 FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
4319 WHERE t.file_path IN ($IN$) AND s.file_path <> t.file_path
4320 AND NOT ${IS_INTERFACE_MEMBER('t')}
4321 `);
4322 for (const path of candidates) found.add(path);
4323 }
4324 return found;
4325 }

Callers 1

Calls 6

IS_INTERFACE_MEMBERFunction · 0.85
mapMethod · 0.80
allMethod · 0.65
prepareMethod · 0.65
joinMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected