Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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