Explorar o código

Merge branch 'main' into delphi-support

Colby Mchenry hai 4 meses
pai
achega
544d193086
Modificáronse 1 ficheiros con 10 adicións e 11 borrados
  1. 10 11
      src/extraction/grammars.ts

+ 10 - 11
src/extraction/grammars.ts

@@ -94,24 +94,23 @@ export async function initGrammars(): Promise<void> {
 
   await Parser.init();
 
-  // Load all grammars in parallel
+  // Load grammars sequentially to avoid web-tree-sitter WASM race condition on Node 20+
+  // See: https://github.com/tree-sitter/tree-sitter/issues/2338
   const entries = Object.entries(WASM_GRAMMAR_FILES) as [GrammarLanguage, string][];
-  await Promise.allSettled(
-    entries.map(async ([lang, wasmFile]) => {
-      try {
+  for (const [lang, wasmFile] of entries) {
+    try {
         // Pascal ships its own WASM (not in tree-sitter-wasms)
         const wasmPath = lang === 'pascal'
           ? path.join(__dirname, 'wasm', wasmFile)
           : require.resolve(`tree-sitter-wasms/out/${wasmFile}`);
         const language = await WasmLanguage.load(wasmPath);
         languageCache.set(lang, language);
-      } catch (error) {
-        const message = error instanceof Error ? error.message : String(error);
-        console.warn(`[CodeGraph] Failed to load ${lang} grammar — parsing will be unavailable: ${message}`);
-        unavailableGrammarErrors.set(lang, message);
-      }
-    })
-  );
+    } catch (error) {
+      const message = error instanceof Error ? error.message : String(error);
+      console.warn(`[CodeGraph] Failed to load ${lang} grammar — parsing will be unavailable: ${message}`);
+      unavailableGrammarErrors.set(lang, message);
+    }
+  }
 
   grammarsInitialized = true;
 }