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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user