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

Function resolveInclude

src/resolution/cpp-macro-visibility.ts:248–282  ·  view source on GitHub ↗
(
  file: string,
  quote: string,
  spec: string,
  language: UnresolvedRef['language'],
  context: ResolutionContext,
  cache: Cache
)

Source from the content-addressed store, hash-verified

246}
247
248function resolveInclude(
249 file: string,
250 quote: string,
251 spec: string,
252 language: UnresolvedRef['language'],
253 context: ResolutionContext,
254 cache: Cache
255): string | null {
256 const key = `${language}\0${file}\0${quote}${spec}`;
257 const cached = cache.includes.get(key);
258 if (cached !== undefined) return cached;
259 const local = path.posix.normalize(path.posix.join(path.posix.dirname(file), spec.replace(/\\/g, '/')));
260 let target =
261 quote === '"' && !local.startsWith('../') && !path.posix.isAbsolute(local) && context.fileExists(local)
262 ? local
263 : resolveImportPath(spec, file, language, context);
264 if (!target) {
265 if (!cache.byBasename) {
266 cache.byBasename = new Map();
267 for (const f of context.getAllFiles()) {
268 const base = f.slice(f.lastIndexOf('/') + 1);
269 const list = cache.byBasename.get(base);
270 if (list) list.push(f);
271 else cache.byBasename.set(base, [f]);
272 }
273 }
274 const normalized = spec.replace(/\\/g, '/');
275 const matches = (cache.byBasename.get(normalized.slice(normalized.lastIndexOf('/') + 1)) ?? []).filter(
276 (f) => f === normalized || f.endsWith('/' + normalized)
277 );
278 if (matches.length === 1) target = matches[0]!;
279 }
280 cache.includes.set(key, target);
281 return target;
282}
283
284function walkTranslationUnit(
285 rootFile: string,

Callers 1

scanFunction · 0.70

Calls 8

resolveImportPathFunction · 0.90
normalizeMethod · 0.80
fileExistsMethod · 0.80
pushMethod · 0.80
getMethod · 0.65
getAllFilesMethod · 0.65
joinMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected