MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / resolveImportPath

Function resolveImportPath

src/resolution/import-resolver.ts:43–77  ·  view source on GitHub ↗
(
  importPath: string,
  fromFile: string,
  language: Language,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

41 * Resolve an import path to an actual file
42 */
43export function resolveImportPath(
44 importPath: string,
45 fromFile: string,
46 language: Language,
47 context: ResolutionContext
48): string | null {
49 // Skip external/npm packages — but pass the context so the
50 // bare-specifier heuristic can consult the project's tsconfig
51 // alias map first (custom prefixes like `@components/*` would
52 // otherwise be misclassified as npm).
53 if (isExternalImport(importPath, language, context)) {
54 return null;
55 }
56
57 const projectRoot = context.getProjectRoot();
58 const fromDir = path.dirname(path.join(projectRoot, fromFile));
59
60 // Handle relative imports
61 if (importPath.startsWith('.')) {
62 return resolveRelativeImport(importPath, fromDir, language, context);
63 }
64
65 // Handle absolute/aliased imports (like @/ or src/)
66 const aliased = resolveAliasedImport(importPath, projectRoot, language, context);
67 if (aliased) return aliased;
68
69 // C/C++ include directory search: when neither relative nor aliased
70 // resolution found a match, search -I directories from
71 // compile_commands.json or heuristic probing.
72 if (language === 'c' || language === 'cpp') {
73 return resolveCppIncludePath(importPath, language, context);
74 }
75
76 return null;
77}
78
79/**
80 * C and C++ standard library header names (without delimiters).

Callers 5

resolution.test.tsFile · 0.90
resolveViaImportFunction · 0.85
findExportedSymbolFunction · 0.85

Calls 6

isExternalImportFunction · 0.85
resolveRelativeImportFunction · 0.85
resolveAliasedImportFunction · 0.85
resolveCppIncludePathFunction · 0.85
joinMethod · 0.80
getProjectRootMethod · 0.65

Tested by

no test coverage detected