Skip to content

Commit 6287936

Browse files
authored
Better condition for chat welcome view (microsoft#235443)
* Better condition for chat welcome view * Undupe
1 parent 14b81ef commit 6287936

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ const ASK_FOR_PUBLIC_CODE_MATCHES = false; // TODO@bpasero revisit this
9494
const TRIGGER_SETUP_COMMAND_ID = 'workbench.action.chat.triggerSetup';
9595
const TRIGGER_SETUP_COMMAND_LABEL = localize2('triggerChatSetup', "Use AI Features with Copilot for Free...");
9696

97+
export const SetupWelcomeViewKeys = new Set([ChatContextKeys.Setup.triggered.key, ChatContextKeys.Setup.installed.key, ChatContextKeys.Setup.signedOut.key, ChatContextKeys.Setup.canSignUp.key]);
98+
export const SetupWelcomeViewCondition = ContextKeyExpr.and(
99+
ContextKeyExpr.has('config.chat.experimental.offerSetup'),
100+
ContextKeyExpr.or(
101+
ContextKeyExpr.and(
102+
ChatContextKeys.Setup.triggered,
103+
ChatContextKeys.Setup.installed.negate()
104+
),
105+
ContextKeyExpr.and(
106+
ChatContextKeys.Setup.canSignUp,
107+
ChatContextKeys.Setup.installed
108+
),
109+
ContextKeyExpr.and(
110+
ChatContextKeys.Setup.signedOut,
111+
ChatContextKeys.Setup.installed
112+
)
113+
)
114+
)!;
115+
97116
export class ChatSetupContribution extends Disposable implements IWorkbenchContribution {
98117

99118
static readonly ID = 'workbench.chat.setup';
@@ -119,23 +138,7 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr
119138
private registerChatWelcome(): void {
120139
Registry.as<IChatViewsWelcomeContributionRegistry>(ChatViewsWelcomeExtensions.ChatViewsWelcomeRegistry).register({
121140
title: localize('welcomeChat', "Welcome to Copilot"),
122-
when: ContextKeyExpr.and(
123-
ContextKeyExpr.has('config.chat.experimental.offerSetup'),
124-
ContextKeyExpr.or(
125-
ContextKeyExpr.and(
126-
ChatContextKeys.Setup.triggered,
127-
ChatContextKeys.Setup.installed.negate()
128-
),
129-
ContextKeyExpr.and(
130-
ChatContextKeys.Setup.canSignUp,
131-
ChatContextKeys.Setup.installed
132-
),
133-
ContextKeyExpr.and(
134-
ChatContextKeys.Setup.signedOut,
135-
ChatContextKeys.Setup.installed
136-
)
137-
)
138-
)!,
141+
when: SetupWelcomeViewCondition,
139142
icon: Codicon.copilotLarge,
140143
content: disposables => disposables.add(this.instantiationService.createInstance(ChatSetupWelcomeContent, this.controller.value, this.context)).element,
141144
});

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import { SIDE_BAR_FOREGROUND } from '../../../common/theme.js';
2727
import { IViewDescriptorService } from '../../../common/views.js';
2828
import { IChatViewTitleActionContext } from '../common/chatActions.js';
2929
import { ChatAgentLocation, IChatAgentService } from '../common/chatAgents.js';
30-
import { ChatContextKeys } from '../common/chatContextKeys.js';
3130
import { ChatModelInitState, IChatModel } from '../common/chatModel.js';
3231
import { CHAT_PROVIDER_ID } from '../common/chatParticipantContribTypes.js';
3332
import { IChatService } from '../common/chatService.js';
33+
import { SetupWelcomeViewCondition, SetupWelcomeViewKeys } from './chatSetup.js';
3434
import { ChatWidget, IChatViewState } from './chatWidget.js';
3535
import { ChatViewWelcomeController, IViewWelcomeDelegate } from './viewsWelcome/chatViewWelcomeController.js';
3636

@@ -103,9 +103,8 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate {
103103
this._onDidChangeViewWelcomeState.fire();
104104
}));
105105

106-
const keysToWatch = new Set(ChatContextKeys.Setup.signedOut.key);
107106
this._register(this.contextKeyService.onDidChangeContext(e => {
108-
if (e.affectsSome(keysToWatch)) {
107+
if (e.affectsSome(SetupWelcomeViewKeys)) {
109108
this._onDidChangeViewWelcomeState.fire();
110109
}
111110
}));
@@ -140,10 +139,10 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate {
140139
}
141140

142141
override shouldShowWelcome(): boolean {
143-
const signedOut = this.contextKeyService.getContextKeyValue<boolean>(ChatContextKeys.Setup.signedOut.key);
142+
const showSetup = this.contextKeyService.contextMatchesRules(SetupWelcomeViewCondition);
144143
const noPersistedSessions = !this.chatService.hasSessions();
145-
const shouldShow = this.didUnregisterProvider || !this._widget?.viewModel && noPersistedSessions || this.defaultParticipantRegistrationFailed || signedOut;
146-
this.logService.trace(`ChatViewPane#shouldShowWelcome(${this.chatOptions.location}) = ${shouldShow}: didUnregister=${this.didUnregisterProvider} || noViewModel:${!this._widget?.viewModel} && noPersistedSessions=${noPersistedSessions} || defaultParticipantRegistrationFailed=${this.defaultParticipantRegistrationFailed} || signedOut=${signedOut}`);
144+
const shouldShow = this.didUnregisterProvider || !this._widget?.viewModel && noPersistedSessions || this.defaultParticipantRegistrationFailed || showSetup;
145+
this.logService.trace(`ChatViewPane#shouldShowWelcome(${this.chatOptions.location}) = ${shouldShow}: didUnregister=${this.didUnregisterProvider} || noViewModel:${!this._widget?.viewModel} && noPersistedSessions=${noPersistedSessions} || defaultParticipantRegistrationFailed=${this.defaultParticipantRegistrationFailed} || showSetup=${showSetup}`);
147146
return !!shouldShow;
148147
}
149148

0 commit comments

Comments
 (0)