Skip to content

Commit 8f9566b

Browse files
authored
feat: preserve last selection isolation option (#4345)
1 parent 824e6c7 commit 8f9566b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as vscode from 'vscode';
99
import { ChatExtendedRequestHandler, ChatSessionProviderOptionItem, Uri } from 'vscode';
1010
import { IRunCommandExecutionService } from '../../../platform/commands/common/runCommandExecutionService';
1111
import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';
12+
import { IVSCodeExtensionContext } from '../../../platform/extContext/common/extensionContext';
1213
import { INativeEnvService } from '../../../platform/env/common/envService';
1314
import { IFileSystemService } from '../../../platform/filesystem/common/fileSystemService';
1415
import { IGitExtensionService } from '../../../platform/git/common/gitExtensionService';
@@ -52,6 +53,7 @@ const AGENTS_OPTION_ID = 'agent';
5253
const REPOSITORY_OPTION_ID = 'repository';
5354
const BRANCH_OPTION_ID = 'branch';
5455
const ISOLATION_OPTION_ID = 'isolation';
56+
const LAST_USED_ISOLATION_OPTION_KEY = 'github.copilot.cli.lastUsedIsolationOption';
5557
const OPEN_REPOSITORY_COMMAND_ID = 'github.copilot.cli.sessions.openRepository';
5658
const OPEN_IN_COPILOT_CLI_COMMAND_ID = 'github.copilot.cli.openInCopilotCLI';
5759
const MAX_MRU_ENTRIES = 10;
@@ -363,6 +365,7 @@ export class CopilotCLIChatSessionContentProvider extends Disposable implements
363365
@IFolderRepositoryManager private readonly folderRepositoryManager: IFolderRepositoryManager,
364366
@IConfigurationService private readonly configurationService: IConfigurationService,
365367
@ICustomSessionTitleService private readonly customSessionTitleService: ICustomSessionTitleService,
368+
@IVSCodeExtensionContext private readonly context: IVSCodeExtensionContext,
366369
) {
367370
super();
368371

@@ -449,7 +452,8 @@ export class CopilotCLIChatSessionContentProvider extends Disposable implements
449452
}
450453
if (repoInfo.repository && isIsolationOptionFeatureEnabled(this.configurationService)) {
451454
if (!_sessionIsolation.has(copilotcliSessionId)) {
452-
_sessionIsolation.set(copilotcliSessionId, 'workspace');
455+
const lastUsed = this.context.globalState.get<string>(LAST_USED_ISOLATION_OPTION_KEY, 'workspace');
456+
_sessionIsolation.set(copilotcliSessionId, lastUsed);
453457
}
454458
const isolationMode = _sessionIsolation.get(copilotcliSessionId)!;
455459
options[ISOLATION_OPTION_ID] = {
@@ -827,6 +831,9 @@ export class CopilotCLIChatSessionContentProvider extends Disposable implements
827831
continue;
828832
}
829833
_sessionIsolation.set(sessionId, update.value);
834+
if (typeof update.value === 'string') {
835+
void this.context.globalState.update(LAST_USED_ISOLATION_OPTION_KEY, update.value);
836+
}
830837
triggerProviderOptionsChange = true;
831838

832839
// When switching to worktree, push a default branch selection to the session

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
550550
git,
551551
folderRepositoryManager,
552552
configurationService,
553-
customSessionTitleService
553+
customSessionTitleService,
554+
new MockExtensionContext() as unknown as IVSCodeExtensionContext
554555
);
555556
const invalidParticipant = new CopilotCLIChatSessionParticipant(
556557
invalidContentProvider,

0 commit comments

Comments
 (0)