Skip to content

Commit 884227a

Browse files
authored
Can't use Chat integration after installation and enablement (#6508)
Fixes #6501
1 parent 036a2e6 commit 884227a

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/extension.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,7 @@ async function init(
234234

235235
registerPostCommitCommandsProvider(reposManager, git);
236236

237-
const chatEnabled = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(EXPERIMENTAL_CHAT, false);
238-
if (chatEnabled) {
239-
const chatParticipantState = new ChatParticipantState();
240-
context.subscriptions.push(new ChatParticipant(context, chatParticipantState));
241-
registerTools(context, credentialStore, reposManager, chatParticipantState);
242-
}
237+
initChat(context, credentialStore, reposManager);
243238

244239
// Make sure any compare changes tabs, which come from the create flow, are closed.
245240
CompareChanges.closeTabs();
@@ -249,6 +244,29 @@ async function init(
249244
telemetry.sendTelemetryEvent('startup');
250245
}
251246

247+
function initChat(context: vscode.ExtensionContext, credentialStore: CredentialStore, reposManager: RepositoriesManager) {
248+
const createParticipant = () => {
249+
const chatParticipantState = new ChatParticipantState();
250+
context.subscriptions.push(new ChatParticipant(context, chatParticipantState));
251+
registerTools(context, credentialStore, reposManager, chatParticipantState);
252+
};
253+
254+
const chatEnabled = () => vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(EXPERIMENTAL_CHAT, false);
255+
if (chatEnabled()) {
256+
createParticipant();
257+
} else {
258+
const disposable = vscode.workspace.onDidChangeConfiguration(e => {
259+
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${EXPERIMENTAL_CHAT}`)) {
260+
if (chatEnabled()) {
261+
disposable.dispose();
262+
createParticipant();
263+
}
264+
}
265+
});
266+
context.subscriptions.push(disposable);
267+
}
268+
}
269+
252270
export async function activate(context: vscode.ExtensionContext): Promise<GitApiImpl> {
253271
Logger.appendLine(`Extension version: ${vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON.version}`, 'Activation');
254272
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

0 commit comments

Comments
 (0)