MCPcopy
hub / github.com/colbymchenry/codegraph / createContext

Method createContext

src/resolution/index.ts:335–516  ·  view source on GitHub ↗

* Create the resolution context

()

Source from the content-addressed store, hash-verified

333 * Create the resolution context
334 */
335 private createContext(): ResolutionContext {
336 return {
337 getNodesInFile: (filePath: string) => {
338 if (!this.nodeCache.has(filePath)) {
339 this.nodeCache.set(filePath, this.queries.getNodesByFile(filePath));
340 }
341 return this.nodeCache.get(filePath)!;
342 },
343
344 getNodesByName: (name: string) => {
345 const cached = this.nameCache.get(name);
346 if (cached !== undefined) return cached;
347 const result = this.queries.getNodesByName(name);
348 this.nameCache.set(name, result);
349 return result;
350 },
351
352 getNodesByQualifiedName: (qualifiedName: string) => {
353 const cached = this.qualifiedNameCache.get(qualifiedName);
354 if (cached !== undefined) return cached;
355 const result = this.queries.getNodesByQualifiedNameExact(qualifiedName);
356 this.qualifiedNameCache.set(qualifiedName, result);
357 return result;
358 },
359
360 getNodesByKind: (kind: Node['kind']) => {
361 return this.queries.getNodesByKind(kind);
362 },
363
364 fileExists: (filePath: string) => {
365 // Check pre-built known files set first (O(1))
366 if (this.knownFiles) {
367 const normalized = filePath.replace(/\\/g, '/');
368 if (this.knownFiles.has(filePath) || this.knownFiles.has(normalized)) {
369 return true;
370 }
371 }
372 // Fall back to filesystem for files not yet indexed
373 const fullPath = path.join(this.projectRoot, filePath);
374 try {
375 return fs.existsSync(fullPath);
376 } catch (error) {
377 logDebug('Error checking file existence', { filePath, error: String(error) });
378 return false;
379 }
380 },
381
382 readFile: (filePath: string) => {
383 if (this.fileCache.has(filePath)) {
384 return this.fileCache.get(filePath)!;
385 }
386
387 const fullPath = path.join(this.projectRoot, filePath);
388 try {
389 const content = fs.readFileSync(fullPath, 'utf-8');
390 this.fileCache.set(filePath, content);
391 return content;
392 } catch (error) {

Callers 1

constructorMethod · 0.95

Calls 15

logDebugFunction · 0.90
extractImportMappingsFunction · 0.90
loadProjectAliasesFunction · 0.90
loadGoModuleFunction · 0.90
loadWorkspacePackagesFunction · 0.90
extractReExportsFunction · 0.90
loadCppIncludeDirsFunction · 0.90
hasMethod · 0.80
setMethod · 0.80
getNodesByFileMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected