diff options
Diffstat (limited to 'packages/cli/src/ui/commands')
| -rw-r--r-- | packages/cli/src/ui/commands/ideCommand.test.ts | 28 | ||||
| -rw-r--r-- | packages/cli/src/ui/commands/ideCommand.ts | 75 |
2 files changed, 87 insertions, 16 deletions
diff --git a/packages/cli/src/ui/commands/ideCommand.test.ts b/packages/cli/src/ui/commands/ideCommand.test.ts index 9898b1e8..10a97e2a 100644 --- a/packages/cli/src/ui/commands/ideCommand.test.ts +++ b/packages/cli/src/ui/commands/ideCommand.test.ts @@ -93,13 +93,14 @@ describe('ideCommand', () => { } as unknown as ReturnType<Config['getIdeClient']>); }); - it('should show connected status', () => { + it('should show connected status', async () => { mockGetConnectionStatus.mockReturnValue({ status: core.IDEConnectionStatus.Connected, }); const command = ideCommand(mockConfig); - const result = command!.subCommands!.find((c) => c.name === 'status')! - .action!(mockContext, ''); + const result = await command!.subCommands!.find( + (c) => c.name === 'status', + )!.action!(mockContext, ''); expect(mockGetConnectionStatus).toHaveBeenCalled(); expect(result).toEqual({ type: 'message', @@ -108,13 +109,14 @@ describe('ideCommand', () => { }); }); - it('should show connecting status', () => { + it('should show connecting status', async () => { mockGetConnectionStatus.mockReturnValue({ status: core.IDEConnectionStatus.Connecting, }); const command = ideCommand(mockConfig); - const result = command!.subCommands!.find((c) => c.name === 'status')! - .action!(mockContext, ''); + const result = await command!.subCommands!.find( + (c) => c.name === 'status', + )!.action!(mockContext, ''); expect(mockGetConnectionStatus).toHaveBeenCalled(); expect(result).toEqual({ type: 'message', @@ -122,13 +124,14 @@ describe('ideCommand', () => { content: `🟡 Connecting...`, }); }); - it('should show disconnected status', () => { + it('should show disconnected status', async () => { mockGetConnectionStatus.mockReturnValue({ status: core.IDEConnectionStatus.Disconnected, }); const command = ideCommand(mockConfig); - const result = command!.subCommands!.find((c) => c.name === 'status')! - .action!(mockContext, ''); + const result = await command!.subCommands!.find( + (c) => c.name === 'status', + )!.action!(mockContext, ''); expect(mockGetConnectionStatus).toHaveBeenCalled(); expect(result).toEqual({ type: 'message', @@ -137,15 +140,16 @@ describe('ideCommand', () => { }); }); - it('should show disconnected status with details', () => { + it('should show disconnected status with details', async () => { const details = 'Something went wrong'; mockGetConnectionStatus.mockReturnValue({ status: core.IDEConnectionStatus.Disconnected, details, }); const command = ideCommand(mockConfig); - const result = command!.subCommands!.find((c) => c.name === 'status')! - .action!(mockContext, ''); + const result = await command!.subCommands!.find( + (c) => c.name === 'status', + )!.action!(mockContext, ''); expect(mockGetConnectionStatus).toHaveBeenCalled(); expect(result).toEqual({ type: 'message', diff --git a/packages/cli/src/ui/commands/ideCommand.ts b/packages/cli/src/ui/commands/ideCommand.ts index fe9f764a..29e264d4 100644 --- a/packages/cli/src/ui/commands/ideCommand.ts +++ b/packages/cli/src/ui/commands/ideCommand.ts @@ -11,7 +11,10 @@ import { getIdeDisplayName, getIdeInstaller, IdeClient, + type File, + ideContext, } from '@google/gemini-cli-core'; +import path from 'node:path'; import { CommandContext, SlashCommand, @@ -49,6 +52,70 @@ function getIdeStatusMessage(ideClient: IdeClient): { } } +function formatFileList(openFiles: File[]): string { + const basenameCounts = new Map<string, number>(); + for (const file of openFiles) { + const basename = path.basename(file.path); + basenameCounts.set(basename, (basenameCounts.get(basename) || 0) + 1); + } + + const fileList = openFiles + .map((file: File) => { + const basename = path.basename(file.path); + const isDuplicate = (basenameCounts.get(basename) || 0) > 1; + const parentDir = path.basename(path.dirname(file.path)); + const displayName = isDuplicate + ? `${basename} (/${parentDir})` + : basename; + + return ` - ${displayName}${file.isActive ? ' (active)' : ''}`; + }) + .join('\n'); + + return `\n\nOpen files:\n${fileList}`; +} + +async function getIdeStatusMessageWithFiles(ideClient: IdeClient): Promise<{ + messageType: 'info' | 'error'; + content: string; +}> { + const connection = ideClient.getConnectionStatus(); + switch (connection.status) { + case IDEConnectionStatus.Connected: { + let content = `🟢 Connected to ${ideClient.getDetectedIdeDisplayName()}`; + try { + const context = await ideContext.getIdeContext(); + const openFiles = context?.workspaceState?.openFiles; + + if (openFiles && openFiles.length > 0) { + content += formatFileList(openFiles); + } + } catch (_e) { + // Ignore + } + return { + messageType: 'info', + content, + }; + } + case IDEConnectionStatus.Connecting: + return { + messageType: 'info', + content: `🟡 Connecting...`, + }; + default: { + let content = `🔴 Disconnected`; + if (connection?.details) { + content += `: ${connection.details}`; + } + return { + messageType: 'error', + content, + }; + } + } +} + export const ideCommand = (config: Config | null): SlashCommand | null => { if (!config || !config.getIdeModeFeature()) { return null; @@ -66,8 +133,7 @@ export const ideCommand = (config: Config | null): SlashCommand | null => { messageType: 'error', content: `IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: ${Object.values( DetectedIde, - ) - .map((ide) => getIdeDisplayName(ide)) + ).map((ide) => getIdeDisplayName(ide))} .join(', ')}`, }) as const, }; @@ -84,8 +150,9 @@ export const ideCommand = (config: Config | null): SlashCommand | null => { name: 'status', description: 'check status of IDE integration', kind: CommandKind.BUILT_IN, - action: (): SlashCommandActionReturn => { - const { messageType, content } = getIdeStatusMessage(ideClient); + action: async (): Promise<SlashCommandActionReturn> => { + const { messageType, content } = + await getIdeStatusMessageWithFiles(ideClient); return { type: 'message', messageType, |
