Skip to content

Commit

Permalink
Can't use Chat integration after installation and enablement (#6508)
Browse files Browse the repository at this point in the history
Fixes #6501
  • Loading branch information
alexr00 authored Dec 4, 2024
1 parent 036a2e6 commit 884227a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,7 @@ async function init(

registerPostCommitCommandsProvider(reposManager, git);

const chatEnabled = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(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();
Expand All @@ -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<boolean>(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<GitApiImpl> {
Logger.appendLine(`Extension version: ${vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON.version}`, 'Activation');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down

0 comments on commit 884227a

Please sign in to comment.