Skip to content

Commit 5bf82a3

Browse files
sandy081Copilot
andcommitted
Agents window: keep the new-session workspace helpers on the widget
The draft's workspace configuration and whether the composer offers more folders become private methods of NewChatWidget. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d9a8498 commit 5bf82a3

3 files changed

Lines changed: 32 additions & 24 deletions

File tree

‎src/vs/sessions/contrib/chat/test/browser/newChatWidget.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { IOpenNewSessionOptions, IOpenNewSessionResult, IOpenSessionOptions } fr
3131
import { SessionsManagementService } from '../../../../../workbench/contrib/sessions/browser/sessionsManagementService.js';
3232
import { ISessionsProvidersService, SessionsProvidersService } from '../../../../../workbench/contrib/sessions/browser/sessionsProvidersService.js';
3333
import { IPickedSessionType, IPreferredSessionType } from '../../../../../workbench/contrib/sessions/browser/chat/sessionTypePicker.js';
34-
import { BackgroundSendStatus, composesForAllSessions, getSupportsSessionFolders, NewChatWidget, shouldShowNewSessionChatTip } from '../../../../../workbench/contrib/sessions/browser/chat/newChatWidget.js';
34+
import { BackgroundSendStatus, composesForAllSessions, NewChatWidget, shouldShowNewSessionChatTip } from '../../../../../workbench/contrib/sessions/browser/chat/newChatWidget.js';
3535
import { INewSessionWorktreeSendChoiceProvider, NewSessionWorktreeSendChoiceService } from '../../../../../workbench/contrib/sessions/browser/chat/newSessionWorktreeSendChoice.js';
3636
import { findOnboardingTarget } from '../../../../../workbench/contrib/onboarding/browser/spotlight/onboardingTarget.js';
3737
import { OnboardingScenarioService } from '../../../../../workbench/contrib/onboarding/browser/onboardingService.js';
@@ -257,6 +257,7 @@ const recreateOnProviderChange = Reflect.get(NewChatWidget.prototype, '_recreate
257257
created: { readonly sessionId: string } | undefined,
258258
) => void;
259259
const handlePromptOptionsWorkspaceChange = Reflect.get(NewChatWidget.prototype, '_handlePromptOptionsWorkspaceChange') as (this: IPromptOptionsWorkspaceHarness, previousFolderUri: URI | undefined, folderUri: URI | undefined) => void;
260+
const getDraftWorkspaceConfig = Reflect.get(NewChatWidget.prototype, '_getDraftWorkspaceConfig') as (sessionId: string, workspace: ISessionWorkspace | undefined) => ISessionWorkspaceConfig | undefined;
260261
const syncWorkspacePickerFromSessionWorkspace = Reflect.get(NewChatWidget.prototype, '_syncWorkspacePickerFromSessionWorkspace') as (this: ISyncWorkspacePickerHarness, session: ITestSessionWithChat | undefined, workspace: ISessionWorkspace | undefined) => void;
261262
const hasEnoughSessionsForFirstRunNotices = Reflect.get(NewChatWidget.prototype, '_hasEnoughSessionsForFirstRunNotices') as (this: ISessionCountHarness) => boolean;
262263
const prepareChatTipSession = Reflect.get(NewChatWidget.prototype, '_prepareChatTipSession') as (this: IChatTipSessionHarness) => void;
@@ -344,6 +345,7 @@ interface ISyncWorkspacePickerHarness {
344345
matchesSelectedWorkspace(workspace: ISessionWorkspace): boolean;
345346
setSelectedWorkspace(folderUri: URI, options: { fireEvent: false; origin: WorkspaceSelectionOrigin; sessionWorkspaceUri?: URI }): void;
346347
};
348+
_getDraftWorkspaceConfig(sessionId: string, workspace: ISessionWorkspace | undefined): ISessionWorkspaceConfig | undefined;
347349
}
348350

349351
interface ISessionCountHarness {
@@ -4057,8 +4059,9 @@ suite('NewChatWidget', () => {
40574059
});
40584060

40594061
test('offers more folders only once the draft says its agent works in them, never before there is a draft', () => {
4060-
const draft = (supportsChatFolders: boolean | undefined) => ({ capabilities: constObservable({ supportsMultipleChats: false, supportsChatFolders }) }) as unknown as ISession;
4061-
assert.deepStrictEqual([undefined, draft(undefined), draft(false), draft(true)].map(session => derived(reader => getSupportsSessionFolders(session, reader)).get()), [false, false, false, true]);
4062+
const supportsSessionFolders = Reflect.get(NewChatWidget.prototype, '_supportsSessionFolders') as (this: object, reader: IReader) => boolean;
4063+
const draft = (supportsChatFolders: boolean | undefined) => upcastPartial<ISession>({ capabilities: constObservable({ supportsMultipleChats: false, supportsChatFolders }) });
4064+
assert.deepStrictEqual([undefined, draft(undefined), draft(false), draft(true)].map(session => derived(reader => supportsSessionFolders.call({ _session: constObservable(session) }, reader)).get()), [false, false, false, true]);
40624065
});
40634066

40644067
test('shows the folders the user added as pills, and keeps them while a send clears the input', () => {
@@ -4255,6 +4258,7 @@ suite('NewChatWidget', () => {
42554258
const selections: Array<{ readonly folderUri: string; readonly providerId: string; readonly persist: boolean; readonly preferDevContainer: boolean; readonly origin: WorkspaceSelectionOrigin }> = [];
42564259
const harness = {
42574260
_reconcileWorkspaceEnvironment: () => { },
4261+
_getDraftWorkspaceConfig: getDraftWorkspaceConfig,
42584262
uriIdentityService: { extUri },
42594263
sessionsProvidersService: {
42604264
getProvider: () => ({
@@ -4311,6 +4315,7 @@ suite('NewChatWidget', () => {
43114315
readonly sessionsProvidersService: { getProvider(): { readonly id: string; isDevContainerEnabled(): boolean } };
43124316
readonly _requestedWorkspaceConfig: { readonly sessionId: string; readonly config: ISessionWorkspaceConfig | undefined } | undefined;
43134317
_isSelectedWorkspaceConfig(session: ITestSessionWithChat, folderUri: URI): boolean;
4318+
_getDraftWorkspaceConfig(sessionId: string, workspace: ISessionWorkspace | undefined): ISessionWorkspaceConfig | undefined;
43144319
},
43154320
folderUri: URI | undefined,
43164321
) => boolean;
@@ -4358,6 +4363,7 @@ suite('NewChatWidget', () => {
43584363
_workspacePicker: { selectedResolved: { providerId: options.providerId ?? LOCAL_AGENT_HOST_PROVIDER_ID }, selectedWorkspaceConfig: options.selectedConfig, addedSessionFolderUris: options.added ?? [] },
43594364
_requestedWorkspaceConfig: options.requestedConfig && { sessionId: 'draft', config: options.requestedConfig },
43604365
_isSelectedWorkspaceConfig: isSelectedWorkspaceConfig,
4366+
_getDraftWorkspaceConfig: getDraftWorkspaceConfig,
43614367
_preferredDevContainerFolderUri: options.preferDevContainer ? folder : undefined,
43624368
_pendingWorkspaceCreation: options.pending ? Promise.resolve({ session: undefined, trustDeclined: false }) : undefined,
43634369
uriIdentityService: { extUri },
@@ -4634,6 +4640,7 @@ suite('NewChatWidget', () => {
46344640
matchesSelectedWorkspace: workspace => workspace.folders[0].root.toString() === cloudFolder.toString(),
46354641
setSelectedWorkspace: (folderUri, options) => selected.push({ folder: folderUri.toString(), origin: options.origin }),
46364642
},
4643+
_getDraftWorkspaceConfig: getDraftWorkspaceConfig,
46374644
};
46384645
const session = upcastPartial<ITestSessionWithChat>({ sessionId: 'draft' });
46394646
const workspace = (root: URI): ISessionWorkspace => upcastPartial<ISessionWorkspace>({

‎src/vs/sessions/contrib/chat/test/browser/sessionWorkspacePicker.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9188,7 +9188,7 @@ suite('WorkspacePicker - a composer outside the main window', () => {
91889188
_pendingWorktreePlacement: observableValue<object | undefined>('pendingWorktreePlacement', undefined),
91899189
_applyRequestedWorktreePlacement: () => { },
91909190
};
9191-
for (const method of ['_selectRequestedNoWorkspace', '_isRequestedAgent', '_seedRequestedTarget', '_syncWorkspacePickerDevContainerMode', 'selectNoWorkspace']) {
9191+
for (const method of ['_selectRequestedNoWorkspace', '_isRequestedAgent', '_seedRequestedTarget', '_syncWorkspacePickerDevContainerMode', '_getDraftWorkspaceConfig', 'selectNoWorkspace']) {
91929192
const implementation = Reflect.get(NewChatWidget.prototype, method) as (...args: unknown[]) => unknown;
91939193
harness[method] = (...args: unknown[]) => implementation.apply(harness, args);
91949194
}

‎src/vs/workbench/contrib/sessions/browser/chat/newChatWidget.ts‎

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,9 @@ function isWorktreeSupportEnabled(configurationService: IConfigurationService):
162162
return !!configurationService.getValue<boolean>(ChatConfiguration.EditorWindowEnableWorktree);
163163
}
164164

165-
/**
166-
* The workspace configuration the draft `sessionId` of `workspace` is in: as it records it, or as its composer requested
167-
* it (`requested`), for a provider that does not record it.
168-
*/
169-
function getDraftWorkspaceConfig(sessionId: string, workspace: ISessionWorkspace | undefined, requested: { readonly sessionId: string; readonly config: ISessionWorkspaceConfig | undefined } | undefined): ISessionWorkspaceConfig | undefined {
170-
return workspace?.workspaceConfig ?? (requested && requested.sessionId === sessionId ? requested.config : undefined);
171-
}
172-
173165
/** The prefix of the ids of the pills of the folders the user added to a new session. */
174166
const SESSION_FOLDER_CONTEXT_ID_PREFIX = 'session-folder:';
175167

176-
/**
177-
* Whether the composer offers more folders for the session of `draft`: only once the draft says its agent works in
178-
* them ({@link ISessionCapabilities.supportsChatFolders}). A provider that cannot drops the folders it is created with.
179-
*/
180-
export function getSupportsSessionFolders(draft: ISession | undefined, reader: IReader): boolean {
181-
return draft?.capabilities.read(reader).supportsChatFolders === true;
182-
}
183-
184168
export function isSessionWorkspaceOptOutEnabled(configurationService: IConfigurationService): boolean {
185169
return configurationService.getValue<boolean>(WORKSPACE_OPT_OUT_SETTING) === true;
186170
}
@@ -515,7 +499,7 @@ export class NewChatWidget extends Disposable {
515499
const PickerCtor = isWeb ? WebWorkspacePicker : WorkspacePicker;
516500
this._workspacePicker = this._register(this.instantiationService.createInstance(PickerCtor, {
517501
searchWorkspaceTargetDirectly: this.options.newSessionPresentation.searchWorkspaceTargetDirectly,
518-
supportsSessionFolders: derived(this, reader => getSupportsSessionFolders(this._session.read(reader), reader)),
502+
supportsSessionFolders: derived(this, reader => this._supportsSessionFolders(reader)),
519503
environment: this._environment,
520504
environmentPickerEnabled,
521505
canRestoreWorkspace: () => !this._savedDraftComposer?.isRestoring && !this._savedDraftTargetUnavailable.get()
@@ -1020,7 +1004,7 @@ export class NewChatWidget extends Disposable {
10201004
private _syncWorkspacePickerFromSessionWorkspace(session: ISession | undefined, workspace: ISessionWorkspace | undefined): void {
10211005
const folderUri = workspace?.folders[0]?.root;
10221006
if (session && folderUri && !this._workspacePicker.matchesSelectedWorkspace(workspace)) {
1023-
this._workspacePicker.setSelectedWorkspace(folderUri, { fireEvent: false, origin: WorkspaceSelectionOrigin.SessionSync, sessionWorkspaceUri: getDraftWorkspaceConfig(session.sessionId, workspace, this._requestedWorkspaceConfig)?.uri, sessionFolders: workspace?.folders.map(folder => folder.root) });
1007+
this._workspacePicker.setSelectedWorkspace(folderUri, { fireEvent: false, origin: WorkspaceSelectionOrigin.SessionSync, sessionWorkspaceUri: this._getDraftWorkspaceConfig(session.sessionId, workspace)?.uri, sessionFolders: workspace?.folders.map(folder => folder.root) });
10241008
}
10251009
}
10261010

@@ -2414,7 +2398,7 @@ export class NewChatWidget extends Disposable {
24142398
this._reconcileWorkspaceEnvironment({ providerId: activeSession.providerId, preferDevContainer });
24152399
}
24162400
const workspace = activeSession.workspace.get();
2417-
this._workspacePicker.setSelectedWorkspace(folderUri, { fireEvent: false, providerId: activeSession.providerId, persist, preferDevContainer, origin, sessionWorkspaceUri: getDraftWorkspaceConfig(activeSession.sessionId, workspace, this._requestedWorkspaceConfig)?.uri, sessionFolders: workspace?.folders.map(folder => folder.root) });
2401+
this._workspacePicker.setSelectedWorkspace(folderUri, { fireEvent: false, providerId: activeSession.providerId, persist, preferDevContainer, origin, sessionWorkspaceUri: this._getDraftWorkspaceConfig(activeSession.sessionId, workspace)?.uri, sessionFolders: workspace?.folders.map(folder => folder.root) });
24182402
return folderUri;
24192403
}
24202404

@@ -3834,6 +3818,23 @@ export class NewChatWidget extends Disposable {
38343818
/** The workspace configuration this composer requested its draft in, for a provider that does not record it. */
38353819
private _requestedWorkspaceConfig: { readonly sessionId: string; readonly config: ISessionWorkspaceConfig | undefined } | undefined;
38363820

3821+
/**
3822+
* The workspace configuration the draft `sessionId` of `workspace` is in: as it records it, or as this composer
3823+
* requested it, for a provider that does not record it.
3824+
*/
3825+
private _getDraftWorkspaceConfig(sessionId: string, workspace: ISessionWorkspace | undefined): ISessionWorkspaceConfig | undefined {
3826+
const requested = this._requestedWorkspaceConfig;
3827+
return workspace?.workspaceConfig ?? (requested && requested.sessionId === sessionId ? requested.config : undefined);
3828+
}
3829+
3830+
/**
3831+
* Whether the composer offers more folders for the session of its draft: only once the draft says its agent works in
3832+
* them ({@link ISessionCapabilities.supportsChatFolders}). A provider that cannot drops the folders it is created with.
3833+
*/
3834+
private _supportsSessionFolders(reader: IReader): boolean {
3835+
return this._session.read(reader)?.capabilities.read(reader).supportsChatFolders === true;
3836+
}
3837+
38373838
private _isCurrentWorkspaceSelection(folderUri: URI | undefined): boolean {
38383839
const session = this._session.get();
38393840
if (!folderUri || !session || isSessionCreated(session) || this._pendingWorkspaceCreation
@@ -3857,7 +3858,7 @@ export class NewChatWidget extends Disposable {
38573858
const selected = this._workspacePicker.selectedWorkspaceConfig;
38583859
const config = selected && extUri.isEqual(selected.folders[0], folderUri) ? selected : undefined;
38593860
const workspace = session.workspace.get();
3860-
const draftConfig = getDraftWorkspaceConfig(session.sessionId, workspace, this._requestedWorkspaceConfig);
3861+
const draftConfig = this._getDraftWorkspaceConfig(session.sessionId, workspace);
38613862
const sameConfig = !draftConfig || !config
38623863
? !draftConfig && !config
38633864
: extUri.isEqual(draftConfig.uri, config.uri)

0 commit comments

Comments
 (0)