* Parse a Django URL handler expression and return the symbol/module to link. * Returns null for shapes we can't confidently link (e.g. lambdas).
(expr: string)
| 162 | * Returns null for shapes we can't confidently link (e.g. lambdas). |
| 163 | */ |
| 164 | function resolveHandlerName(expr: string): { name: string; kind: 'references' | 'imports' } | null { |
| 165 | // include('module.path') |
| 166 | const includeMatch = expr.match(/^include\s*\(\s*['"]([^'"]+)['"]/); |
| 167 | if (includeMatch) return { name: includeMatch[1]!, kind: 'imports' }; |
| 168 | |
| 169 | // Strip trailing .as_view(...) or .as_view() |
| 170 | let head = expr.replace(/\.as_view\s*\([^)]*\)\s*$/, ''); |
| 171 | // Drop any other trailing method call |
| 172 | head = head.replace(/\.\w+\s*\([^)]*\)\s*$/, ''); |
| 173 | |
| 174 | const dotted = head.split('.').filter(Boolean); |
| 175 | if (dotted.length === 0) return null; |
| 176 | const last = dotted[dotted.length - 1]!; |
| 177 | if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(last)) return null; |
| 178 | |
| 179 | return { name: last, kind: 'references' }; |
| 180 | } |
| 181 | |
| 182 | export const flaskResolver: FrameworkResolver = { |
| 183 | name: 'flask', |