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

Function resolveInclude

src/resolution/cpp-macro-visibility.ts:212–246  ·  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

210}
211
212function resolveInclude(
213 file: string,
214 quote: string,
215 spec: string,
216 language: UnresolvedRef['language'],
217 context: ResolutionContext,
218 cache: Cache
219): string | null {
220 const key = `${language}\0${file}\0${quote}${spec}`;
221 const cached = cache.includes.get(key);
222 if (cached !== undefined) return cached;
223 const local = path.posix.normalize(path.posix.join(path.posix.dirname(file), spec.replace(/\\/g, '/')));
224 let target =
225 quote === '"' && !local.startsWith('../') && !path.posix.isAbsolute(local) && context.fileExists(local)
226 ? local
227 : resolveImportPath(spec, file, language, context);
228 if (!target) {
229 if (!cache.byBasename) {
230 cache.byBasename = new Map();
231 for (const f of context.getAllFiles()) {
232 const base = f.slice(f.lastIndexOf('/') + 1);
233 const list = cache.byBasename.get(base);
234 if (list) list.push(f);
235 else cache.byBasename.set(base, [f]);
236 }
237 }
238 const normalized = spec.replace(/\\/g, '/');
239 const matches = (cache.byBasename.get(normalized.slice(normalized.lastIndexOf('/') + 1)) ?? []).filter(
240 (f) => f === normalized || f.endsWith('/' + normalized)
241 );
242 if (matches.length === 1) target = matches[0]!;
243 }
244 cache.includes.set(key, target);
245 return target;
246}
247
248function walkTranslationUnit(
249 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