diff options
Diffstat (limited to 'packages/cli/src/ui/commands/ideCommand.ts')
| -rw-r--r-- | packages/cli/src/ui/commands/ideCommand.ts | 90 |
1 files changed, 59 insertions, 31 deletions
diff --git a/packages/cli/src/ui/commands/ideCommand.ts b/packages/cli/src/ui/commands/ideCommand.ts index c6d65264..fe9f764a 100644 --- a/packages/cli/src/ui/commands/ideCommand.ts +++ b/packages/cli/src/ui/commands/ideCommand.ts @@ -10,6 +10,7 @@ import { IDEConnectionStatus, getIdeDisplayName, getIdeInstaller, + IdeClient, } from '@google/gemini-cli-core'; import { CommandContext, @@ -19,6 +20,35 @@ import { } from './types.js'; import { SettingScope } from '../../config/settings.js'; +function getIdeStatusMessage(ideClient: IdeClient): { + messageType: 'info' | 'error'; + content: string; +} { + const connection = ideClient.getConnectionStatus(); + switch (connection.status) { + case IDEConnectionStatus.Connected: + return { + messageType: 'info', + content: `🟢 Connected to ${ideClient.getDetectedIdeDisplayName()}`, + }; + 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; @@ -54,33 +84,13 @@ export const ideCommand = (config: Config | null): SlashCommand | null => { name: 'status', description: 'check status of IDE integration', kind: CommandKind.BUILT_IN, - action: (_context: CommandContext): SlashCommandActionReturn => { - const connection = ideClient.getConnectionStatus(); - switch (connection.status) { - case IDEConnectionStatus.Connected: - return { - type: 'message', - messageType: 'info', - content: `🟢 Connected to ${ideClient.getDetectedIdeDisplayName()}`, - } as const; - case IDEConnectionStatus.Connecting: - return { - type: 'message', - messageType: 'info', - content: `🟡 Connecting...`, - } as const; - default: { - let content = `🔴 Disconnected`; - if (connection?.details) { - content += `: ${connection.details}`; - } - return { - type: 'message', - messageType: 'error', - content, - } as const; - } - } + action: (): SlashCommandActionReturn => { + const { messageType, content } = getIdeStatusMessage(ideClient); + return { + type: 'message', + messageType, + content, + } as const; }, }; @@ -110,6 +120,10 @@ export const ideCommand = (config: Config | null): SlashCommand | null => { ); const result = await installer.install(); + if (result.success) { + config.setIdeMode(true); + context.services.settings.setValue(SettingScope.User, 'ideMode', true); + } context.ui.addItem( { type: result.success ? 'info' : 'error', @@ -126,8 +140,15 @@ export const ideCommand = (config: Config | null): SlashCommand | null => { kind: CommandKind.BUILT_IN, action: async (context: CommandContext) => { context.services.settings.setValue(SettingScope.User, 'ideMode', true); - config.setIdeMode(true); - config.setIdeClientConnected(); + await config.setIdeModeAndSyncConnection(true); + const { messageType, content } = getIdeStatusMessage(ideClient); + context.ui.addItem( + { + type: messageType, + text: content, + }, + Date.now(), + ); }, }; @@ -137,8 +158,15 @@ export const ideCommand = (config: Config | null): SlashCommand | null => { kind: CommandKind.BUILT_IN, action: async (context: CommandContext) => { context.services.settings.setValue(SettingScope.User, 'ideMode', false); - config.setIdeMode(false); - config.setIdeClientDisconnected(); + await config.setIdeModeAndSyncConnection(false); + const { messageType, content } = getIdeStatusMessage(ideClient); + context.ui.addItem( + { + type: messageType, + text: content, + }, + Date.now(), + ); }, }; |
