refactor(cli): centralize token parsing in useCommandCompletion to optimize re-renders

This commit is contained in:
MD. MOHIBUR RAHMAN
2026-02-24 05:22:51 +06:00
parent d6770d2ae9
commit dfa5c79a47
@@ -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 || '',