fix(cli): allow @ file selector on slash command lines (#16370)

This commit is contained in:
Gal Zahavi
2026-01-13 14:01:30 -08:00
committed by GitHub
parent b518125c46
commit b2e866585d
4 changed files with 28 additions and 9 deletions
@@ -16,7 +16,10 @@ import {
import { act, useEffect } from 'react';
import { renderWithProviders } from '../../test-utils/render.js';
import { waitFor } from '../../test-utils/async.js';
import { useCommandCompletion } from './useCommandCompletion.js';
import {
useCommandCompletion,
CompletionMode,
} from './useCommandCompletion.js';
import type { CommandContext } from '../commands/types.js';
import type { Config } from '@google/gemini-cli-core';
import { useTextBuffer } from '../components/shared/text-buffer.js';
@@ -160,6 +163,7 @@ describe('useCommandCompletion', () => {
expect(result.current.visibleStartIndex).toBe(0);
expect(result.current.showSuggestions).toBe(false);
expect(result.current.isLoadingSuggestions).toBe(false);
expect(result.current.completionMode).toBe(CompletionMode.IDLE);
});
it('should reset state when completion mode becomes IDLE', async () => {
@@ -207,7 +211,7 @@ describe('useCommandCompletion', () => {
it('should call useAtCompletion with the correct query for an escaped space', async () => {
const text = '@src/a\\ file.txt';
renderCommandCompletionHook(text);
const { result } = renderCommandCompletionHook(text);
await waitFor(() => {
expect(useAtCompletion).toHaveBeenLastCalledWith(
@@ -216,6 +220,7 @@ describe('useCommandCompletion', () => {
pattern: 'src/a\\ file.txt',
}),
);
expect(result.current.completionMode).toBe(CompletionMode.AT);
});
});
@@ -272,6 +277,9 @@ describe('useCommandCompletion', () => {
expect(result.current.showSuggestions).toBe(
expectedShowSuggestions,
);
if (!shellModeActive) {
expect(result.current.completionMode).toBe(CompletionMode.SLASH);
}
});
},
);
@@ -55,6 +55,7 @@ export interface UseCommandCompletionReturn {
leafCommand: SlashCommand | null;
};
getCompletedText: (suggestion: Suggestion) => string | null;
completionMode: CompletionMode;
}
export function useCommandCompletion(
@@ -341,5 +342,6 @@ export function useCommandCompletion(
getCommandFromSuggestion: slashCompletionRange.getCommandFromSuggestion,
slashCompletionRange,
getCompletedText,
completionMode,
};
}