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

Function nearestHelper

src/resolution/pascal-scope.ts:2035–2044  ·  view source on GitHub ↗

* The helper for a class that applies in a file: of those its unit declares * or uses, its own unit's, else the one of the unit it uses last, the one * declared last of them. Null when none does.

(cls: Node, fromFile: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

2033 * declared last of them. Null when none does.
2034 */
2035function nearestHelper(cls: Node, fromFile: string, context: ResolutionContext): Node | null {
2036 const helpers = helpersByType(context).get(cls.id);
2037 if (!helpers) return null;
2038 const own = ownUnitFiles(fromFile, context);
2039 const used = usedUnitFiles(fromFile, context);
2040 // How near a helper's unit is: its own unit's nearest, then the units used last.
2041 const rank = (file: string): number => (own.includes(file) ? Infinity : used.indexOf(file));
2042 return helpers.filter((h) => rank(h.filePath) >= 0)
2043 .sort((a, b) => rank(b.filePath) - rank(a.filePath) || b.startLine - a.startLine)[0] ?? null;
2044}
2045
2046/** A member a helper declares, or one of the helpers it descends from. */
2047function helperChainMember(helper: Node | null, lower: string, context: ResolutionContext): Node | null {

Callers 2

memberOfValueFunction · 0.85
helperMemberFunction · 0.85

Calls 5

helpersByTypeFunction · 0.85
ownUnitFilesFunction · 0.85
usedUnitFilesFunction · 0.85
rankFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected