mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-19 00:02:51 -07:00
refactor(cli): centralize token parsing in useCommandCompletion to optimize re-renders
This commit is contained in:
@@ -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 || '',
|
||||
|
||||
Reference in New Issue
Block a user