MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / initTreeSitter

Function initTreeSitter

src/tools/ast/parser.ts:37–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35}
36
37async function initTreeSitter(): Promise<void> {
38 if (TreeSitter) return;
39 try {
40 const mod: any = await import('web-tree-sitter');
41 // web-tree-sitter changed its public shape at v0.25:
42 // - old (<=0.24): default export is the Parser class; Parser.init();
43 // grammars load via Parser.Language.load(path).
44 // - new (>=0.25): named exports `Parser` and `Language`; Parser.init();
45 // grammars load via Language.load(path).
46 // Support BOTH so a runtime bump to read ABI-15 grammars doesn't break us.
47 const ParserCtor = mod.Parser ?? mod.default ?? mod;
48 TreeSitter = ParserCtor;
49 TSLanguage = mod.Language ?? ParserCtor?.Language ?? null;
50 if (typeof ParserCtor.init === 'function') {
51 await ParserCtor.init();
52 }
53 } catch (e: any) {
54 throw new Error(`Failed to initialize Tree-sitter: ${e.message}. AST tools will be unavailable.`);
55 }
56}
57
58export async function getParser(language: string): Promise<{ parser: any; language: any } | null> {
59 try {

Callers 2

getParserFunction · 0.85
diagnoseGrammarFunction · 0.85

Calls 1

initMethod · 0.80

Tested by

no test coverage detected