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

Method resolveCfmlComponentPath

src/resolution/index.ts:4258–4338  ·  view source on GitHub ↗

* Resolve a CFML inheritance reference written as a component path (#1152). * Two forms exist in real code: * * - Dotted: `extends="coldbox.system.web.Controller"` — dots are directory * separators from the webroot or a CFML mapping. Mappings live in server * config / Application.

(ref: UnresolvedRef)

Source from the content-addressed store, hash-verified

4256 * corroborates, and the file must be named like the component.
4257 */
4258 private resolveCfmlComponentPath(ref: UnresolvedRef): ResolvedRef | null {
4259 const cfmlCandidates = (name: string): Node[] =>
4260 this.context
4261 .getNodesByName(name)
4262 .filter(
4263 (n) =>
4264 (n.kind === 'class' || n.kind === 'interface') &&
4265 (n.language === 'cfml' || n.language === 'cfscript')
4266 );
4267 const norm = (p: string): string => p.replace(/\\/g, '/').toLowerCase();
4268
4269 // Relative-path form: `../base`, `./base`, `sub/thing` — resolve against
4270 // the referencing file's directory and require an exact (case-insensitive)
4271 // file match.
4272 if (ref.referenceName.includes('/')) {
4273 const rel = ref.referenceName.replace(/\.cfc$/i, '');
4274 const fromDir = ref.filePath.replace(/\\/g, '/').split('/').slice(0, -1);
4275 const parts = [...fromDir];
4276 for (const seg of rel.split('/')) {
4277 if (seg === '' || seg === '.') continue;
4278 if (seg === '..') {
4279 if (parts.length === 0) return null; // escapes the project root
4280 parts.pop();
4281 } else {
4282 parts.push(seg);
4283 }
4284 }
4285 const wantPath = norm(parts.join('/') + '.cfc');
4286 const className = parts[parts.length - 1];
4287 if (!className) return null;
4288 const target = cfmlCandidates(className).find((c) => norm(c.filePath) === wantPath);
4289 return target
4290 ? { original: ref, targetNodeId: target.id, confidence: 0.95, resolvedBy: 'file-path' }
4291 : null;
4292 }
4293
4294 // Dotted form.
4295 const segments = ref.referenceName.split('.').map((s) => s.trim()).filter(Boolean);
4296 if (segments.length < 2) return null;
4297 const className = segments[segments.length - 1]!;
4298 const dirSegments = segments.slice(0, -1);
4299
4300 // Production code never names a component in a test suite; a test can
4301 // name one, by the path to it.
4302 const fromTest = isTestPath(ref.filePath);
4303 let bestScore = 0;
4304 let tied: Node[] = [];
4305 for (const cand of cfmlCandidates(className)) {
4306 if (!fromTest && isTestSuitePath(cand.filePath)) continue;
4307 const dirs = cand.filePath.replace(/\\/g, '/').split('/').slice(0, -1);
4308 // Count matching directory segments right-to-left: for
4309 // `coldbox.system.web.Controller` vs `system/web/Controller.cfc`,
4310 // `web` and `system` match, then the repo root ends the run → score 2.
4311 let score = 0;
4312 while (
4313 score < dirSegments.length &&
4314 score < dirs.length &&
4315 dirSegments[dirSegments.length - 1 - score]!.toLowerCase() ===

Callers 2

resolveOneInnerMethod · 0.95

Calls 5

isTestPathFunction · 0.90
pushMethod · 0.80
mapMethod · 0.80
normFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected