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

Function csharpNamespaceScope

src/resolution/name-matcher.ts:4216–4236  ·  view source on GitHub ↗

* The namespaces a C# file's code runs in and the ones it imports: its * `namespace` declarations, its `using X;`, the `global using X;` of its * project's files (every file's, outside any project) and the * ` ` of the project files above it.

(file: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

4214 * `<Using Include="X" />` of the project files above it.
4215 */
4216function csharpNamespaceScope(file: string, context: ResolutionContext): { namespaces: string[]; usings: Set<string>; aliases: Map<string, string> } {
4217 let memo = CSHARP_NAMESPACE_SCOPES.get(context);
4218 if (!memo) CSHARP_NAMESPACE_SCOPES.set(context, (memo = new Map()));
4219 const hit = memo.get(file);
4220 if (hit) return hit;
4221 const text = stripCommentsForRegex(context.readFile(file) ?? '', 'java');
4222 const namespaces = [...text.matchAll(/^\s*namespace\s+([\w.]+)/gm)].map((m) => m[1]!);
4223 let projectMemo = CSHARP_PROJECT_USINGS.get(context);
4224 if (!projectMemo) CSHARP_PROJECT_USINGS.set(context, (projectMemo = new Map()));
4225 const project = csharpProjectUsings(path.posix.dirname(file), context, projectMemo);
4226 const usings = new Set<string>(project.usings);
4227 if (!project.project) for (const u of csharpGlobalUsings('.', context)) usings.add(u);
4228 const aliases = new Map<string, string>();
4229 for (const m of text.matchAll(/^\s*(?:global\s+)?using\s+(?!static\b)(?:([A-Za-z_]\w*)\s*=\s*)?([\w.]+)\s*;/gm)) {
4230 if (m[1]) aliases.set(m[1], m[2]!);
4231 else usings.add(m[2]!);
4232 }
4233 const scope = { namespaces, usings, aliases };
4234 memo.set(file, scope);
4235 return scope;
4236}
4237
4238/**
4239 * The `<Using Include="X" />` of the project files from `dir` up, and the

Callers 1

isCsharpTypeVisibleFunction · 0.85

Calls 8

stripCommentsForRegexFunction · 0.90
csharpProjectUsingsFunction · 0.85
csharpGlobalUsingsFunction · 0.85
readFileMethod · 0.80
mapMethod · 0.80
addMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected