fix: Improve CLI progress display and prevent tree-sitter WASM memory crashes

Replaces fixed-width padding with terminal escape sequences for proper progress line clearing across different terminal widths. Adds periodic parser reset every 5000 parses per language to prevent WASM heap fragmentation that causes "memory access out of bounds" crashes in large repositories. Includes filename truncation to fit available terminal width.
This commit is contained in:
Colby McHenry
2026-04-04 10:28:07 -05:00
parent e4908e1270
commit 3a44d5c4d1
5 changed files with 64 additions and 10 deletions
+18
View File
@@ -205,10 +205,28 @@ export function getSupportedLanguages(): Language[] {
return [...(Object.keys(WASM_GRAMMAR_FILES) as GrammarLanguage[]), 'svelte', 'liquid'];
}
/**
* Reset the cached parser for a language to reclaim WASM heap memory.
* The tree-sitter WASM runtime accumulates fragmented memory over thousands
* of parses. Deleting and recreating the Parser instance forces the WASM
* heap to reset, preventing "memory access out of bounds" crashes in
* large repos.
*/
export function resetParser(language: Language): void {
const old = parserCache.get(language);
if (old) {
old.delete();
parserCache.delete(language);
}
}
/**
* Clear parser/grammar caches (useful for testing)
*/
export function clearParserCache(): void {
for (const parser of parserCache.values()) {
parser.delete();
}
parserCache.clear();
// Note: languageCache is NOT cleared — WASM languages persist.
// To fully re-init, set parserInitialized = false and call initGrammars() again.