diff --git a/packages/core/src/utils/shell-utils.ts b/packages/core/src/utils/shell-utils.ts index b35bfd815a..c6150ab4b3 100644 --- a/packages/core/src/utils/shell-utils.ts +++ b/packages/core/src/utils/shell-utils.ts @@ -164,8 +164,9 @@ async function loadBashLanguage(): Promise { export async function initializeShellParsers(): Promise { if (!treeSitterInitialization) { + let timerId: NodeJS.Timeout | undefined; const timeoutPromise = new Promise((_, reject) => { - setTimeout( + timerId = setTimeout( () => reject(new Error('Tree-sitter initialization timed out')), 5000, ); @@ -173,12 +174,16 @@ export async function initializeShellParsers(): Promise { treeSitterInitialization = Promise.race([ loadBashLanguage(), timeoutPromise, - ]).catch((error) => { - treeSitterInitialization = null; - // Log the error but don't throw, allowing the application to fall back to safe defaults (ASK_USER) - // or regex checks where appropriate. - debugLogger.debug('Failed to initialize shell parsers:', error); - }); + ]) + .finally(() => { + if (timerId) clearTimeout(timerId); + }) + .catch((error) => { + treeSitterInitialization = null; + // Log the error but don't throw, allowing the application to fall back to safe defaults (ASK_USER) + // or regex checks where appropriate. + debugLogger.debug('Failed to initialize shell parsers:', error); + }); } await treeSitterInitialization;