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

Function viewFile

src/resolution/frameworks/codeigniter.ts:233–252  ·  view source on GitHub ↗

The file the `$this->load->view('users/list')` on this line loads: the caller's module's, another module's, or the app's.

(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

231
232/** The file the `$this->load->view('users/list')` on this line loads: the caller's module's, another module's, or the app's. */
233function viewFile(ref: UnresolvedRef, context: ResolutionContext): Node | null {
234 const line = context.getFileLines?.(ref.filePath)?.[ref.line - 1];
235 const view = line ? VIEW_RE.exec(line)?.[1] : undefined;
236 if (!view) return null;
237 const file = /\.\w+$/.test(view) ? view : `${view}.php`;
238 const root = ref.filePath.slice(0, Math.max(ref.filePath.indexOf('application/'), 0));
239 const module = MODULE_OF.exec(ref.filePath);
240 const modules = module ? ref.filePath.slice(0, module.index + module[0].length - module[1]!.length - 1) : `${root}application/modules/`;
241 const slash = file.indexOf('/');
242 const candidates = [
243 ...(module ? [`${modules}${module[1]}/views/${file}`] : []),
244 ...(slash > 0 ? [`${modules}${file.slice(0, slash)}/views/${file.slice(slash + 1)}`] : []),
245 `${root}application/views/${file}`,
246 ];
247 for (const candidate of candidates) {
248 const node = context.getNodesInFile(candidate).find((n) => n.kind === 'file');
249 if (node) return node;
250 }
251 return null;
252}
253
254function aliasesIn(file: string, table: ClassTable, context: ResolutionContext): Map<string, string> {
255 const known = table.aliases.get(file);

Callers 1

resolveFunction · 0.85

Calls 3

getFileLinesMethod · 0.80
execMethod · 0.65
getNodesInFileMethod · 0.65

Tested by

no test coverage detected