From dfa5c79a476cd6ae05aa06df06864851b00284df Mon Sep 17 00:00:00 2001 From: "MD. MOHIBUR RAHMAN" <35300157+mrpmohiburrahman@users.noreply.github.com> Date: Tue, 24 Feb 2026 05:22:51 +0600 Subject: [PATCH] refactor(cli): centralize token parsing in useCommandCompletion to optimize re-renders --- .../cli/src/ui/hooks/useCommandCompletion.tsx | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/ui/hooks/useCommandCompletion.tsx b/packages/cli/src/ui/hooks/useCommandCompletion.tsx index 573d0571fe..097a1e63b3 100644 --- a/packages/cli/src/ui/hooks/useCommandCompletion.tsx +++ b/packages/cli/src/ui/hooks/useCommandCompletion.tsx @@ -107,6 +107,9 @@ export function useCommandCompletion({ completionStart, completionEnd, shellTokenIsCommand, + shellTokens, + shellCursorIndex, + shellCommandToken, } = useMemo(() => { const currentLine = buffer.lines[cursorRow] || ''; const codePoints = toCodePoints(currentLine); @@ -248,22 +251,6 @@ export function useCommandCompletion({ setIsPerfectMatch, }); - const { shellTokens, shellCursorIndex, shellCommandToken } = useMemo(() => { - if (!shellModeActive) { - return { shellTokens: [], shellCursorIndex: -1, shellCommandToken: '' }; - } - const currentLine = buffer.lines[cursorRow] || ''; - const tokenInfo = getTokenAtCursor(currentLine, cursorCol); - if (!tokenInfo) { - return { shellTokens: [''], shellCursorIndex: 0, shellCommandToken: '' }; - } - return { - shellTokens: tokenInfo.tokens, - shellCursorIndex: tokenInfo.cursorIndex, - shellCommandToken: tokenInfo.commandToken, - }; - }, [buffer.lines, cursorRow, cursorCol, shellModeActive]); - useShellCompletion({ enabled: active && completionMode === CompletionMode.SHELL, query: query || '',