Improve user-facing error messages for IDE mode (#5522)

This commit is contained in:
Shreya Keshive
2025-08-04 17:06:17 -04:00
committed by GitHub
parent fb6d9cbd36
commit 0895e29c1b
5 changed files with 43 additions and 54 deletions

View File

@@ -65,6 +65,7 @@ describe('ideCommand', () => {
vi.mocked(mockConfig.getIdeMode).mockReturnValue(true);
vi.mocked(mockConfig.getIdeClient).mockReturnValue({
getCurrentIde: () => DetectedIde.VSCode,
getDetectedIdeDisplayName: () => 'VS Code',
} as ReturnType<Config['getIdeClient']>);
const command = ideCommand(mockConfig);
expect(command).not.toBeNull();
@@ -82,6 +83,7 @@ describe('ideCommand', () => {
vi.mocked(mockConfig.getIdeClient).mockReturnValue({
getConnectionStatus: mockGetConnectionStatus,
getCurrentIde: () => DetectedIde.VSCode,
getDetectedIdeDisplayName: () => 'VS Code',
} as unknown as ReturnType<Config['getIdeClient']>);
});
@@ -96,7 +98,7 @@ describe('ideCommand', () => {
expect(result).toEqual({
type: 'message',
messageType: 'info',
content: '🟢 Connected',
content: '🟢 Connected to VS Code',
});
});
@@ -155,6 +157,7 @@ describe('ideCommand', () => {
vi.mocked(mockConfig.getIdeClient).mockReturnValue({
getCurrentIde: () => DetectedIde.VSCode,
getConnectionStatus: vi.fn(),
getDetectedIdeDisplayName: () => 'VS Code',
} as unknown as ReturnType<Config['getIdeClient']>);
vi.mocked(core.getIdeInstaller).mockReturnValue({
install: mockInstall,
@@ -180,7 +183,7 @@ describe('ideCommand', () => {
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: 'info',
text: `Installing IDE companion extension...`,
text: `Installing IDE companion...`,
}),
expect.any(Number),
);
@@ -210,7 +213,7 @@ describe('ideCommand', () => {
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: 'info',
text: `Installing IDE companion extension...`,
text: `Installing IDE companion...`,
}),
expect.any(Number),
);

View File

@@ -6,6 +6,7 @@
import {
Config,
DetectedIde,
IDEConnectionStatus,
getIdeDisplayName,
getIdeInstaller,
@@ -19,12 +20,27 @@ import {
import { SettingScope } from '../../config/settings.js';
export const ideCommand = (config: Config | null): SlashCommand | null => {
if (!config?.getIdeModeFeature()) {
if (!config || !config.getIdeModeFeature()) {
return null;
}
const currentIDE = config.getIdeClient().getCurrentIde();
if (!currentIDE) {
return null;
const ideClient = config.getIdeClient();
const currentIDE = ideClient.getCurrentIde();
if (!currentIDE || !ideClient.getDetectedIdeDisplayName()) {
return {
name: 'ide',
description: 'manage IDE integration',
kind: CommandKind.BUILT_IN,
action: (): SlashCommandActionReturn =>
({
type: 'message',
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))
.join(', ')}`,
}) as const,
};
}
const ideSlashCommand: SlashCommand = {
@@ -39,13 +55,13 @@ export const ideCommand = (config: Config | null): SlashCommand | null => {
description: 'check status of IDE integration',
kind: CommandKind.BUILT_IN,
action: (_context: CommandContext): SlashCommandActionReturn => {
const connection = config.getIdeClient().getConnectionStatus();
switch (connection?.status) {
const connection = ideClient.getConnectionStatus();
switch (connection.status) {
case IDEConnectionStatus.Connected:
return {
type: 'message',
messageType: 'info',
content: `🟢 Connected`,
content: `🟢 Connected to ${ideClient.getDetectedIdeDisplayName()}`,
} as const;
case IDEConnectionStatus.Connecting:
return {
@@ -70,7 +86,7 @@ export const ideCommand = (config: Config | null): SlashCommand | null => {
const installCommand: SlashCommand = {
name: 'install',
description: `install required IDE companion ${getIdeDisplayName(currentIDE)} extension `,
description: `install required IDE companion for ${ideClient.getDetectedIdeDisplayName()}`,
kind: CommandKind.BUILT_IN,
action: async (context) => {
const installer = getIdeInstaller(currentIDE);
@@ -78,7 +94,7 @@ export const ideCommand = (config: Config | null): SlashCommand | null => {
context.ui.addItem(
{
type: 'error',
text: 'No installer available for your configured IDE.',
text: `No installer is available for ${ideClient.getDetectedIdeDisplayName()}. Please install the IDE companion manually from its marketplace.`,
},
Date.now(),
);
@@ -88,7 +104,7 @@ export const ideCommand = (config: Config | null): SlashCommand | null => {
context.ui.addItem(
{
type: 'info',
text: `Installing IDE companion extension...`,
text: `Installing IDE companion...`,
},
Date.now(),
);