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