summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands/ideCommand.ts
diff options
context:
space:
mode:
authorchristine betts <[email protected]>2025-07-30 22:36:24 +0000
committerGitHub <[email protected]>2025-07-30 22:36:24 +0000
commit325bb8913776c60b763ee5f66375a4ca90d22ce0 (patch)
treeeb2aaf9fa1f826e9cfeff3e1507457aeb61d8fdf /packages/cli/src/ui/commands/ideCommand.ts
parentac1bb5ee4275e508dfc2256bbd5ca012e4a4f469 (diff)
Add toggleable IDE mode setting (#5146)
Diffstat (limited to 'packages/cli/src/ui/commands/ideCommand.ts')
-rw-r--r--packages/cli/src/ui/commands/ideCommand.ts183
1 files changed, 111 insertions, 72 deletions
diff --git a/packages/cli/src/ui/commands/ideCommand.ts b/packages/cli/src/ui/commands/ideCommand.ts
index 26b0f57d..1da7d6b0 100644
--- a/packages/cli/src/ui/commands/ideCommand.ts
+++ b/packages/cli/src/ui/commands/ideCommand.ts
@@ -6,9 +6,9 @@
import {
Config,
+ IDEConnectionStatus,
getIdeDisplayName,
getIdeInstaller,
- IDEConnectionStatus,
} from '@google/gemini-cli-core';
import {
CommandContext,
@@ -16,91 +16,130 @@ import {
SlashCommandActionReturn,
CommandKind,
} from './types.js';
+import { SettingScope } from '../../config/settings.js';
export const ideCommand = (config: Config | null): SlashCommand | null => {
- if (!config?.getIdeMode()) {
+ if (!config?.getIdeModeFeature()) {
return null;
}
const currentIDE = config.getIdeClient().getCurrentIde();
if (!currentIDE) {
- throw new Error(
- 'IDE slash command should not be available if not running in an IDE',
- );
+ return null;
}
- return {
+ const ideSlashCommand: SlashCommand = {
name: 'ide',
description: 'manage IDE integration',
kind: CommandKind.BUILT_IN,
- subCommands: [
- {
- name: 'status',
- description: 'check status of IDE integration',
- kind: CommandKind.BUILT_IN,
- action: (_context: CommandContext): SlashCommandActionReturn => {
- const connection = config.getIdeClient().getConnectionStatus();
- switch (connection?.status) {
- case IDEConnectionStatus.Connected:
- return {
- type: 'message',
- messageType: 'info',
- content: `🟢 Connected`,
- } 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;
- }
- }
- },
- },
- {
- name: 'install',
- description: `install required IDE companion ${getIdeDisplayName(currentIDE)} extension `,
- kind: CommandKind.BUILT_IN,
- action: async (context) => {
- const installer = getIdeInstaller(currentIDE);
- if (!installer) {
- context.ui.addItem(
- {
- type: 'error',
- text: 'No installer available for your configured IDE.',
- },
- Date.now(),
- );
- return;
+ subCommands: [],
+ };
+
+ const statusCommand: SlashCommand = {
+ name: 'status',
+ description: 'check status of IDE integration',
+ kind: CommandKind.BUILT_IN,
+ action: (_context: CommandContext): SlashCommandActionReturn => {
+ const connection = config.getIdeClient().getConnectionStatus();
+ switch (connection?.status) {
+ case IDEConnectionStatus.Connected:
+ return {
+ type: 'message',
+ messageType: 'info',
+ content: `🟢 Connected`,
+ } 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;
+ }
+ }
+ },
+ };
- context.ui.addItem(
- {
- type: 'info',
- text: `Installing IDE companion extension...`,
- },
- Date.now(),
- );
+ const installCommand: SlashCommand = {
+ name: 'install',
+ description: `install required IDE companion ${getIdeDisplayName(currentIDE)} extension `,
+ kind: CommandKind.BUILT_IN,
+ action: async (context) => {
+ const installer = getIdeInstaller(currentIDE);
+ if (!installer) {
+ context.ui.addItem(
+ {
+ type: 'error',
+ text: 'No installer available for your configured IDE.',
+ },
+ Date.now(),
+ );
+ return;
+ }
- const result = await installer.install();
- context.ui.addItem(
- {
- type: result.success ? 'info' : 'error',
- text: result.message,
- },
- Date.now(),
- );
+ context.ui.addItem(
+ {
+ type: 'info',
+ text: `Installing IDE companion extension...`,
},
- },
- ],
+ Date.now(),
+ );
+
+ const result = await installer.install();
+ context.ui.addItem(
+ {
+ type: result.success ? 'info' : 'error',
+ text: result.message,
+ },
+ Date.now(),
+ );
+ },
+ };
+
+ const enableCommand: SlashCommand = {
+ name: 'enable',
+ description: 'enable IDE integration',
+ kind: CommandKind.BUILT_IN,
+ action: async (context: CommandContext) => {
+ context.services.settings.setValue(SettingScope.User, 'ideMode', true);
+ config.setIdeMode(true);
+ config.setIdeClientConnected();
+ },
+ };
+
+ const disableCommand: SlashCommand = {
+ name: 'disable',
+ description: 'disable IDE integration',
+ kind: CommandKind.BUILT_IN,
+ action: async (context: CommandContext) => {
+ context.services.settings.setValue(SettingScope.User, 'ideMode', false);
+ config.setIdeMode(false);
+ config.setIdeClientDisconnected();
+ },
};
+
+ const ideModeEnabled = config.getIdeMode();
+ if (ideModeEnabled) {
+ ideSlashCommand.subCommands = [
+ disableCommand,
+ statusCommand,
+ installCommand,
+ ];
+ } else {
+ ideSlashCommand.subCommands = [
+ enableCommand,
+ statusCommand,
+ installCommand,
+ ];
+ }
+
+ return ideSlashCommand;
};