diff options
Diffstat (limited to 'packages/cli/src/ui/commands/ideCommand.ts')
| -rw-r--r-- | packages/cli/src/ui/commands/ideCommand.ts | 75 |
1 files changed, 71 insertions, 4 deletions
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, |
