MCPcopy
hub / github.com/zgsm-ai/costrict / inspectTreeStructure

Function inspectTreeStructure

src/services/tree-sitter/__tests__/helpers.ts:123–140  ·  view source on GitHub ↗
(content: string, language: string = "typescript")

Source from the content-addressed store, hash-verified

121
122// Helper function to inspect tree structure
123export 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}

Calls 7

initializeTreeSitterFunction · 0.85
parseMethod · 0.80
debugLogFunction · 0.70
replaceMethod · 0.65
toStringMethod · 0.65
cwdMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected