(content: string, language: string = "typescript")
| 121 | |
| 122 | // Helper function to inspect tree structure |
| 123 | export async function inspectTreeStructure(content: string, language: string = "typescript"): Promise<string> { |
| 124 | const { Parser, Language } = await initializeTreeSitter() |
| 125 | const parser = new Parser() |
| 126 | const cwd = process.cwd() |
| 127 | const normalizedCwd = cwd.replace(/\\/g, "/") |
| 128 | const wasmPath = normalizedCwd.endsWith("/src") |
| 129 | ? path.join(cwd, `dist/tree-sitter-${language}.wasm`) |
| 130 | : path.join(cwd, `src/dist/tree-sitter-${language}.wasm`) |
| 131 | const lang = await Language.load(wasmPath) |
| 132 | parser.setLanguage(lang) |
| 133 | |
| 134 | // Parse the content |
| 135 | const tree = parser.parse(content) |
| 136 | |
| 137 | // Print the tree structure |
| 138 | debugLog(`TREE STRUCTURE (${language}):\n${tree?.rootNode.toString()}`) |
| 139 | return tree?.rootNode.toString() || "" |
| 140 | } |
no test coverage detected