fix(vscode): suppress update and install messages in managed IDEs (#10431)

This commit is contained in:
Shreya Keshive
2025-10-02 14:00:51 -04:00
committed by GitHub
parent 460ec60212
commit 4a70d6f22f
3 changed files with 75 additions and 42 deletions
@@ -209,17 +209,34 @@ describe('activate', () => {
ide: IDE_DEFINITIONS.cloudshell,
},
{ ide: IDE_DEFINITIONS.firebasestudio },
])('does not show the notification for $ide.name', async ({ ide }) => {
vi.mocked(detectIdeFromEnv).mockReturnValue(ide);
vi.mocked(context.globalState.get).mockReturnValue(undefined);
const showInformationMessageMock = vi.mocked(
vscode.window.showInformationMessage,
);
])(
'does not show install or update messages for $ide.name',
async ({ ide }) => {
vi.mocked(detectIdeFromEnv).mockReturnValue(ide);
vi.mocked(context.globalState.get).mockReturnValue(undefined);
vi.spyOn(global, 'fetch').mockResolvedValue({
ok: true,
json: async () => ({
results: [
{
extensions: [
{
versions: [{ version: '1.2.0' }],
},
],
},
],
}),
} as Response);
const showInformationMessageMock = vi.mocked(
vscode.window.showInformationMessage,
);
await activate(context);
await activate(context);
expect(showInformationMessageMock).not.toHaveBeenCalled();
});
expect(showInformationMessageMock).not.toHaveBeenCalled();
},
);
it('should not show an update notification if the version is older', async () => {
vi.spyOn(global, 'fetch').mockResolvedValue({
+17 -11
View File
@@ -20,11 +20,9 @@ const INFO_MESSAGE_SHOWN_KEY = 'geminiCliInfoMessageShown';
export const DIFF_SCHEME = 'gemini-diff';
/**
* IDE environments where the installation greeting is hidden. In these
* environments we either are pre-installed and the installation message is
* confusing or we just want to be quiet.
* In these environments the companion extension is installed and managed by the IDE instead of the user.
*/
const HIDE_INSTALLATION_GREETING_IDES: ReadonlySet<IdeInfo['name']> = new Set([
const MANAGED_EXTENSION_SURFACES: ReadonlySet<IdeInfo['name']> = new Set([
IDE_DEFINITIONS.firebasestudio.name,
IDE_DEFINITIONS.cloudshell.name,
]);
@@ -37,6 +35,7 @@ let log: (message: string) => void = () => {};
async function checkForUpdates(
context: vscode.ExtensionContext,
log: (message: string) => void,
isManagedExtensionSurface: boolean,
) {
try {
const currentVersion = context.extension.packageJSON.version;
@@ -81,7 +80,11 @@ async function checkForUpdates(
// The versions are sorted by date, so the first one is the latest.
const latestVersion = extension?.versions?.[0]?.version;
if (latestVersion && semver.gt(latestVersion, currentVersion)) {
if (
!isManagedExtensionSurface &&
latestVersion &&
semver.gt(latestVersion, currentVersion)
) {
const selection = await vscode.window.showInformationMessage(
`A new version (${latestVersion}) of the Gemini CLI Companion extension is available.`,
'Update to latest version',
@@ -105,7 +108,11 @@ export async function activate(context: vscode.ExtensionContext) {
log = createLogger(context, logger);
log('Extension activated');
checkForUpdates(context, log);
const isManagedExtensionSurface = MANAGED_EXTENSION_SURFACES.has(
detectIdeFromEnv().name,
);
checkForUpdates(context, log, isManagedExtensionSurface);
const diffContentProvider = new DiffContentProvider();
const diffManager = new DiffManager(log, diffContentProvider);
@@ -148,11 +155,10 @@ export async function activate(context: vscode.ExtensionContext) {
log(`Failed to start IDE server: ${message}`);
}
const infoMessageEnabled = !HIDE_INSTALLATION_GREETING_IDES.has(
detectIdeFromEnv().name,
);
if (!context.globalState.get(INFO_MESSAGE_SHOWN_KEY) && infoMessageEnabled) {
if (
!context.globalState.get(INFO_MESSAGE_SHOWN_KEY) &&
!isManagedExtensionSurface
) {
void vscode.window.showInformationMessage(
'Gemini CLI Companion extension successfully installed.',
);