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

Method createContext

src/resolution/index.ts:974–1382  ·  view source on GitHub ↗

* Create the resolution context

()

Source from the content-addressed store, hash-verified

972 * Create the resolution context
973 */
974 private createContext(): ResolutionContext {
975 return {
976 // A C or C++ `#include` the import resolver can't place is linked by the
977 // end of its path, as resolveOneInner's name matching does: protobuf's
978 // `google/protobuf/descriptor.upb.h`, which two generated copies end in.
979 // cppIncluders reads includes through this, so it sees the include edges
980 // a reader sees. A standard header is never the project's: `<math.h>`
981 // is not jemalloc's test/math.h, which only its includers may see.
982 resolveImport: (ref) => resolveViaImport(ref, this.context) ??
983 ((ref.language === 'c' || ref.language === 'cpp') && ref.referenceKind === 'imports' &&
984 !isExternalImport(ref.referenceName, ref.language, this.context) ? matchByFilePath(ref, this.context) : null),
985 // A path alias makes an import the project's only when it maps the
986 // import to a file the index holds. Matching its prefix is not enough:
987 // cord-field's `"*": ["./typings/*"]` matches every package, and
988 // counting the match bound 169 imports of `@mui/material`'s Typography
989 // to its own. Nor is a path that exists on disk: home-assistant's
990 // `"lit/decorators": ["./node_modules/lit/decorators.js"]` lands in
991 // `node_modules`, topcoder's `config` package on its `config/` folder.
992 isOutOfRepoImport: (source, fromFile, language) => {
993 if (!isExternalImport(source, language, this.context, { aliasPrefixes: false, fromFile })) return false;
994 const resolved = resolveImportPath(source, fromFile, language, this.context);
995 if (resolved !== null && this.isIndexedFile(resolved)) return false;
996 return this.isDeclaredOutsidePackage(source, fromFile) ||
997 (ESM_IMPORT_LANGUAGES.has(language) && this.isInstalledPackage(source, fromFile));
998 },
999 resolveModuleFile: (source, fromFile, language) =>
1000 resolveImportPath(source, fromFile, language, this.context),
1001 isDeclaredPackage: (source, fromFile) => this.isDeclaredOutsidePackage(source, fromFile),
1002 isIndexedFile: (filePath) => this.isIndexedFile(filePath),
1003 getNodesInFile: (filePath: string) => {
1004 if (!this.nodeCache.has(filePath)) {
1005 this.nodeCache.set(filePath, this.queries.getNodesByFile(filePath));
1006 }
1007 return this.nodeCache.get(filePath)!;
1008 },
1009
1010 fileHasExportedNode: (filePath: string) => {
1011 const cached = this.nodeCache.get(filePath);
1012 return cached !== undefined ? cached.some((n) => n.isExported) : this.queries.fileHasExportedNode(filePath);
1013 },
1014
1015 getExportedNodesInFile: (filePath: string) => {
1016 const cached = this.nodeCache.get(filePath);
1017 return cached !== undefined ? cached.filter((n) => n.isExported) : this.queries.getExportedNodesByFile(filePath);
1018 },
1019
1020 getNodesInFileNamed: (filePath: string, name: string) => {
1021 const cached = this.nodeCache.get(filePath);
1022 return cached !== undefined ? cached.filter((n) => n.name === name) : this.queries.getNodesByFileAndName(filePath, name);
1023 },
1024
1025 getNodesByName: (name: string) => {
1026 const cached = this.nameCache.get(name);
1027 if (cached !== undefined) return cached;
1028 const result = this.queries.getNodesByName(name);
1029 this.nameCache.set(name, result);
1030 return result;
1031 },

Callers 1

constructorMethod · 0.95

Calls 15

isIndexedFileMethod · 0.95
isInstalledPackageMethod · 0.95
readFileCachedMethod · 0.95
fileContainsMethod · 0.95
scanFileMethod · 0.95
nodeByIdMethod · 0.95
phpWebRootOfMethod · 0.95
nearestGoModuleMethod · 0.95
getGoModulesMethod · 0.95
readCargoCratesMethod · 0.95
resolveViaImportFunction · 0.90

Tested by

no test coverage detected