Use observables for the dropdowns in Claude#311277
Merged
TylerLeonhardt merged 2 commits intomainfrom Apr 20, 2026
Merged
Conversation
This makes it wayyyy easier to test as we can trigger the pipeline and see if the expected groups get created. Co-authored-by: Copilot <copilot@github.com>
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors Claude chat session dropdown option building to be driven by observables, enabling end-to-end reactivity tests that assert option groups update in response to config, workspace, and session-state changes.
Changes:
- Introduce a per-input-state observable pipeline in
ClaudeChatSessionItemControllerto derive and pushinputState.groupsreactively. - Extract a pure
buildPermissionModeItemshelper and simplifyClaudeSessionOptionBuilderAPIs to be observable-friendly. - Expand tests to drive the reactive pipeline through config/workspace/session-state signals; extend session metadata mapping to include
gitBranch.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/chatSessions/vscode-node/claudeChatSessionContentProvider.ts | Adds the observable pipeline for dropdown groups and session-start locking behavior. |
| extensions/copilot/src/extension/chatSessions/vscode-node/claudeSessionOptionBuilder.ts | Simplifies group-building APIs and introduces pure permission-mode group construction. |
| extensions/copilot/src/extension/chatSessions/vscode-node/test/claudeChatSessionContentProvider.spec.ts | Adds integration-style tests to verify reactive group updates and fork state copying. |
| extensions/copilot/src/extension/chatSessions/vscode-node/test/claudeSessionOptionBuilder.spec.ts | Updates unit tests to match the simplified builder APIs. |
| extensions/copilot/src/extension/chatSessions/claude/node/sessionParser/sdkSessionAdapter.ts | Maps gitBranch into lightweight session info. |
| extensions/copilot/src/extension/chatSessions/claude/node/sessionParser/claudeSessionSchema.ts | Extends IClaudeCodeSessionInfo with optional gitBranch. |
Copilot's findings
Comments suppressed due to low confidence (2)
extensions/copilot/src/extension/chatSessions/vscode-node/claudeChatSessionContentProvider.ts:364
syncWorkspaceFolderItemskicks off an async MRU fetch when the workspace becomes empty, but the promise can resolve after the workspace folders change again (e.g. empty → multi-root quickly) and overwritefolderItemswith stale MRU results. Track a request/version token or re-check the latest workspace folder state before applying the async result so late resolutions can’t clobber newer folder-derived items.
store.add(autorun(reader => {
/** @description syncWorkspaceFolderItems */
const folders = this._workspaceFolders.read(reader);
if (folders.length !== 0) {
folderItems.set(
folders.map(f => toWorkspaceFolderOptionItem(f, this._workspaceService.getWorkspaceFolderName(f) || basename(f))),
undefined,
);
} else {
this._optionBuilder.getFolderOptionItems()
.then(items => folderItems.set(items, undefined))
.catch(e => this._logService.error(e));
}
}));
extensions/copilot/src/extension/chatSessions/vscode-node/claudeChatSessionContentProvider.ts:396
- The reactive pipeline seeds
permissionMode/folderUrionce from the initial groups, but never updates these observables when the user changes the dropdown selection ininputState.groups. As a result, any subsequent recomputation (e.g. workspace folder changes, bypass-permissions config toggles) will reset the selected item back to the initial seeded values rather than preserving the user’s latest choice. Sync selection back into the per-state observables (e.g. by observinginputState.onDidChangeand re-reading the selected items, with a guard to avoid feedback loops) so derived groups preserve current selections across external updates.
const permissionMode = observableValue<PermissionMode>(this, seed.permissionMode);
const folderUri = observableValue<URI | undefined>(this, seed.folderUri);
const folderItems = observableValue<readonly vscode.ChatSessionProviderOptionItem[]>(this, seed.folderItems);
const isSessionStarted = observableValue<boolean>(this, seed.isSessionStarted);
// When workspace folders change, update folder items reactively.
// Falls back to the async MRU list when the workspace becomes empty,
// matching the old imperative `buildNewFolderGroup` behavior.
store.add(autorun(reader => {
/** @description syncWorkspaceFolderItems */
const folders = this._workspaceFolders.read(reader);
if (folders.length !== 0) {
folderItems.set(
folders.map(f => toWorkspaceFolderOptionItem(f, this._workspaceService.getWorkspaceFolderName(f) || basename(f))),
undefined,
);
} else {
this._optionBuilder.getFolderOptionItems()
.then(items => folderItems.set(items, undefined))
.catch(e => this._logService.error(e));
}
}));
const permissionModeGroup = derived(reader => {
/** @description permissionModeGroup */
const bypassEnabled = this._bypassPermissionsEnabled.read(reader);
const selectedMode = permissionMode.read(reader);
const group = buildPermissionModeItems(bypassEnabled);
const selectedItem = group.items.find(i => i.id === selectedMode) ?? group.items[0];
return { ...group, selected: selectedItem };
});
const folderGroup = derived<vscode.ChatSessionProviderOptionGroup | undefined>(reader => {
/** @description folderGroup */
const items = folderItems.read(reader);
const folders = this._workspaceFolders.read(reader);
// Hide folder group when there's exactly one workspace folder (implicit)
if (folders.length === 1) {
return undefined;
}
const selectedFolder = folderUri.read(reader);
const locked = isSessionStarted.read(reader);
const lockedItems = locked ? items.map(i => ({ ...i, locked: true })) : items;
const selectedItem = selectedFolder
? lockedItems.find(i => i.id === selectedFolder.fsPath)
: lockedItems[0];
return {
id: FOLDER_OPTION_ID,
name: vscode.l10n.t('Folder'),
description: vscode.l10n.t('Pick Folder'),
items: lockedItems,
selected: selectedItem ? (locked ? { ...selectedItem, locked: true } : selectedItem) : undefined,
};
});
- Files reviewed: 6/6 changed files
- Comments generated: 1
roblourens
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes it wayyyy easier to test as we can trigger the pipeline and see if the expected groups get created.
Co-authored-by: Copilot copilot@github.com