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

Function viewFile

src/resolution/frameworks/codeigniter.ts:235–254  ·  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

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