Skip to content

Commit d0605ba

Browse files
authored
Switch config class to a namespace as it doesn't store any state (#7535)
1 parent d2e04d2 commit d0605ba

File tree

4 files changed

+43
-44
lines changed

4 files changed

+43
-44
lines changed

src/common/config.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import vscode from 'vscode';
7+
import { CODING_AGENT, CODING_AGENT_AUTO_COMMIT_AND_PUSH, CODING_AGENT_ENABLED, CODING_AGENT_PROMPT_FOR_CONFIRMATION } from './settingKeys';
8+
9+
/**
10+
* Handles configuration settings for the Copilot Remote Agent
11+
*/
12+
export namespace CopilotRemoteAgentConfig {
13+
function config() {
14+
return vscode.workspace.getConfiguration(CODING_AGENT);
15+
}
16+
17+
export function getEnabled(): boolean {
18+
return config().get(CODING_AGENT_ENABLED, false);
19+
}
20+
21+
export function getPromptForConfirmation(): boolean {
22+
return config().get(CODING_AGENT_PROMPT_FOR_CONFIRMATION, true);
23+
24+
}
25+
26+
export function getAutoCommitAndPushEnabled(): boolean {
27+
return config().get(CODING_AGENT_AUTO_COMMIT_AND_PUSH, false);
28+
}
29+
30+
export async function disablePromptForConfirmation(): Promise<void> {
31+
await config().update(CODING_AGENT_PROMPT_FOR_CONFIRMATION, false, vscode.ConfigurationTarget.Global);
32+
}
33+
}

src/github/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface IAPISessionLogs {
109109
export interface ICopilotRemoteAgentCommandArgs {
110110
userPrompt: string;
111111
summary?: string;
112-
source?: string;
112+
source?: 'prompt' | (string & {});
113113
followup?: string;
114114
_version?: number; // TODO(jospicer): Remove once stabilized/engine version enforced
115115
}

src/github/copilotRemoteAgent.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as nodePath from 'path';
77
import vscode from 'vscode';
88
import { parseSessionLogs, parseToolCallDetails } from '../../common/sessionParsing';
99
import { COPILOT_ACCOUNTS } from '../common/comment';
10+
import { CopilotRemoteAgentConfig } from '../common/config';
1011
import { COPILOT_LOGINS, copilotEventToStatus, CopilotPRStatus, mostRecentCopilotEvent } from '../common/copilot';
1112
import { commands } from '../common/executeCommands';
1213
import { Disposable } from '../common/lifecycle';
@@ -20,7 +21,6 @@ import { IAPISessionLogs, ICopilotRemoteAgentCommandArgs, ICopilotRemoteAgentCom
2021
import { ChatSessionWithPR, CopilotApi, getCopilotApi, RemoteAgentJobPayload, SessionInfo, SessionSetupStep } from './copilotApi';
2122
import { CopilotPRWatcher, CopilotStateModel } from './copilotPrWatcher';
2223
import { ChatSessionContentBuilder } from './copilotRemoteAgent/chatSessionContentBuilder';
23-
import { CopilotRemoteAgentConfig } from './copilotRemoteAgent/config';
2424
import { GitOperationsManager } from './copilotRemoteAgent/gitOperationsManager';
2525
import { CredentialStore } from './credentials';
2626
import { ReposManagerState } from './folderRepositoryManager';
@@ -54,7 +54,6 @@ export class CopilotRemoteAgentManager extends Disposable {
5454
private readonly _onDidChangeChatSessions = this._register(new vscode.EventEmitter<void>());
5555
readonly onDidChangeChatSessions = this._onDidChangeChatSessions.event;
5656

57-
private readonly _config: CopilotRemoteAgentConfig;
5857
private readonly gitOperationsManager: GitOperationsManager;
5958

6059
constructor(private credentialStore: CredentialStore, public repositoriesManager: RepositoriesManager, private telemetry: ITelemetry) {
@@ -92,7 +91,6 @@ export class CopilotRemoteAgentManager extends Disposable {
9291

9392
// Set initial context
9493
this.updateAssignabilityContext();
95-
this._config = new CopilotRemoteAgentConfig();
9694
}
9795

9896
private _copilotApiPromise: Promise<CopilotApi | undefined> | undefined;
@@ -108,11 +106,11 @@ export class CopilotRemoteAgentManager extends Disposable {
108106
}
109107

110108
public get enabled(): boolean {
111-
return this._config.enabled;
109+
return CopilotRemoteAgentConfig.getEnabled();
112110
}
113111

114112
public get autoCommitAndPushEnabled(): boolean {
115-
return this._config.autoCommitAndPushEnabled;
113+
return CopilotRemoteAgentConfig.getAutoCommitAndPushEnabled();
116114
}
117115

118116
private _repoManagerInitializationPromise: Promise<void> | undefined;
@@ -162,7 +160,7 @@ export class CopilotRemoteAgentManager extends Disposable {
162160

163161
async isAvailable(): Promise<boolean> {
164162
// Check if the manager is enabled, copilot API is available, and it's assignable
165-
if (!this._config.enabled) {
163+
if (!CopilotRemoteAgentConfig.getEnabled()) {
166164
return false;
167165
}
168166

@@ -300,7 +298,7 @@ export class CopilotRemoteAgentManager extends Disposable {
300298
let autoPushAndCommit = false;
301299
const message = vscode.l10n.t('Copilot coding agent will continue your work in \'{0}\'.', repoName);
302300
const detail = vscode.l10n.t('Your chat context will be used to continue work in a new pull request.');
303-
if (source !== 'prompt' && hasChanges && this._config.autoCommitAndPushEnabled) {
301+
if (source !== 'prompt' && hasChanges && CopilotRemoteAgentConfig.getAutoCommitAndPushEnabled()) {
304302
// Pending changes modal
305303
const modalResult = await vscode.window.showInformationMessage(
306304
message,
@@ -331,7 +329,7 @@ export class CopilotRemoteAgentManager extends Disposable {
331329
if (modalResult === PUSH_CHANGES) {
332330
autoPushAndCommit = true;
333331
}
334-
} else if (this._config.promptForConfirmation) {
332+
} else if (CopilotRemoteAgentConfig.getPromptForConfirmation()) {
335333
// No pending changes modal
336334
const modalResult = await vscode.window.showInformationMessage(
337335
source !== 'prompt' ? message : vscode.l10n.t('Copilot coding agent will implement the specification outlined in this prompt file'),
@@ -348,7 +346,7 @@ export class CopilotRemoteAgentManager extends Disposable {
348346
}
349347

350348
if (modalResult === CONTINUE_AND_DO_NOT_ASK_AGAIN) {
351-
await this._config.disablePromptForConfirmation();
349+
await CopilotRemoteAgentConfig.disablePromptForConfirmation();
352350
}
353351

354352
if (modalResult === LEARN_MORE) {
@@ -442,7 +440,7 @@ export class CopilotRemoteAgentManager extends Disposable {
442440
let ref = baseRef;
443441
const hasChanges = autoPushAndCommit && (repository.state.workingTreeChanges.length > 0 || repository.state.indexChanges.length > 0);
444442
if (hasChanges) {
445-
if (!this._config.autoCommitAndPushEnabled) {
443+
if (!CopilotRemoteAgentConfig.getAutoCommitAndPushEnabled()) {
446444
return { error: vscode.l10n.t('Uncommitted changes detected. Please commit or stash your changes before starting the remote agent. Enable \'{0}\' to push your changes automatically.', CODING_AGENT_AUTO_COMMIT_AND_PUSH), state: 'error' };
447445
}
448446
try {
@@ -455,7 +453,7 @@ export class CopilotRemoteAgentManager extends Disposable {
455453
const base_ref = hasChanges ? baseRef : ref;
456454
try {
457455
if (!(await ghRepository.hasBranch(base_ref))) {
458-
if (!this._config.autoCommitAndPushEnabled) {
456+
if (!CopilotRemoteAgentConfig.getAutoCommitAndPushEnabled()) {
459457
// We won't auto-push a branch if the user has disabled the setting
460458
return { error: vscode.l10n.t('The branch \'{0}\' does not exist on the remote repository \'{1}/{2}\'. Please create the remote branch first.', base_ref, owner, repo), state: 'error' };
461459
}

src/github/copilotRemoteAgent/config.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)