refactor(ide): replace DetectedIde enum with IDE_DEFINITIONS object (#8698)

This commit is contained in:
Shreya Keshive
2025-09-18 15:23:24 -04:00
committed by GitHub
parent f2a47dec54
commit db5b49b2ca
16 changed files with 129 additions and 229 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ import { MessageType, StreamingState } from './types.js';
import { import {
type EditorType, type EditorType,
type Config, type Config,
type DetectedIde, type IdeInfo,
type IdeContext, type IdeContext,
type UserTierId, type UserTierId,
DEFAULT_GEMINI_FLASH_MODEL, DEFAULT_GEMINI_FLASH_MODEL,
@@ -717,7 +717,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
]); ]);
const [idePromptAnswered, setIdePromptAnswered] = useState(false); const [idePromptAnswered, setIdePromptAnswered] = useState(false);
const [currentIDE, setCurrentIDE] = useState<DetectedIde | null>(null); const [currentIDE, setCurrentIDE] = useState<IdeInfo | null>(null);
useEffect(() => { useEffect(() => {
const getIde = async () => { const getIde = async () => {
+3 -4
View File
@@ -4,8 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import type { DetectedIde } from '@google/gemini-cli-core'; import type { IdeInfo } from '@google/gemini-cli-core';
import { getIdeInfo } from '@google/gemini-cli-core';
import { Box, Text } from 'ink'; import { Box, Text } from 'ink';
import type { RadioSelectItem } from './components/shared/RadioButtonSelect.js'; import type { RadioSelectItem } from './components/shared/RadioButtonSelect.js';
import { RadioButtonSelect } from './components/shared/RadioButtonSelect.js'; import { RadioButtonSelect } from './components/shared/RadioButtonSelect.js';
@@ -18,7 +17,7 @@ export type IdeIntegrationNudgeResult = {
}; };
interface IdeIntegrationNudgeProps { interface IdeIntegrationNudgeProps {
ide: DetectedIde; ide: IdeInfo;
onComplete: (result: IdeIntegrationNudgeResult) => void; onComplete: (result: IdeIntegrationNudgeResult) => void;
} }
@@ -38,7 +37,7 @@ export function IdeIntegrationNudge({
{ isActive: true }, { isActive: true },
); );
const { displayName: ideName } = getIdeInfo(ide); const { displayName: ideName } = ide;
// Assume extension is already installed if the env variables are set. // Assume extension is already installed if the env variables are set.
const isExtensionPreInstalled = const isExtensionPreInstalled =
!!process.env['GEMINI_CLI_IDE_SERVER_PORT'] && !!process.env['GEMINI_CLI_IDE_SERVER_PORT'] &&
+13 -18
View File
@@ -8,7 +8,7 @@ import type { MockInstance } from 'vitest';
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
import { ideCommand } from './ideCommand.js'; import { ideCommand } from './ideCommand.js';
import { type CommandContext } from './types.js'; import { type CommandContext } from './types.js';
import { DetectedIde } from '@google/gemini-cli-core'; import { IDE_DEFINITIONS } from '@google/gemini-cli-core';
import * as core from '@google/gemini-cli-core'; import * as core from '@google/gemini-cli-core';
vi.mock('@google/gemini-cli-core', async (importOriginal) => { vi.mock('@google/gemini-cli-core', async (importOriginal) => {
@@ -36,11 +36,14 @@ describe('ideCommand', () => {
disconnect: vi.fn(), disconnect: vi.fn(),
connect: vi.fn(), connect: vi.fn(),
getCurrentIde: vi.fn(), getCurrentIde: vi.fn(),
getDetectedIdeDisplayName: vi.fn(),
getConnectionStatus: vi.fn(), getConnectionStatus: vi.fn(),
getDetectedIdeDisplayName: vi.fn(),
} as unknown as core.IdeClient; } as unknown as core.IdeClient;
vi.mocked(core.IdeClient.getInstance).mockResolvedValue(mockIdeClient); vi.mocked(core.IdeClient.getInstance).mockResolvedValue(mockIdeClient);
vi.mocked(mockIdeClient.getDetectedIdeDisplayName).mockReturnValue(
'VS Code',
);
mockContext = { mockContext = {
ui: { ui: {
@@ -66,9 +69,8 @@ describe('ideCommand', () => {
}); });
it('should return the ide command', async () => { it('should return the ide command', async () => {
vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue(DetectedIde.VSCode); vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue(
vi.mocked(mockIdeClient.getDetectedIdeDisplayName).mockReturnValue( IDE_DEFINITIONS.vscode,
'VS Code',
); );
vi.mocked(mockIdeClient.getConnectionStatus).mockReturnValue({ vi.mocked(mockIdeClient.getConnectionStatus).mockReturnValue({
status: core.IDEConnectionStatus.Disconnected, status: core.IDEConnectionStatus.Disconnected,
@@ -83,9 +85,8 @@ describe('ideCommand', () => {
}); });
it('should show disable command when connected', async () => { it('should show disable command when connected', async () => {
vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue(DetectedIde.VSCode); vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue(
vi.mocked(mockIdeClient.getDetectedIdeDisplayName).mockReturnValue( IDE_DEFINITIONS.vscode,
'VS Code',
); );
vi.mocked(mockIdeClient.getConnectionStatus).mockReturnValue({ vi.mocked(mockIdeClient.getConnectionStatus).mockReturnValue({
status: core.IDEConnectionStatus.Connected, status: core.IDEConnectionStatus.Connected,
@@ -100,10 +101,7 @@ describe('ideCommand', () => {
describe('status subcommand', () => { describe('status subcommand', () => {
beforeEach(() => { beforeEach(() => {
vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue( vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue(
DetectedIde.VSCode, IDE_DEFINITIONS.vscode,
);
vi.mocked(mockIdeClient.getDetectedIdeDisplayName).mockReturnValue(
'VS Code',
); );
}); });
@@ -177,10 +175,7 @@ describe('ideCommand', () => {
const mockInstall = vi.fn(); const mockInstall = vi.fn();
beforeEach(() => { beforeEach(() => {
vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue( vi.mocked(mockIdeClient.getCurrentIde).mockReturnValue(
DetectedIde.VSCode, IDE_DEFINITIONS.vscode,
);
vi.mocked(mockIdeClient.getDetectedIdeDisplayName).mockReturnValue(
'VS Code',
); );
vi.mocked(mockIdeClient.getConnectionStatus).mockReturnValue({ vi.mocked(mockIdeClient.getConnectionStatus).mockReturnValue({
status: core.IDEConnectionStatus.Disconnected, status: core.IDEConnectionStatus.Disconnected,
@@ -211,7 +206,7 @@ describe('ideCommand', () => {
await vi.runAllTimersAsync(); await vi.runAllTimersAsync();
await actionPromise; await actionPromise;
expect(core.getIdeInstaller).toHaveBeenCalledWith('vscode'); expect(core.getIdeInstaller).toHaveBeenCalledWith(IDE_DEFINITIONS.vscode);
expect(mockInstall).toHaveBeenCalled(); expect(mockInstall).toHaveBeenCalled();
expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
@@ -249,7 +244,7 @@ describe('ideCommand', () => {
'', '',
); );
expect(core.getIdeInstaller).toHaveBeenCalledWith('vscode'); expect(core.getIdeInstaller).toHaveBeenCalledWith(IDE_DEFINITIONS.vscode);
expect(mockInstall).toHaveBeenCalled(); expect(mockInstall).toHaveBeenCalled();
expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
+1 -1
View File
@@ -135,7 +135,7 @@ async function setIdeModeAndSyncConnection(
export const ideCommand = async (): Promise<SlashCommand> => { export const ideCommand = async (): Promise<SlashCommand> => {
const ideClient = await IdeClient.getInstance(); const ideClient = await IdeClient.getInstance();
const currentIDE = ideClient.getCurrentIde(); const currentIDE = ideClient.getCurrentIde();
if (!currentIDE || !ideClient.getDetectedIdeDisplayName()) { if (!currentIDE) {
return { return {
name: 'ide', name: 'ide',
description: 'manage IDE integration', description: 'manage IDE integration',
@@ -21,7 +21,7 @@ import type {
IdeContext, IdeContext,
ApprovalMode, ApprovalMode,
UserTierId, UserTierId,
DetectedIde, IdeInfo,
FallbackIntent, FallbackIntent,
} from '@google/gemini-cli-core'; } from '@google/gemini-cli-core';
import type { DOMElement } from 'ink'; import type { DOMElement } from 'ink';
@@ -104,7 +104,7 @@ export interface UIState {
terminalWidth: number; terminalWidth: number;
terminalHeight: number; terminalHeight: number;
mainControlsRef: React.MutableRefObject<DOMElement | null>; mainControlsRef: React.MutableRefObject<DOMElement | null>;
currentIDE: DetectedIde | null; currentIDE: IdeInfo | null;
updateInfo: UpdateObject | null; updateInfo: UpdateObject | null;
showIdeRestartPrompt: boolean; showIdeRestartPrompt: boolean;
isRestarting: boolean; isRestarting: boolean;
+1 -1
View File
@@ -23,7 +23,7 @@ export {
DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES, DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD, DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
} from './src/config/config.js'; } from './src/config/config.js';
export { detectIdeFromEnv, getIdeInfo } from './src/ide/detect-ide.js'; export { detectIdeFromEnv } from './src/ide/detect-ide.js';
export { logIdeConnection } from './src/telemetry/loggers.js'; export { logIdeConnection } from './src/telemetry/loggers.js';
export { export {
+11 -61
View File
@@ -5,7 +5,7 @@
*/ */
import { describe, it, expect, vi, afterEach } from 'vitest'; import { describe, it, expect, vi, afterEach } from 'vitest';
import { detectIde, DetectedIde, getIdeInfo } from './detect-ide.js'; import { detectIde, IDE_DEFINITIONS } from './detect-ide.js';
describe('detectIde', () => { describe('detectIde', () => {
const ideProcessInfo = { pid: 123, command: 'some/path/to/code' }; const ideProcessInfo = { pid: 123, command: 'some/path/to/code' };
@@ -23,110 +23,60 @@ describe('detectIde', () => {
it('should detect Devin', () => { it('should detect Devin', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('__COG_BASHRC_SOURCED', '1'); vi.stubEnv('__COG_BASHRC_SOURCED', '1');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Devin); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.devin);
}); });
it('should detect Replit', () => { it('should detect Replit', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('REPLIT_USER', 'testuser'); vi.stubEnv('REPLIT_USER', 'testuser');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Replit); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.replit);
}); });
it('should detect Cursor', () => { it('should detect Cursor', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('CURSOR_TRACE_ID', 'some-id'); vi.stubEnv('CURSOR_TRACE_ID', 'some-id');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Cursor); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.cursor);
}); });
it('should detect Codespaces', () => { it('should detect Codespaces', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('CODESPACES', 'true'); vi.stubEnv('CODESPACES', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Codespaces); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.codespaces);
}); });
it('should detect Cloud Shell via EDITOR_IN_CLOUD_SHELL', () => { it('should detect Cloud Shell via EDITOR_IN_CLOUD_SHELL', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('EDITOR_IN_CLOUD_SHELL', 'true'); vi.stubEnv('EDITOR_IN_CLOUD_SHELL', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.CloudShell); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.cloudshell);
}); });
it('should detect Cloud Shell via CLOUD_SHELL', () => { it('should detect Cloud Shell via CLOUD_SHELL', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('CLOUD_SHELL', 'true'); vi.stubEnv('CLOUD_SHELL', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.CloudShell); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.cloudshell);
}); });
it('should detect Trae', () => { it('should detect Trae', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('TERM_PRODUCT', 'Trae'); vi.stubEnv('TERM_PRODUCT', 'Trae');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Trae); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.trae);
}); });
it('should detect Firebase Studio via MONOSPACE_ENV', () => { it('should detect Firebase Studio via MONOSPACE_ENV', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('MONOSPACE_ENV', 'true'); vi.stubEnv('MONOSPACE_ENV', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.FirebaseStudio); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.firebasestudio);
}); });
it('should detect VSCode when no other IDE is detected and command includes "code"', () => { it('should detect VSCode when no other IDE is detected and command includes "code"', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('MONOSPACE_ENV', ''); vi.stubEnv('MONOSPACE_ENV', '');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.VSCode); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.vscode);
}); });
it('should detect VSCodeFork when no other IDE is detected and command does not include "code"', () => { it('should detect VSCodeFork when no other IDE is detected and command does not include "code"', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode'); vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('MONOSPACE_ENV', ''); vi.stubEnv('MONOSPACE_ENV', '');
expect(detectIde(ideProcessInfoNoCode)).toBe(DetectedIde.VSCodeFork); expect(detectIde(ideProcessInfoNoCode)).toBe(IDE_DEFINITIONS.vscodefork);
});
it('should prioritize other IDEs over VSCode detection', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('REPLIT_USER', 'testuser');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Replit);
});
});
describe('getIdeInfo', () => {
it('should return correct info for Devin', () => {
expect(getIdeInfo(DetectedIde.Devin)).toEqual({ displayName: 'Devin' });
});
it('should return correct info for Replit', () => {
expect(getIdeInfo(DetectedIde.Replit)).toEqual({ displayName: 'Replit' });
});
it('should return correct info for Cursor', () => {
expect(getIdeInfo(DetectedIde.Cursor)).toEqual({ displayName: 'Cursor' });
});
it('should return correct info for CloudShell', () => {
expect(getIdeInfo(DetectedIde.CloudShell)).toEqual({
displayName: 'Cloud Shell',
});
});
it('should return correct info for Codespaces', () => {
expect(getIdeInfo(DetectedIde.Codespaces)).toEqual({
displayName: 'GitHub Codespaces',
});
});
it('should return correct info for FirebaseStudio', () => {
expect(getIdeInfo(DetectedIde.FirebaseStudio)).toEqual({
displayName: 'Firebase Studio',
});
});
it('should return correct info for Trae', () => {
expect(getIdeInfo(DetectedIde.Trae)).toEqual({ displayName: 'Trae' });
});
it('should return correct info for VSCode', () => {
expect(getIdeInfo(DetectedIde.VSCode)).toEqual({ displayName: 'VS Code' });
});
it('should return correct info for VSCodeFork', () => {
expect(getIdeInfo(DetectedIde.VSCodeFork)).toEqual({ displayName: 'IDE' });
}); });
}); });
+29 -72
View File
@@ -4,113 +4,70 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
export enum DetectedIde { export const IDE_DEFINITIONS = {
Devin = 'devin', devin: { name: 'devin', displayName: 'Devin' },
Replit = 'replit', replit: { name: 'replit', displayName: 'Replit' },
Cursor = 'cursor', cursor: { name: 'cursor', displayName: 'Cursor' },
CloudShell = 'cloudshell', cloudshell: { name: 'cloudshell', displayName: 'Cloud Shell' },
Codespaces = 'codespaces', codespaces: { name: 'codespaces', displayName: 'GitHub Codespaces' },
FirebaseStudio = 'firebasestudio', firebasestudio: { name: 'firebasestudio', displayName: 'Firebase Studio' },
Trae = 'trae', trae: { name: 'trae', displayName: 'Trae' },
VSCode = 'vscode', vscode: { name: 'vscode', displayName: 'VS Code' },
VSCodeFork = 'vscodefork', vscodefork: { name: 'vscodefork', displayName: 'IDE' },
} } as const;
export type IdeName = keyof typeof IDE_DEFINITIONS;
export interface IdeInfo { export interface IdeInfo {
name: IdeName;
displayName: string; displayName: string;
} }
export function getIdeInfo(ide: DetectedIde): IdeInfo { export function detectIdeFromEnv(): IdeInfo {
switch (ide) {
case DetectedIde.Devin:
return {
displayName: 'Devin',
};
case DetectedIde.Replit:
return {
displayName: 'Replit',
};
case DetectedIde.Cursor:
return {
displayName: 'Cursor',
};
case DetectedIde.CloudShell:
return {
displayName: 'Cloud Shell',
};
case DetectedIde.Codespaces:
return {
displayName: 'GitHub Codespaces',
};
case DetectedIde.FirebaseStudio:
return {
displayName: 'Firebase Studio',
};
case DetectedIde.Trae:
return {
displayName: 'Trae',
};
case DetectedIde.VSCode:
return {
displayName: 'VS Code',
};
case DetectedIde.VSCodeFork:
return {
displayName: 'IDE',
};
default: {
// This ensures that if a new IDE is added to the enum, we get a compile-time error.
const exhaustiveCheck: never = ide;
return exhaustiveCheck;
}
}
}
export function detectIdeFromEnv(): DetectedIde {
if (process.env['__COG_BASHRC_SOURCED']) { if (process.env['__COG_BASHRC_SOURCED']) {
return DetectedIde.Devin; return IDE_DEFINITIONS.devin;
} }
if (process.env['REPLIT_USER']) { if (process.env['REPLIT_USER']) {
return DetectedIde.Replit; return IDE_DEFINITIONS.replit;
} }
if (process.env['CURSOR_TRACE_ID']) { if (process.env['CURSOR_TRACE_ID']) {
return DetectedIde.Cursor; return IDE_DEFINITIONS.cursor;
} }
if (process.env['CODESPACES']) { if (process.env['CODESPACES']) {
return DetectedIde.Codespaces; return IDE_DEFINITIONS.codespaces;
} }
if (process.env['EDITOR_IN_CLOUD_SHELL'] || process.env['CLOUD_SHELL']) { if (process.env['EDITOR_IN_CLOUD_SHELL'] || process.env['CLOUD_SHELL']) {
return DetectedIde.CloudShell; return IDE_DEFINITIONS.cloudshell;
} }
if (process.env['TERM_PRODUCT'] === 'Trae') { if (process.env['TERM_PRODUCT'] === 'Trae') {
return DetectedIde.Trae; return IDE_DEFINITIONS.trae;
} }
if (process.env['MONOSPACE_ENV']) { if (process.env['MONOSPACE_ENV']) {
return DetectedIde.FirebaseStudio; return IDE_DEFINITIONS.firebasestudio;
} }
return DetectedIde.VSCode; return IDE_DEFINITIONS.vscode;
} }
function verifyVSCode( function verifyVSCode(
ide: DetectedIde, ide: IdeInfo,
ideProcessInfo: { ideProcessInfo: {
pid: number; pid: number;
command: string; command: string;
}, },
): DetectedIde { ): IdeInfo {
if (ide !== DetectedIde.VSCode) { if (ide.name !== IDE_DEFINITIONS.vscode.name) {
return ide; return ide;
} }
if (ideProcessInfo.command.toLowerCase().includes('code')) { if (ideProcessInfo.command.toLowerCase().includes('code')) {
return DetectedIde.VSCode; return IDE_DEFINITIONS.vscode;
} }
return DetectedIde.VSCodeFork; return IDE_DEFINITIONS.vscodefork;
} }
export function detectIde(ideProcessInfo: { export function detectIde(ideProcessInfo: {
pid: number; pid: number;
command: string; command: string;
}): DetectedIde | undefined { }): IdeInfo | undefined {
// Only VSCode-based integrations are currently supported. // Only VSCode-based integrations are currently supported.
if (process.env['TERM_PROGRAM'] !== 'vscode') { if (process.env['TERM_PROGRAM'] !== 'vscode') {
return undefined; return undefined;
+2 -10
View File
@@ -20,12 +20,7 @@ import { getIdeProcessInfo } from './process-utils.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { import { detectIde, IDE_DEFINITIONS } from './detect-ide.js';
detectIde,
DetectedIde,
getIdeInfo,
type IdeInfo,
} from './detect-ide.js';
import * as os from 'node:os'; import * as os from 'node:os';
import * as path from 'node:path'; import * as path from 'node:path';
@@ -67,10 +62,7 @@ describe('IdeClient', () => {
// Mock dependencies // Mock dependencies
vi.spyOn(process, 'cwd').mockReturnValue('/test/workspace/sub-dir'); vi.spyOn(process, 'cwd').mockReturnValue('/test/workspace/sub-dir');
vi.mocked(detectIde).mockReturnValue(DetectedIde.VSCode); vi.mocked(detectIde).mockReturnValue(IDE_DEFINITIONS.vscode);
vi.mocked(getIdeInfo).mockReturnValue({
displayName: 'VS Code',
} as IdeInfo);
vi.mocked(getIdeProcessInfo).mockResolvedValue({ vi.mocked(getIdeProcessInfo).mockResolvedValue({
pid: 12345, pid: 12345,
command: 'test-ide', command: 'test-ide',
+8 -14
View File
@@ -6,7 +6,7 @@
import * as fs from 'node:fs'; import * as fs from 'node:fs';
import { isSubpath } from '../utils/paths.js'; import { isSubpath } from '../utils/paths.js';
import { detectIde, type DetectedIde, getIdeInfo } from '../ide/detect-ide.js'; import { detectIde, type IdeInfo } from '../ide/detect-ide.js';
import { ideContextStore } from './ideContext.js'; import { ideContextStore } from './ideContext.js';
import { import {
IdeContextNotificationSchema, IdeContextNotificationSchema,
@@ -85,8 +85,7 @@ export class IdeClient {
details: details:
'IDE integration is currently disabled. To enable it, run /ide enable.', 'IDE integration is currently disabled. To enable it, run /ide enable.',
}; };
private currentIde: DetectedIde | undefined; private currentIde: IdeInfo | undefined;
private currentIdeDisplayName: string | undefined;
private ideProcessInfo: { pid: number; command: string } | undefined; private ideProcessInfo: { pid: number; command: string } | undefined;
private authToken: string | undefined; private authToken: string | undefined;
private diffResponses = new Map<string, (result: DiffUpdateResult) => void>(); private diffResponses = new Map<string, (result: DiffUpdateResult) => void>();
@@ -108,11 +107,6 @@ export class IdeClient {
const client = new IdeClient(); const client = new IdeClient();
client.ideProcessInfo = await getIdeProcessInfo(); client.ideProcessInfo = await getIdeProcessInfo();
client.currentIde = detectIde(client.ideProcessInfo); client.currentIde = detectIde(client.ideProcessInfo);
if (client.currentIde) {
client.currentIdeDisplayName = getIdeInfo(
client.currentIde,
).displayName;
}
return client; return client;
})(); })();
} }
@@ -136,7 +130,7 @@ export class IdeClient {
} }
async connect(): Promise<void> { async connect(): Promise<void> {
if (!this.currentIde || !this.currentIdeDisplayName) { if (!this.currentIde) {
this.setState( this.setState(
IDEConnectionStatus.Disconnected, IDEConnectionStatus.Disconnected,
`IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: VS Code or VS Code forks`, `IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: VS Code or VS Code forks`,
@@ -157,7 +151,7 @@ export class IdeClient {
const { isValid, error } = IdeClient.validateWorkspacePath( const { isValid, error } = IdeClient.validateWorkspacePath(
workspacePath, workspacePath,
this.currentIdeDisplayName, this.currentIde.displayName,
process.cwd(), process.cwd(),
); );
@@ -203,7 +197,7 @@ export class IdeClient {
this.setState( this.setState(
IDEConnectionStatus.Disconnected, IDEConnectionStatus.Disconnected,
`Failed to connect to IDE companion extension in ${this.currentIdeDisplayName}. Please ensure the extension is running. To install the extension, run /ide install.`, `Failed to connect to IDE companion extension in ${this.currentIde.displayName}. Please ensure the extension is running. To install the extension, run /ide install.`,
true, true,
); );
} }
@@ -407,7 +401,7 @@ export class IdeClient {
this.client?.close(); this.client?.close();
} }
getCurrentIde(): DetectedIde | undefined { getCurrentIde(): IdeInfo | undefined {
return this.currentIde; return this.currentIde;
} }
@@ -416,7 +410,7 @@ export class IdeClient {
} }
getDetectedIdeDisplayName(): string | undefined { getDetectedIdeDisplayName(): string | undefined {
return this.currentIdeDisplayName; return this.currentIde?.displayName;
} }
isDiffingEnabled(): boolean { isDiffingEnabled(): boolean {
@@ -636,7 +630,7 @@ export class IdeClient {
} }
const { isValid } = IdeClient.validateWorkspacePath( const { isValid } = IdeClient.validateWorkspacePath(
content.workspacePath, content.workspacePath,
this.currentIdeDisplayName, this.currentIde?.displayName,
process.cwd(), process.cwd(),
); );
return isValid; return isValid;
+32 -21
View File
@@ -4,16 +4,11 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; import { vi } from 'vitest';
import { getIdeInstaller } from './ide-installer.js';
import * as child_process from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { DetectedIde } from './detect-ide.js';
vi.mock('node:child_process', async (importOriginal) => { vi.mock('node:child_process', async (importOriginal) => {
const actual = (await importOriginal()) as typeof child_process; const actual =
(await importOriginal()) as typeof import('node:child_process');
return { return {
...actual, ...actual,
execSync: vi.fn(), execSync: vi.fn(),
@@ -23,6 +18,14 @@ vi.mock('node:child_process', async (importOriginal) => {
vi.mock('fs'); vi.mock('fs');
vi.mock('os'); vi.mock('os');
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { getIdeInstaller } from './ide-installer.js';
import * as child_process from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { IDE_DEFINITIONS, type IdeInfo } from './detect-ide.js';
describe('ide-installer', () => { describe('ide-installer', () => {
const HOME_DIR = '/home/user'; const HOME_DIR = '/home/user';
@@ -35,23 +38,28 @@ describe('ide-installer', () => {
}); });
describe('getIdeInstaller', () => { describe('getIdeInstaller', () => {
it.each([{ ide: DetectedIde.VSCode }, { ide: DetectedIde.FirebaseStudio }])( it.each([
'returns a VsCodeInstaller for "$ide"', { ide: IDE_DEFINITIONS.vscode },
({ ide }) => { { ide: IDE_DEFINITIONS.firebasestudio },
const installer = getIdeInstaller(ide); ])('returns a VsCodeInstaller for "$ide.name"', ({ ide }) => {
const installer = getIdeInstaller(ide);
expect(installer).not.toBeNull(); expect(installer).not.toBeNull();
expect(installer?.install).toEqual(expect.any(Function)); expect(installer?.install).toEqual(expect.any(Function));
}, });
);
}); });
describe('VsCodeInstaller', () => { describe('VsCodeInstaller', () => {
function setup({ function setup({
ide = DetectedIde.VSCode, ide = IDE_DEFINITIONS.vscode,
existsResult = false, existsResult = false,
execSync = () => '', execSync = () => '',
platform = 'linux' as NodeJS.Platform, platform = 'linux' as NodeJS.Platform,
}: {
ide?: IdeInfo;
existsResult?: boolean;
execSync?: () => string;
platform?: NodeJS.Platform;
} = {}) { } = {}) {
vi.spyOn(child_process, 'execSync').mockImplementation(execSync); vi.spyOn(child_process, 'execSync').mockImplementation(execSync);
vi.spyOn(fs, 'existsSync').mockReturnValue(existsResult); vi.spyOn(fs, 'existsSync').mockReturnValue(existsResult);
@@ -117,12 +125,12 @@ describe('ide-installer', () => {
it.each([ it.each([
{ {
ide: DetectedIde.VSCode, ide: IDE_DEFINITIONS.vscode,
expectedMessage: expectedMessage:
'VS Code companion extension was installed successfully', 'VS Code companion extension was installed successfully',
}, },
{ {
ide: DetectedIde.FirebaseStudio, ide: IDE_DEFINITIONS.firebasestudio,
expectedMessage: expectedMessage:
'Firebase Studio companion extension was installed successfully', 'Firebase Studio companion extension was installed successfully',
}, },
@@ -137,9 +145,12 @@ describe('ide-installer', () => {
); );
it.each([ it.each([
{ ide: DetectedIde.VSCode, expectedErr: 'VS Code CLI not found' },
{ {
ide: DetectedIde.FirebaseStudio, ide: IDE_DEFINITIONS.vscode,
expectedErr: 'VS Code CLI not found',
},
{
ide: IDE_DEFINITIONS.firebasestudio,
expectedErr: 'Firebase Studio CLI not found', expectedErr: 'Firebase Studio CLI not found',
}, },
])( ])(
+6 -8
View File
@@ -9,7 +9,7 @@ import * as process from 'node:process';
import * as path from 'node:path'; import * as path from 'node:path';
import * as fs from 'node:fs'; import * as fs from 'node:fs';
import * as os from 'node:os'; import * as os from 'node:os';
import { DetectedIde, getIdeInfo, type IdeInfo } from './detect-ide.js'; import { IDE_DEFINITIONS, type IdeInfo } from './detect-ide.js';
import { GEMINI_CLI_COMPANION_EXTENSION_NAME } from './constants.js'; import { GEMINI_CLI_COMPANION_EXTENSION_NAME } from './constants.js';
function getVsCodeCommand(platform: NodeJS.Platform = process.platform) { function getVsCodeCommand(platform: NodeJS.Platform = process.platform) {
@@ -100,14 +100,12 @@ async function findVsCodeCommand(
class VsCodeInstaller implements IdeInstaller { class VsCodeInstaller implements IdeInstaller {
private vsCodeCommand: Promise<string | null>; private vsCodeCommand: Promise<string | null>;
private readonly ideInfo: IdeInfo;
constructor( constructor(
readonly ide: DetectedIde, readonly ideInfo: IdeInfo,
readonly platform = process.platform, readonly platform = process.platform,
) { ) {
this.vsCodeCommand = findVsCodeCommand(platform); this.vsCodeCommand = findVsCodeCommand(platform);
this.ideInfo = getIdeInfo(ide);
} }
async install(): Promise<InstallResult> { async install(): Promise<InstallResult> {
@@ -150,12 +148,12 @@ class VsCodeInstaller implements IdeInstaller {
} }
export function getIdeInstaller( export function getIdeInstaller(
ide: DetectedIde, ide: IdeInfo,
platform = process.platform, platform = process.platform,
): IdeInstaller | null { ): IdeInstaller | null {
switch (ide) { switch (ide.name) {
case DetectedIde.VSCode: case IDE_DEFINITIONS.vscode.name:
case DetectedIde.FirebaseStudio: case IDE_DEFINITIONS.firebasestudio.name:
return new VsCodeInstaller(ide, platform); return new VsCodeInstaller(ide, platform);
default: default:
return null; return null;
+1 -2
View File
@@ -64,8 +64,7 @@ export * from './services/fileSystemService.js';
export * from './ide/ide-client.js'; export * from './ide/ide-client.js';
export * from './ide/ideContext.js'; export * from './ide/ideContext.js';
export * from './ide/ide-installer.js'; export * from './ide/ide-installer.js';
export { getIdeInfo, DetectedIde } from './ide/detect-ide.js'; export { IDE_DEFINITIONS, type IdeInfo } from './ide/detect-ide.js';
export { type IdeInfo } from './ide/detect-ide.js';
export * from './ide/constants.js'; export * from './ide/constants.js';
export * from './ide/types.js'; export * from './ide/types.js';
@@ -37,7 +37,7 @@ import { UserAccountManager } from '../../utils/userAccountManager.js';
import { safeJsonStringify } from '../../utils/safeJsonStringify.js'; import { safeJsonStringify } from '../../utils/safeJsonStringify.js';
import { FixedDeque } from 'mnemonist'; import { FixedDeque } from 'mnemonist';
import { GIT_COMMIT_INFO, CLI_VERSION } from '../../generated/git-commit.js'; import { GIT_COMMIT_INFO, CLI_VERSION } from '../../generated/git-commit.js';
import { DetectedIde, detectIdeFromEnv } from '../../ide/detect-ide.js'; import { IDE_DEFINITIONS, detectIdeFromEnv } from '../../ide/detect-ide.js';
export enum EventNames { export enum EventNames {
START_SESSION = 'start_session', START_SESSION = 'start_session',
@@ -113,7 +113,7 @@ function determineSurface(): string {
} else if (process.env['GITHUB_SHA']) { } else if (process.env['GITHUB_SHA']) {
return 'GitHub'; return 'GitHub';
} else if (process.env['TERM_PROGRAM'] === 'vscode') { } else if (process.env['TERM_PROGRAM'] === 'vscode') {
return detectIdeFromEnv() || DetectedIde.VSCode; return detectIdeFromEnv().name || IDE_DEFINITIONS.vscode.name;
} else { } else {
return 'SURFACE_NOT_SET'; return 'SURFACE_NOT_SET';
} }
@@ -7,13 +7,13 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { activate } from './extension.js'; import { activate } from './extension.js';
import { DetectedIde, detectIdeFromEnv } from '@google/gemini-cli-core'; import { IDE_DEFINITIONS, detectIdeFromEnv } from '@google/gemini-cli-core';
vi.mock('@google/gemini-cli-core', async () => { vi.mock('@google/gemini-cli-core', async () => {
const actual = await vi.importActual('@google/gemini-cli-core'); const actual = await vi.importActual('@google/gemini-cli-core');
return { return {
...actual, ...actual,
detectIdeFromEnv: vi.fn(() => DetectedIde.VSCode), detectIdeFromEnv: vi.fn(() => IDE_DEFINITIONS.vscode),
}; };
}); });
@@ -198,10 +198,10 @@ describe('activate', () => {
it.each([ it.each([
{ {
ide: DetectedIde.CloudShell, ide: IDE_DEFINITIONS.cloudshell,
}, },
{ ide: DetectedIde.FirebaseStudio }, { ide: IDE_DEFINITIONS.firebasestudio },
])('does not show the notification for $ide', async ({ ide }) => { ])('does not show the notification for $ide.name', async ({ ide }) => {
vi.mocked(detectIdeFromEnv).mockReturnValue(ide); vi.mocked(detectIdeFromEnv).mockReturnValue(ide);
vi.mocked(context.globalState.get).mockReturnValue(undefined); vi.mocked(context.globalState.get).mockReturnValue(undefined);
const showInformationMessageMock = vi.mocked( const showInformationMessageMock = vi.mocked(
+11 -6
View File
@@ -9,7 +9,11 @@ import { IDEServer } from './ide-server.js';
import semver from 'semver'; import semver from 'semver';
import { DiffContentProvider, DiffManager } from './diff-manager.js'; import { DiffContentProvider, DiffManager } from './diff-manager.js';
import { createLogger } from './utils/logger.js'; import { createLogger } from './utils/logger.js';
import { detectIdeFromEnv, DetectedIde } from '@google/gemini-cli-core'; import {
detectIdeFromEnv,
IDE_DEFINITIONS,
type IdeInfo,
} from '@google/gemini-cli-core';
const CLI_IDE_COMPANION_IDENTIFIER = 'Google.gemini-cli-vscode-ide-companion'; const CLI_IDE_COMPANION_IDENTIFIER = 'Google.gemini-cli-vscode-ide-companion';
const INFO_MESSAGE_SHOWN_KEY = 'geminiCliInfoMessageShown'; const INFO_MESSAGE_SHOWN_KEY = 'geminiCliInfoMessageShown';
@@ -20,9 +24,9 @@ export const DIFF_SCHEME = 'gemini-diff';
* environments we either are pre-installed and the installation message is * environments we either are pre-installed and the installation message is
* confusing or we just want to be quiet. * confusing or we just want to be quiet.
*/ */
const HIDE_INSTALLATION_GREETING_IDES: ReadonlySet<DetectedIde> = new Set([ const HIDE_INSTALLATION_GREETING_IDES: ReadonlySet<IdeInfo['name']> = new Set([
DetectedIde.FirebaseStudio, IDE_DEFINITIONS.firebasestudio.name,
DetectedIde.CloudShell, IDE_DEFINITIONS.cloudshell.name,
]); ]);
let ideServer: IDEServer; let ideServer: IDEServer;
@@ -144,8 +148,9 @@ export async function activate(context: vscode.ExtensionContext) {
log(`Failed to start IDE server: ${message}`); log(`Failed to start IDE server: ${message}`);
} }
const infoMessageEnabled = const infoMessageEnabled = !HIDE_INSTALLATION_GREETING_IDES.has(
!HIDE_INSTALLATION_GREETING_IDES.has(detectIdeFromEnv()); detectIdeFromEnv().name,
);
if (!context.globalState.get(INFO_MESSAGE_SHOWN_KEY) && infoMessageEnabled) { if (!context.globalState.get(INFO_MESSAGE_SHOWN_KEY) && infoMessageEnabled) {
void vscode.window.showInformationMessage( void vscode.window.showInformationMessage(