diff options
| author | Shreya Keshive <[email protected]> | 2025-08-06 15:47:58 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-06 19:47:58 +0000 |
| commit | 024b8207eb75bdc0c031f6380d6759b9e342e502 (patch) | |
| tree | df6789c5ef0a53b0099bc3217f0e23f3ea2bacca /packages/vscode-ide-companion/src | |
| parent | 1fb680baccf93fee5c96167da96fd31e4d57cf6f (diff) | |
Add hint to enable IDE integration for users running in VS Code (#5610)
Diffstat (limited to 'packages/vscode-ide-companion/src')
| -rw-r--r-- | packages/vscode-ide-companion/src/extension.test.ts | 99 | ||||
| -rw-r--r-- | packages/vscode-ide-companion/src/extension.ts | 20 |
2 files changed, 119 insertions, 0 deletions
diff --git a/packages/vscode-ide-companion/src/extension.test.ts b/packages/vscode-ide-companion/src/extension.test.ts new file mode 100644 index 00000000..89d1821f --- /dev/null +++ b/packages/vscode-ide-companion/src/extension.test.ts @@ -0,0 +1,99 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import * as vscode from 'vscode'; +import { activate } from './extension.js'; + +vi.mock('vscode', () => ({ + window: { + createOutputChannel: vi.fn(() => ({ + appendLine: vi.fn(), + })), + showInformationMessage: vi.fn(), + createTerminal: vi.fn(() => ({ + show: vi.fn(), + sendText: vi.fn(), + })), + }, + workspace: { + workspaceFolders: [], + onDidCloseTextDocument: vi.fn(), + registerTextDocumentContentProvider: vi.fn(), + onDidChangeWorkspaceFolders: vi.fn(), + }, + commands: { + registerCommand: vi.fn(), + executeCommand: vi.fn(), + }, + Uri: { + joinPath: vi.fn(), + }, + ExtensionMode: { + Development: 1, + Production: 2, + }, + EventEmitter: vi.fn(() => ({ + event: vi.fn(), + fire: vi.fn(), + dispose: vi.fn(), + })), +})); + +describe('activate', () => { + let context: vscode.ExtensionContext; + + beforeEach(() => { + context = { + subscriptions: [], + environmentVariableCollection: { + replace: vi.fn(), + }, + globalState: { + get: vi.fn(), + update: vi.fn(), + }, + extensionUri: { + fsPath: '/path/to/extension', + }, + } as unknown as vscode.ExtensionContext; + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it('should show the info message on first activation', async () => { + const showInformationMessageMock = vi + .mocked(vscode.window.showInformationMessage) + .mockResolvedValue(undefined as never); + vi.mocked(context.globalState.get).mockReturnValue(undefined); + await activate(context); + expect(showInformationMessageMock).toHaveBeenCalledWith( + 'Gemini CLI Companion extension successfully installed. Please restart your terminal to enable full IDE integration.', + 'Re-launch Gemini CLI', + ); + }); + + it('should not show the info message on subsequent activations', async () => { + vi.mocked(context.globalState.get).mockReturnValue(true); + await activate(context); + expect(vscode.window.showInformationMessage).not.toHaveBeenCalled(); + }); + + it('should launch the Gemini CLI when the user clicks the button', async () => { + const showInformationMessageMock = vi + .mocked(vscode.window.showInformationMessage) + .mockResolvedValue('Re-launch Gemini CLI' as never); + vi.mocked(context.globalState.get).mockReturnValue(undefined); + await activate(context); + expect(showInformationMessageMock).toHaveBeenCalled(); + await new Promise(process.nextTick); // Wait for the promise to resolve + expect(vscode.commands.executeCommand).toHaveBeenCalledWith( + 'gemini-cli.runGeminiCLI', + ); + }); +}); diff --git a/packages/vscode-ide-companion/src/extension.ts b/packages/vscode-ide-companion/src/extension.ts index b31e15b8..08389731 100644 --- a/packages/vscode-ide-companion/src/extension.ts +++ b/packages/vscode-ide-companion/src/extension.ts @@ -9,6 +9,7 @@ import { IDEServer } from './ide-server.js'; import { DiffContentProvider, DiffManager } from './diff-manager.js'; import { createLogger } from './utils/logger.js'; +const INFO_MESSAGE_SHOWN_KEY = 'geminiCliInfoMessageShown'; const IDE_WORKSPACE_PATH_ENV_VAR = 'GEMINI_CLI_IDE_WORKSPACE_PATH'; export const DIFF_SCHEME = 'gemini-diff'; @@ -81,6 +82,25 @@ export async function activate(context: vscode.ExtensionContext) { log(`Failed to start IDE server: ${message}`); } + if (!context.globalState.get(INFO_MESSAGE_SHOWN_KEY)) { + void vscode.window + .showInformationMessage( + 'Gemini CLI Companion extension successfully installed. Please restart your terminal to enable full IDE integration.', + 'Re-launch Gemini CLI', + ) + .then( + (selection) => { + if (selection === 'Re-launch Gemini CLI') { + void vscode.commands.executeCommand('gemini-cli.runGeminiCLI'); + } + }, + (err) => { + log(`Failed to show information message: ${String(err)}`); + }, + ); + context.globalState.update(INFO_MESSAGE_SHOWN_KEY, true); + } + context.subscriptions.push( vscode.workspace.onDidChangeWorkspaceFolders(() => { updateWorkspacePath(context); |
