(content: string, ext: string)
| 221 | } |
| 222 | |
| 223 | export async function parseWithTreeSitter(content: string, ext: string): Promise<CodeSymbol[] | null> { |
| 224 | const grammarName = getGrammarName(ext); |
| 225 | if (!grammarName) return null; |
| 226 | |
| 227 | const defTypes = DEFINITION_TYPES[grammarName]; |
| 228 | if (!defTypes) return null; |
| 229 | |
| 230 | const lang = await loadGrammar(grammarName); |
| 231 | if (!lang) return null; |
| 232 | |
| 233 | let parser: TSParser | null = null; |
| 234 | let tree: any = null; |
| 235 | try { |
| 236 | const Parser = await initParser(); |
| 237 | parser = new Parser(); |
| 238 | parser.setLanguage(lang); |
| 239 | tree = parser.parse(content); |
| 240 | return walkTree(tree.rootNode, defTypes); |
| 241 | } catch { |
| 242 | return null; |
| 243 | } finally { |
| 244 | tree?.delete?.(); |
| 245 | parser?.delete?.(); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | export function getSupportedExtensions(): string[] { |
| 250 | return Object.keys(EXT_TO_GRAMMAR); |
no test coverage detected