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

Method getAmbientDeclarationPathsAmong

src/db/queries.ts:4157–4214  ·  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

4155 * candidate list, so this is a partial-index probe over a handful of paths.
4156 */
4157 getAmbientDeclarationPathsAmong(filePaths: Iterable<string>): Set<string> {
4158 const unique = [...new Set(filePaths)];
4159 const found = new Set<string>();
4160 if (unique.length === 0) return found;
4161
4162 for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
4163 const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
4164 const placeholders = chunk.map(() => '?').join(',');
4165 // `file`/`import`/`export`/`parameter` are structural bookkeeping, not
4166 // things the file declares, so they neither qualify nor disqualify.
4167 const rows = this.db
4168 .prepare(`
4169 SELECT n.file_path AS file_path,
4170 SUM(CASE WHEN n.kind NOT IN ('file','import','export','parameter')
4171 AND NOT ${IS_INTERFACE_MEMBER('n')}
4172 THEN 1 ELSE 0 END) AS declared,
4173 SUM(CASE WHEN n.kind IN ('interface','type_alias','enum','enum_member','namespace')
4174 THEN 1 ELSE 0 END) AS typeDeclared
4175 FROM nodes n
4176 WHERE n.file_path IN (${placeholders})
4177 GROUP BY n.file_path
4178 `)
4179 .all(...chunk) as Array<{ file_path: string; declared: number; typeDeclared: number }>;
4180 let candidates = rows
4181 .filter((r) => r.declared > 0 && r.declared === r.typeDeclared)
4182 .map((r) => r.file_path);
4183 if (candidates.length === 0) continue;
4184
4185 const disqualify = (sql: string): void => {
4186 if (candidates.length === 0) return;
4187 const hit = new Set(
4188 (this.db
4189 .prepare(sql.replace('$IN$', candidates.map(() => '?').join(',')))
4190 .all(...candidates) as Array<{ file_path: string }>).map((r) => r.file_path),
4191 );
4192 candidates = candidates.filter((p) => !hit.has(p));
4193 };
4194 // (3) originates behaviour — a signature has no body to originate from,
4195 // so an edge attributed to one is not evidence about this file.
4196 disqualify(`
4197 SELECT DISTINCT n.file_path AS file_path
4198 FROM edges e JOIN nodes n ON n.id = e.source
4199 WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
4200 AND NOT ${IS_INTERFACE_MEMBER('n')}
4201 `);
4202 // (4) something outside the file depends on it — but a call that lands on
4203 // an interface's own signature is a use of the API, not a dependency on
4204 // this file's structure. The edges aimed at the interface still count.
4205 disqualify(`
4206 SELECT DISTINCT t.file_path AS file_path
4207 FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
4208 WHERE t.file_path IN ($IN$) AND s.file_path <> t.file_path
4209 AND NOT ${IS_INTERFACE_MEMBER('t')}
4210 `);
4211 for (const path of candidates) found.add(path);
4212 }
4213 return found;
4214 }

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