MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / loadGrammarsForLanguages

Function loadGrammarsForLanguages

src/extraction/grammars.ts:404–432  ·  view source on GitHub ↗
(languages: Language[], wasmBytes?: Record<string, Uint8Array>)

Source from the content-addressed store, hash-verified

402 * language's bytes are present they're loaded from memory instead of disk.
403 */
404export async function loadGrammarsForLanguages(languages: Language[], wasmBytes?: Record<string, Uint8Array>): Promise<void> {
405 if (!parserInitialized) {
406 await initGrammars();
407 }
408
409 languages = expandGrammarLanguages(languages);
410
411 // Deduplicate and filter to languages that have WASM grammars and aren't already loaded
412 const toLoad = [...new Set(languages)].filter(
413 (lang): lang is GrammarLanguage =>
414 lang in WASM_GRAMMAR_FILES &&
415 !languageCache.has(lang) &&
416 !unavailableGrammarErrors.has(lang)
417 );
418
419 // Load grammars sequentially to avoid web-tree-sitter WASM race condition on Node 20+
420 // See: https://github.com/tree-sitter/tree-sitter/issues/2338
421 for (const lang of toLoad) {
422 try {
423 const bytes = wasmBytes?.[lang];
424 const language = await WasmLanguage.load(bytes ?? resolveWasmPath(lang));
425 languageCache.set(lang, language);
426 } catch (error) {
427 const message = error instanceof Error ? error.message : String(error);
428 console.warn(`[CodeGraph] Failed to load ${lang} grammar — parsing will be unavailable: ${message}`);
429 unavailableGrammarErrors.set(lang, message);
430 }
431 }
432}
433
434/**
435 * Load ALL grammar WASM files. Convenience function for tests and

Calls 6

initGrammarsFunction · 0.85
expandGrammarLanguagesFunction · 0.85
resolveWasmPathFunction · 0.85
hasMethod · 0.80
warnMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected