MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / parseWithTreeSitter

Function parseWithTreeSitter

src/core/tree-sitter.ts:223–247  ·  view source on GitHub ↗
(content: string, ext: string)

Source from the content-addressed store, hash-verified

221}
222
223export 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
249export function getSupportedExtensions(): string[] {
250 return Object.keys(EXT_TO_GRAMMAR);

Callers 2

analyzeFileFunction · 0.85

Calls 4

getGrammarNameFunction · 0.85
loadGrammarFunction · 0.85
initParserFunction · 0.85
walkTreeFunction · 0.85

Tested by

no test coverage detected