Skip to content

Commit fa0bf8d

Browse files
authored
feat: add ChatGettingStartedContribution to handle extension installation events (microsoft#232191)
1 parent 964dee3 commit fa0bf8d

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatActions.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { localize, localize2 } from '../../../../../nls.js';
1818
import { IActionViewItemService } from '../../../../../platform/actions/browser/actionViewItemService.js';
1919
import { DropdownWithPrimaryActionViewItem } from '../../../../../platform/actions/browser/dropdownWithPrimaryActionViewItem.js';
2020
import { Action2, MenuId, MenuItemAction, MenuRegistry, registerAction2, SubmenuItemAction } from '../../../../../platform/actions/common/actions.js';
21-
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
2221
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
2322
import { IsLinuxContext, IsWindowsContext } from '../../../../../platform/contextkey/common/contextkeys.js';
2423
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
@@ -538,7 +537,6 @@ abstract class BaseInstallChatAction extends Action2 {
538537

539538
override async run(accessor: ServicesAccessor): Promise<void> {
540539
const extensionsWorkbenchService = accessor.get(IExtensionsWorkbenchService);
541-
const commandService = accessor.get(ICommandService);
542540
const productService = accessor.get(IProductService);
543541
const telemetryService = accessor.get(ITelemetryService);
544542

@@ -572,10 +570,6 @@ abstract class BaseInstallChatAction extends Action2 {
572570
installResult,
573571
hasJustification: !!justification
574572
});
575-
576-
if (installResult === 'installed') {
577-
await commandService.executeCommand(CHAT_OPEN_ACTION_ID);
578-
}
579573
}
580574
}
581575

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { IWorkbenchContribution } from '../../../../common/contributions.js';
7+
import { Disposable } from '../../../../../base/common/lifecycle.js';
8+
import { IProductService } from '../../../../../platform/product/common/productService.js';
9+
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
10+
import { IExtensionService } from '../../../../services/extensions/common/extensions.js';
11+
import { ExtensionIdentifier } from '../../../../../platform/extensions/common/extensions.js';
12+
import { CHAT_OPEN_ACTION_ID } from './chatActions.js';
13+
14+
15+
export class ChatGettingStartedContribution extends Disposable implements IWorkbenchContribution {
16+
static readonly ID = 'workbench.contrib.chatGettingStarted';
17+
private recentlyInstalled: boolean = false;
18+
19+
constructor(
20+
@IProductService private readonly productService: IProductService,
21+
@IExtensionService private readonly extensionService: IExtensionService,
22+
@ICommandService private readonly commandService: ICommandService,
23+
) {
24+
super();
25+
26+
if (!this.productService.gitHubEntitlement) {
27+
return;
28+
}
29+
30+
this.registerListeners();
31+
}
32+
33+
private registerListeners() {
34+
35+
this._register(this.extensionService.onDidChangeExtensions((result) => {
36+
for (const ext of result.added) {
37+
if (ExtensionIdentifier.equals(this.productService.gitHubEntitlement!.extensionId, ext.identifier)) {
38+
this.recentlyInstalled = true;
39+
return;
40+
}
41+
}
42+
}));
43+
44+
this.extensionService.onDidChangeExtensionsStatus(async (event) => {
45+
for (const ext of event) {
46+
if (ExtensionIdentifier.equals(this.productService.gitHubEntitlement!.extensionId, ext.value)) {
47+
const extensionStatus = this.extensionService.getExtensionsStatus();
48+
if (extensionStatus[ext.value].activationTimes && this.recentlyInstalled) {
49+
await this.commandService.executeCommand(CHAT_OPEN_ACTION_ID);
50+
this.recentlyInstalled = false;
51+
return;
52+
}
53+
}
54+
}
55+
});
56+
}
57+
}

src/vs/workbench/contrib/chat/browser/chat.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import { ChatImplicitContextContribution } from './contrib/chatImplicitContext.j
7575
import { LanguageModelToolsService } from './languageModelToolsService.js';
7676
import { ChatViewsWelcomeHandler } from './viewsWelcome/chatViewsWelcomeContributions.js';
7777
import { ILanguageModelIgnoredFilesService, LanguageModelIgnoredFilesService } from '../common/ignoredFiles.js';
78-
78+
import { ChatGettingStartedContribution } from './actions/chatGettingStarted.js';
7979

8080
// Register configuration
8181
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
@@ -297,7 +297,7 @@ registerWorkbenchContribution2(ChatCommandCenterRendering.ID, ChatCommandCenterR
297297
registerWorkbenchContribution2(ChatImplicitContextContribution.ID, ChatImplicitContextContribution, WorkbenchPhase.Eventually);
298298
registerWorkbenchContribution2(ChatEditorSaving.ID, ChatEditorSaving, WorkbenchPhase.AfterRestored);
299299
registerWorkbenchContribution2(ChatViewsWelcomeHandler.ID, ChatViewsWelcomeHandler, WorkbenchPhase.BlockStartup);
300-
300+
registerWorkbenchContribution2(ChatGettingStartedContribution.ID, ChatGettingStartedContribution, WorkbenchPhase.Eventually);
301301

302302
registerChatActions();
303303
registerChatCopyActions();

0 commit comments

Comments
 (0)