summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands/ideCommand.ts
diff options
context:
space:
mode:
authorShreya Keshive <[email protected]>2025-08-05 18:52:58 -0400
committerGitHub <[email protected]>2025-08-05 22:52:58 +0000
commit268627469b384ba3fa8dfe2e05b5186248013070 (patch)
tree27d6421c6d7cc7986d284fa8f7bf0fece9c607e3 /packages/cli/src/ui/commands/ideCommand.ts
parent6a72cd064bccb5fda4618671c2da63c4e22c1ef9 (diff)
Refactor IDE client state management, improve user-facing error messages, and add logging of connection events (#5591)
Co-authored-by: matt korwel <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/commands/ideCommand.ts')
-rw-r--r--packages/cli/src/ui/commands/ideCommand.ts90
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(),
+ );
},
};