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

Method getRazorUsings

src/resolution/index.ts:2116–2136  ·  view source on GitHub ↗

* Collect the `@using` namespaces in scope for a `.razor`/`.cshtml` file: its * own `@using` directives plus every `_Imports.razor` from the file's folder up * to the project root (Razor `_Imports` cascade). Cached per file.

(filePath: string)

Source from the content-addressed store, hash-verified

2114 * to the project root (Razor `_Imports` cascade). Cached per file.
2115 */
2116 private getRazorUsings(filePath: string): string[] {
2117 const cached = this.razorUsingsCache.get(filePath);
2118 if (cached) return cached;
2119 const usings = new Set<string>();
2120 const addFrom = (src: string | null): void => {
2121 if (!src) return;
2122 for (const m of src.matchAll(/^\s*@using\s+(?:static\s+)?([A-Za-z_][\w.]*)/gm)) usings.add(m[1]!);
2123 };
2124 addFrom(this.context.readFile(filePath));
2125 let dir = filePath.includes('/') ? filePath.slice(0, filePath.lastIndexOf('/')) : '';
2126 // Walk up to the project root, reading each level's _Imports.razor.
2127 for (;;) {
2128 addFrom(this.context.readFile(dir ? `${dir}/_Imports.razor` : '_Imports.razor'));
2129 if (!dir) break;
2130 const slash = dir.lastIndexOf('/');
2131 dir = slash >= 0 ? dir.slice(0, slash) : '';
2132 }
2133 const arr = [...usings];
2134 this.razorUsingsCache.set(filePath, arr);
2135 return arr;
2136 }
2137
2138 /**
2139 * Resolve a Razor/Blazor simple type ref through the file's `@using`

Callers 1

resolveRazorUsingMethod · 0.95

Calls 3

readFileMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected