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

Function extract

src/resolution/frameworks/csharp.ts:143–314  ·  view source on GitHub ↗
(filePath, content)

Source from the content-addressed store, hash-verified

141 },
142
143 extract(filePath, content) {
144 if (!filePath.endsWith('.cs')) return { nodes: [], references: [] };
145 const nodes: Node[] = [];
146 const references: UnresolvedRef[] = [];
147 const now = Date.now();
148 const safe = stripCommentsForRegex(content, 'csharp');
149
150 // Attribute routing: each controller's own `[Route]` templates (or its
151 // base class's), each action's verb, `[AcceptVerbs]` and `[Route]`
152 // attributes, and the route tokens, as ASP.NET Core reads them (#2905).
153 const seen = new Set<string>();
154 for (const r of aspnetAttributeRoutes(safe)) {
155 const id = `route:${filePath}:${r.line}:${r.method}:${r.path}`;
156 if (seen.has(id)) continue;
157 seen.add(id);
158 nodes.push({
159 id,
160 kind: 'route',
161 name: `${r.method} ${r.path}`,
162 // A controller that declares no template takes its base class's, which
163 // postExtract reads once every file is in: the qualified name keeps
164 // what the route is made of until then (inheritedControllerRoutes).
165 qualifiedName: r.inherit
166 ? `${filePath}::aspnet-base:${r.inherit.base}:${r.inherit.controller}:${r.inherit.action}:${r.method}:${JSON.stringify(r.inherit.template)}`
167 : `${filePath}::route:${r.path}`,
168 filePath,
169 startLine: r.line,
170 endLine: r.line,
171 startColumn: 0,
172 endColumn: r.length,
173 language: 'csharp',
174 updatedAt: now,
175 });
176 references.push({
177 fromNodeId: id,
178 referenceName: r.handler,
179 referenceKind: 'references',
180 line: r.line,
181 column: 0,
182 filePath,
183 language: 'csharp',
184 });
185 }
186
187 let match: RegExpExecArray | null;
188
189 // Minimal APIs: app.MapGet("/path", handler)
190 const minimalRegex = /\.Map(Get|Post|Put|Patch|Delete)\s*\(\s*"([^"]+)"\s*,\s*([^,)]+)/g;
191 while ((match = minimalRegex.exec(safe)) !== null) {
192 const [, verb, rawPath, handlerExpr] = match;
193 // `app.MapGet("api/todos", …)` serves `/api/todos`.
194 const routePath = joinCsPath('', rawPath!);
195 const method = verb!.toUpperCase();
196 const line = lineAt(safe, match.index);
197
198 const routeNode: Node = {
199 id: `route:${filePath}:${line}:${method}:${routePath}`,
200 kind: 'route',

Callers

nothing calls this directly

Calls 10

stripCommentsForRegexFunction · 0.90
aspnetAttributeRoutesFunction · 0.90
lineAtFunction · 0.90
joinCsPathFunction · 0.85
extractCSharpTailIdentFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
execMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected