(node: TSNode, depth: number, parent: CodeSymbol | null)
| 182 | const symbols: CodeSymbol[] = []; |
| 183 | |
| 184 | function visit(node: TSNode, depth: number, parent: CodeSymbol | null): void { |
| 185 | if (depth > maxDepth) return; |
| 186 | |
| 187 | const kindStr = defTypes[node.type]; |
| 188 | if (kindStr) { |
| 189 | const sym: CodeSymbol = { |
| 190 | name: extractName(node, kindStr), |
| 191 | kind: mapKind(kindStr), |
| 192 | line: node.startPosition.row + 1, |
| 193 | endLine: node.endPosition.row + 1, |
| 194 | signature: extractSignature(node), |
| 195 | children: [], |
| 196 | }; |
| 197 | |
| 198 | if (parent && depth > 0) { |
| 199 | parent.children.push(sym); |
| 200 | } else { |
| 201 | symbols.push(sym); |
| 202 | } |
| 203 | |
| 204 | for (const child of node.namedChildren ?? []) { |
| 205 | visit(child, depth + 1, sym); |
| 206 | } |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | for (const child of node.namedChildren ?? []) { |
| 211 | visit(child, depth, parent); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | visit(rootNode, 0, null); |
| 216 | return symbols; |
no test coverage detected