(filePath, content)
| 92 | }, |
| 93 | |
| 94 | extract(filePath, content) { |
| 95 | if (!filePath.endsWith('.rs')) return { nodes: [], references: [] }; |
| 96 | const nodes: Node[] = []; |
| 97 | const references: UnresolvedRef[] = []; |
| 98 | const now = Date.now(); |
| 99 | const safe = stripCommentsForRegex(content, 'rust'); |
| 100 | // Where a handler's own name is written, for the handler expression `expr` |
| 101 | // ending at `exprEnd`: the Rust scope gate reads the reference's line, and |
| 102 | // rustfmt wraps a long `.route(` call so its handler sits below it (#2326). |
| 103 | const handlerSite = (exprEnd: number, expr: string, handler: string) => { |
| 104 | const offset = exprEnd - expr.length + expr.lastIndexOf(handler); |
| 105 | return { line: safe.slice(0, offset).split('\n').length, column: offset - safe.lastIndexOf('\n', offset - 1) - 1 }; |
| 106 | }; |
| 107 | |
| 108 | // Actix-web / Rocket attribute: #[get("/path")] fn handler(..) |
| 109 | // Capture the method, path, and the fn identifier that follows. |
| 110 | const attrRegex = /#\[(get|post|put|patch|delete|head|options)\s*\(\s*["']([^"']+)["'][^\]]*\)\]/g; |
| 111 | let match: RegExpExecArray | null; |
| 112 | while ((match = attrRegex.exec(safe)) !== null) { |
| 113 | const [, method, routePath] = match; |
| 114 | const line = safe.slice(0, match.index).split('\n').length; |
| 115 | const upper = method!.toUpperCase(); |
| 116 | |
| 117 | const routeNode: Node = { |
| 118 | id: `route:${filePath}:${line}:${upper}:${routePath}`, |
| 119 | kind: 'route', |
| 120 | name: `${upper} ${routePath}`, |
| 121 | qualifiedName: `${filePath}::route:${routePath}`, |
| 122 | filePath, |
| 123 | startLine: line, |
| 124 | endLine: line, |
| 125 | startColumn: 0, |
| 126 | endColumn: match[0].length, |
| 127 | language: 'rust', |
| 128 | updatedAt: now, |
| 129 | }; |
| 130 | nodes.push(routeNode); |
| 131 | |
| 132 | const tail = safe.slice(match.index + match[0].length); |
| 133 | const fnMatch = tail.match(/\n\s*(?:pub\s+)?(?:async\s+)?fn\s+(\w+)/); |
| 134 | if (fnMatch) { |
| 135 | references.push({ |
| 136 | fromNodeId: routeNode.id, |
| 137 | referenceName: fnMatch[1]!, |
| 138 | referenceKind: 'references', |
| 139 | line, |
| 140 | column: 0, |
| 141 | filePath, |
| 142 | language: 'rust', |
| 143 | }); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Axum: .route("/path", get(h1).post(h2)…) — balanced-paren scan the route |
| 148 | // call, then emit one route node per chained method. Handlers may be |
| 149 | // namespaced (`get(module::handler)`, `get(self::list)`); take the last |
| 150 | // path segment so the ref names the fn, not the module. |
| 151 | const routeOpenRegex = /\.route\s*\(/g; |
nothing calls this directly
no test coverage detected