From 884227aade19fae1f40c06edf1487677f5d8d737 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Wed, 4 Dec 2024 10:45:41 +0100 Subject: [PATCH] Can't use Chat integration after installation and enablement (#6508) Fixes #6501 --- src/extension.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 2690834fb3..7fbd7551b4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -234,12 +234,7 @@ async function init( registerPostCommitCommandsProvider(reposManager, git); - const chatEnabled = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(EXPERIMENTAL_CHAT, false); - if (chatEnabled) { - const chatParticipantState = new ChatParticipantState(); - context.subscriptions.push(new ChatParticipant(context, chatParticipantState)); - registerTools(context, credentialStore, reposManager, chatParticipantState); - } + initChat(context, credentialStore, reposManager); // Make sure any compare changes tabs, which come from the create flow, are closed. CompareChanges.closeTabs(); @@ -249,6 +244,29 @@ async function init( telemetry.sendTelemetryEvent('startup'); } +function initChat(context: vscode.ExtensionContext, credentialStore: CredentialStore, reposManager: RepositoriesManager) { + const createParticipant = () => { + const chatParticipantState = new ChatParticipantState(); + context.subscriptions.push(new ChatParticipant(context, chatParticipantState)); + registerTools(context, credentialStore, reposManager, chatParticipantState); + }; + + const chatEnabled = () => vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(EXPERIMENTAL_CHAT, false); + if (chatEnabled()) { + createParticipant(); + } else { + const disposable = vscode.workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${EXPERIMENTAL_CHAT}`)) { + if (chatEnabled()) { + disposable.dispose(); + createParticipant(); + } + } + }); + context.subscriptions.push(disposable); + } +} + export async function activate(context: vscode.ExtensionContext): Promise { Logger.appendLine(`Extension version: ${vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON.version}`, 'Activation'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment