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

Method createContext

src/resolution/index.ts:876–1278  ·  view source on GitHub ↗

* Create the resolution context

()

Source from the content-addressed store, hash-verified

874 * Create the resolution context
875 */
876 private createContext(): ResolutionContext {
877 return {
878 // A C or C++ `#include` the import resolver can't place is linked by the
879 // end of its path, as resolveOneInner's name matching does: protobuf's
880 // `google/protobuf/descriptor.upb.h`, which two generated copies end in.
881 // cppIncluders reads includes through this, so it sees the include edges
882 // a reader sees. A standard header is never the project's: `<math.h>`
883 // is not jemalloc's test/math.h, which only its includers may see.
884 resolveImport: (ref) => resolveViaImport(ref, this.context) ??
885 ((ref.language === 'c' || ref.language === 'cpp') && ref.referenceKind === 'imports' &&
886 !isExternalImport(ref.referenceName, ref.language, this.context) ? matchByFilePath(ref, this.context) : null),
887 // A path alias makes an import the project's only when it maps the
888 // import to a file the index holds. Matching its prefix is not enough:
889 // cord-field's `"*": ["./typings/*"]` matches every package, and
890 // counting the match bound 169 imports of `@mui/material`'s Typography
891 // to its own. Nor is a path that exists on disk: home-assistant's
892 // `"lit/decorators": ["./node_modules/lit/decorators.js"]` lands in
893 // `node_modules`, topcoder's `config` package on its `config/` folder.
894 isOutOfRepoImport: (source, fromFile, language) => {
895 if (!isExternalImport(source, language, this.context, { aliasPrefixes: false, fromFile })) return false;
896 const resolved = resolveImportPath(source, fromFile, language, this.context);
897 if (resolved !== null && this.isIndexedFile(resolved)) return false;
898 return this.isDeclaredOutsidePackage(source, fromFile);
899 },
900 resolveModuleFile: (source, fromFile, language) =>
901 resolveImportPath(source, fromFile, language, this.context),
902 isDeclaredPackage: (source, fromFile) => this.isDeclaredOutsidePackage(source, fromFile),
903 isIndexedFile: (filePath) => this.isIndexedFile(filePath),
904 getNodesInFile: (filePath: string) => {
905 if (!this.nodeCache.has(filePath)) {
906 this.nodeCache.set(filePath, this.queries.getNodesByFile(filePath));
907 }
908 return this.nodeCache.get(filePath)!;
909 },
910
911 fileHasExportedNode: (filePath: string) => {
912 const cached = this.nodeCache.get(filePath);
913 return cached !== undefined ? cached.some((n) => n.isExported) : this.queries.fileHasExportedNode(filePath);
914 },
915
916 getExportedNodesInFile: (filePath: string) => {
917 const cached = this.nodeCache.get(filePath);
918 return cached !== undefined ? cached.filter((n) => n.isExported) : this.queries.getExportedNodesByFile(filePath);
919 },
920
921 getNodesInFileNamed: (filePath: string, name: string) => {
922 const cached = this.nodeCache.get(filePath);
923 return cached !== undefined ? cached.filter((n) => n.name === name) : this.queries.getNodesByFileAndName(filePath, name);
924 },
925
926 getNodesByName: (name: string) => {
927 const cached = this.nameCache.get(name);
928 if (cached !== undefined) return cached;
929 const result = this.queries.getNodesByName(name);
930 this.nameCache.set(name, result);
931 return result;
932 },
933

Callers 1

constructorMethod · 0.95

Calls 15

isIndexedFileMethod · 0.95
readFileCachedMethod · 0.95
fileContainsMethod · 0.95
scanFileMethod · 0.95
nodeByIdMethod · 0.95
nearestGoModuleMethod · 0.95
getGoModulesMethod · 0.95
readCargoCratesMethod · 0.95
resolveViaImportFunction · 0.90
isExternalImportFunction · 0.90
resolveImportPathFunction · 0.90

Tested by

no test coverage detected