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

Method resolveCfmlComponentPath

src/resolution/index.ts:4175–4255  ·  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

4173 * corroborates, and the file must be named like the component.
4174 */
4175 private resolveCfmlComponentPath(ref: UnresolvedRef): ResolvedRef | null {
4176 const cfmlCandidates = (name: string): Node[] =>
4177 this.context
4178 .getNodesByName(name)
4179 .filter(
4180 (n) =>
4181 (n.kind === 'class' || n.kind === 'interface') &&
4182 (n.language === 'cfml' || n.language === 'cfscript')
4183 );
4184 const norm = (p: string): string => p.replace(/\\/g, '/').toLowerCase();
4185
4186 // Relative-path form: `../base`, `./base`, `sub/thing` — resolve against
4187 // the referencing file's directory and require an exact (case-insensitive)
4188 // file match.
4189 if (ref.referenceName.includes('/')) {
4190 const rel = ref.referenceName.replace(/\.cfc$/i, '');
4191 const fromDir = ref.filePath.replace(/\\/g, '/').split('/').slice(0, -1);
4192 const parts = [...fromDir];
4193 for (const seg of rel.split('/')) {
4194 if (seg === '' || seg === '.') continue;
4195 if (seg === '..') {
4196 if (parts.length === 0) return null; // escapes the project root
4197 parts.pop();
4198 } else {
4199 parts.push(seg);
4200 }
4201 }
4202 const wantPath = norm(parts.join('/') + '.cfc');
4203 const className = parts[parts.length - 1];
4204 if (!className) return null;
4205 const target = cfmlCandidates(className).find((c) => norm(c.filePath) === wantPath);
4206 return target
4207 ? { original: ref, targetNodeId: target.id, confidence: 0.95, resolvedBy: 'file-path' }
4208 : null;
4209 }
4210
4211 // Dotted form.
4212 const segments = ref.referenceName.split('.').map((s) => s.trim()).filter(Boolean);
4213 if (segments.length < 2) return null;
4214 const className = segments[segments.length - 1]!;
4215 const dirSegments = segments.slice(0, -1);
4216
4217 // Production code never names a component in a test suite; a test can
4218 // name one, by the path to it.
4219 const fromTest = isTestPath(ref.filePath);
4220 let bestScore = 0;
4221 let tied: Node[] = [];
4222 for (const cand of cfmlCandidates(className)) {
4223 if (!fromTest && isTestSuitePath(cand.filePath)) continue;
4224 const dirs = cand.filePath.replace(/\\/g, '/').split('/').slice(0, -1);
4225 // Count matching directory segments right-to-left: for
4226 // `coldbox.system.web.Controller` vs `system/web/Controller.cfc`,
4227 // `web` and `system` match, then the repo root ends the run → score 2.
4228 let score = 0;
4229 while (
4230 score < dirSegments.length &&
4231 score < dirs.length &&
4232 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