import { IAction } from "../../../../base/common/actions.js"; import { Emitter, Event } from "../../../../base/common/event.js"; import { CancellationToken } from "../../../../base/common/cancellation.js"; import { Disposable, IDisposable } from "../../../../base/common/lifecycle.js"; import { URI } from "../../../../base/common/uri.js"; import { IObservable, IReader } from "../../../../base/common/observable.js"; import { IActionWidgetService } from "../../../../platform/actionWidget/browser/actionWidget.service.js"; import { IActionListItem, IActionListOptions } from "../../../../platform/actionWidget/browser/actionList.js"; import { ITabDescriptor } from "../../../../platform/actionWidget/browser/tabbedActionListWidget.js"; import { IMenuService } from "../../../../platform/actions/common/actions.service.js"; import { IRemoteAgentHostService } from "../../../../platform/agentHost/common/remoteAgentHostService.service.js"; import { ICommandService } from "../../../../platform/commands/common/commands.service.js"; import { IConfigurationService } from "../../../../platform/configuration/common/configuration.service.js"; import { ContextKeyExpression } from "../../../../platform/contextkey/common/contextkey.js"; import { IContextKeyService } from "../../../../platform/contextkey/common/contextkey.service.js"; import { IContextMenuService } from "../../../../platform/contextview/browser/contextView.service.js"; import { IFileDialogService } from "../../../../platform/dialogs/common/dialogs.service.js"; import { IDialogService } from "../../../../platform/dialogs/common/dialogs.service.js"; import { IFileService } from "../../../../platform/files/common/files.service.js"; import { IHoverService } from "../../../../platform/hover/browser/hover.service.js"; import { IHoverDelegate } from "../../../../base/browser/ui/hover/hoverDelegate.js"; import { IKeybindingService } from "../../../../platform/keybinding/common/keybinding.service.js"; import { IUriIdentityService } from "../../../../platform/uriIdentity/common/uriIdentity.service.js"; import { INotificationService } from "../../../../platform/notification/common/notification.service.js"; import { IProgressService } from "../../../../platform/progress/common/progress.service.js"; import { ThemeIcon } from "../../../../base/common/themables.js"; import { ISessionWorkspace, ISessionWorkspaceBrowseAction } from "../../../services/sessions/common/session.js"; import { ISessionsProvidersService } from "../../../services/sessions/browser/sessionsProvidersService.service.js"; import { IAgentHostFilterService } from "../../../services/agentHostFilter/common/agentHostFilter.service.js"; import { ISessionsRecentWorkspacesService } from "../../../services/sessions/browser/sessionsRecentWorkspacesService.service.js"; import { IInstantiationService } from "../../../../platform/instantiation/common/instantiation.js"; import { ITelemetryService } from "../../../../platform/telemetry/common/telemetry.service.js"; import { NewSessionWorkspacePreselectionSource } from "./newSessionComposerService.js"; import { IWorkspaceSelectionSnapshot, WorkspaceSelectionOrigin } from "../../../common/workspaceSelection.js"; import { type IResolvedFolderWorkspace } from "./sessionWorkspaceFallback.js"; import { IChatRequestVariableEntry } from "../../../../workbench/contrib/chat/common/attachments/chatVariableEntries.js"; import { ISessionCreationEnvironment } from "./sessionEnvironmentPicker.js"; export type { IResolvedFolderWorkspace } from "./sessionWorkspaceFallback.js"; /** How workspace picker rows are laid out: the folder name, then its location as a description that truncates first. */ export declare const WORKSPACE_PICKER_LIST_OPTIONS: { readonly className: "sessions-new-chat-picker-list"; readonly useFullHeight: true; readonly reserveSubmenuSpace: false; readonly inlineDescription: true; readonly showGroupTitleOnFirstItem: true; readonly hideDefaultKeybindingTooltip: true; }; export declare const MAX_NEW_PICKER_RECENT_WORKSPACES = 10; /** * Item type used in the action list. */ export interface IWorkspacePickerItem { readonly id?: string; readonly folderUri?: URI; readonly ariaLabel?: string; /** The resolved workspace (used for unavailable-provider checks). */ readonly providerId?: string; readonly browseActionIndex?: number; readonly browseAction?: ISessionWorkspaceBrowseAction; readonly attachAsContext?: boolean; readonly checked?: boolean; /** Whether selecting this folder should use its Dev Container. */ preferDevContainer?: boolean; /** Command to execute when this item is selected. */ readonly commandId?: string; /** Inline action to run when this item is selected. */ readonly run?: () => void; } export interface IWorkspacePickerOptions { readonly environment?: IObservable; readonly environmentPickerEnabled?: IObservable; readonly onUserSelection?: () => void; readonly whenSelectionAccepted?: () => Promise; readonly canSelectWorkspace?: (folderUri: URI, providerId: string | undefined) => Promise; readonly canRestoreWorkspace?: () => boolean; readonly restoreFromSessions?: boolean; readonly sessionWorkspaceProviderFilter?: (providerId: string) => boolean; readonly getWorkspaceGroupAction?: (group: string | undefined) => IWorkspacePickerGroupAction | undefined; readonly getNoWorkspaceOption?: () => IWorkspacePickerNoWorkspaceOption | undefined; } export interface IWorkspacePickerGroupAction { readonly label: string; readonly description?: string; readonly icon: ThemeIcon; readonly commandId: string; readonly hideWorkspaceItems?: boolean; } export interface IWorkspacePickerNoWorkspaceOption { readonly description: string; readonly isSelected: boolean; readonly selectedLabel?: string; readonly select: () => void; readonly submenuActions?: readonly IAction[]; } export interface IWorkspacePickerTrigger { readonly label?: string; readonly ariaLabel: string; readonly tooltip?: string | (() => string); readonly focusCommand?: { readonly id: string; readonly when: ContextKeyExpression; readonly enabled: IObservable; }; readonly icon?: ThemeIcon; readonly contextViewLayer?: number; readonly hideNoWorkspaceOption?: boolean; readonly hideIconWhenAttached?: boolean; readonly reflectsWorkspace?: boolean; readonly clearable?: IObservable; readonly group?: string; readonly attachesContext?: boolean; readonly hideWhenWorkspaceSelected?: boolean; readonly hideWhenNoWorkspaceSelected?: boolean; readonly hideWhenNoGitHubRepository?: boolean; } export interface IResolvedBrowseSelection { readonly workspace: ISessionWorkspace; readonly providerId: string; } /** * A unified workspace picker that shows workspaces from all registered session * providers in a single dropdown. * * Browse actions from providers are appended at the bottom of the list. */ export declare class WorkspacePicker extends Disposable { protected readonly options: IWorkspacePickerOptions; protected readonly actionWidgetService: IActionWidgetService; private readonly uriIdentityService; protected readonly sessionsProvidersService: ISessionsProvidersService; private readonly recentWorkspacesService; private readonly remoteAgentHostService; private readonly configurationService; private readonly commandService; private readonly menuService; private readonly contextKeyService; private readonly instantiationService; private readonly fileDialogService; private readonly telemetryService; private readonly notificationService; private readonly keybindingService; private readonly contextMenuService; private readonly fileService; private readonly dialogService; private readonly agentHostFilterService; private readonly progressService; protected readonly _onDidSelectWorkspace: Emitter; readonly onDidSelectWorkspace: Event; private readonly _onDidSelectWorkspaceMode; readonly onDidSelectWorkspaceMode: Event<{ readonly folderUri: URI; readonly preferDevContainer: boolean; }>; protected readonly _onDidChangeSelection: Emitter; readonly onDidChangeSelection: Event; private readonly _onDidChangeChatPetPlatform; readonly onDidChangeChatPetPlatform: Event; private readonly _onDidSelectContext; readonly onDidSelectContext: Event; private readonly _onDidSelectFolderContext; readonly onDidSelectFolderContext: Event; private readonly _onDidSelectRepositoryContext; readonly onDidSelectRepositoryContext: Event; private readonly _onDidRemoveAttachedContext; readonly onDidRemoveAttachedContext: Event; private _selectedFolderUri; private _selectedResolved; private _selectedDevContainerFolderUri; private _preselectionSource; private _selectionOrigin; private _selectionGeneration; private _sessionRestoreGeneration; private readonly _sessionRestoreState; private readonly _sessionWorkspaceFallback; /** * Set to `true` once the user has explicitly picked or cleared a workspace. * Until then, late-arriving provider registrations are allowed to upgrade * the current (auto-restored) selection to the user's stored "checked" * entry. After the user has acted, providers coming and going never move * the selection out from under them. */ private _userHasPicked; /** * Watches the connection status of a restored remote workspace. Cleared when * the user explicitly picks, when the connection succeeds, or when it fails * and we fall back. */ private readonly _connectionStatusWatch; private readonly _gitHubInfoWatch; private readonly _providerSessionTypesWatch; private readonly _localBrowseAction; /** * "Primary" trigger. This is the most recently created entry. Preserved for subclass * read access (e.g. {@link WebWorkspacePicker} anchors its mobile sheet here) and for * {@link showPicker} calls that do not supply an anchor. */ protected _triggerElement: HTMLElement | undefined; /** All live trigger elements. Label updates fan out to every entry. */ private readonly _triggerElements; private readonly _triggerOptions; private readonly _triggerContents; private readonly _contextSelections; private readonly _renderDisposables; private readonly _additionalRepositorySelections; private readonly _additionalFolderSelections; private readonly _devContainerAvailability; private readonly _onDidChangeDevContainerAvailability; readonly onDidChangeDevContainerAvailability: Event; private readonly _devContainerAvailabilityLimiter; private readonly _devContainerAvailabilityRefresh; private _attachedContext; private readonly _pickerGroupContext; private _activeTriggerElement; protected _directPickerGroup: string | undefined; protected _directPickerAttachesContext: boolean | undefined; /** * Currently active workspace tab (a group label contributed by a * provider, e.g. `"This Computer"` / `"Cloud"` / `"Remote"`). */ private _activeTab; get selectedFolderUri(): URI | undefined; /** * Returns the currently selected folder resolved to a workspace via the * first provider that can resolve it. Used internally for rendering * (label, icon, group). The provider association is not part of the * picker's public contract — callers should use {@link selectedFolderUri} * and let the management service rediscover the provider. */ get selectedResolved(): IResolvedFolderWorkspace | undefined; get additionalFolderUris(): readonly URI[]; get attachedContextWorkspaces(): readonly ISessionWorkspace[]; clearAttachedContext(): void; syncAttachedContext(attachments: readonly IChatRequestVariableEntry[]): void; private _syncAttachedContext; get preselectionSource(): NewSessionWorkspacePreselectionSource; get selectionSnapshot(): IWorkspaceSelectionSnapshot; matchesSelectedWorkspace(workspace: ISessionWorkspace, reader?: IReader): boolean; constructor(options: IWorkspacePickerOptions, actionWidgetService: IActionWidgetService, uriIdentityService: IUriIdentityService, sessionsProvidersService: ISessionsProvidersService, recentWorkspacesService: ISessionsRecentWorkspacesService, remoteAgentHostService: IRemoteAgentHostService, configurationService: IConfigurationService, commandService: ICommandService, menuService: IMenuService, contextKeyService: IContextKeyService, instantiationService: IInstantiationService, fileDialogService: IFileDialogService, telemetryService: ITelemetryService, notificationService: INotificationService, _hoverService: IHoverService, keybindingService: IKeybindingService, contextMenuService: IContextMenuService, fileService: IFileService, dialogService: IDialogService, agentHostFilterService: IAgentHostFilterService, progressService: IProgressService); protected _selectWorkspaceGroup(group: string): void; /** * Renders the project picker trigger button into the given container. * Returns the container element. * * Calling it again replaces the trigger created by the previous * {@link render} call. */ render(container: HTMLElement, hoverDelegate?: IHoverDelegate): HTMLElement; /** * Renders another trigger without replacing the primary picker controls. */ renderAdditionalTrigger(container: HTMLElement, options: IWorkspacePickerTrigger): IDisposable; renderCategoryTriggers(container: HTMLElement, triggers: readonly IWorkspacePickerTrigger[], label?: string, hoverDelegate?: IHoverDelegate): HTMLElement; getChatPetPlatformElements(): readonly HTMLElement[]; /** * Shared trigger-creation core for {@link render}. Wires up the click / * keyboard / touch handlers and the per-trigger lifecycle. */ private _addTrigger; /** Overridable clock so the ghost-click guard can be tested deterministically. */ protected _now(): number; /** * Shows the workspace picker dropdown anchored to a trigger element. * * @param force When true, re-show even if the picker is already visible. * Used internally when swapping items in place after a tab * change. * @param anchor The specific trigger element to anchor the popup to. When * omitted, defaults to the most-recently rendered trigger. * Pass through when more than one trigger is live and the * popup should align with the one the user actually clicked. */ showPicker(force?: boolean, anchor?: HTMLElement, preferredGroup?: string, attachesContext?: boolean): void; protected _setDirectPickerFilter(group: string | undefined, attachesContext: boolean | undefined): void; refreshPresentation(): void; protected _getAvailableTabs(): ITabDescriptor[]; private _buildDelegate; protected _buildListOptions(items: readonly IActionListItem[], pickerWidth: number | undefined): IActionListOptions; /** * Flat (no-tabs) presentation. Delegates rendering to the shared * `IActionWidgetService` so we benefit from its keybindings, focus * tracking and submenu chrome. */ private _showFlatPicker; /** * Dispatch logic for a picker item once the user picks it. Shared * between the desktop action-widget delegate and any mobile sheet * subclass that opts to render a different UI but reuse the * selection semantics. Treats unavailable workspaces as a no-op. */ protected _dispatchPickerItem(item: IWorkspacePickerItem): Promise; private _attachAdditionalFolder; private _attachAdditionalRepository; protected _findRelatedLocalWorkspace(workspace: ISessionWorkspace): IResolvedFolderWorkspace | undefined; private _cloneRepositoryInEnvironment; private _findRelatedEnvironmentWorkspace; private _getRepositoryId; private _watchProviderSessionTypes; protected _refreshPickerItems(): void; protected _refreshRecentWorkspaces(): void; private _getCurrentRepositoryId; /** * Emits `newChatPickerClosed` telemetry on user selection. The * "before" value is read from storage (the currently-checked recent * workspace) if available, otherwise from the in-memory selection. * The "after" value comes from the item the user picked — undefined * when the item is a browse action or command rather than a workspace. */ private _reportPickerClosed; /** * Programmatically set the selected workspace by folder URI. * @param folderUri The folder URI to select. * @param options.fireEvent Whether to fire the onDidSelectWorkspace event. Defaults to true. * @param options.providerId Optional providerId hint that wins over any historical * recent entry's provider. Use when the caller knows which provider should * own the resulting session (e.g. "New Session" invoked from a workspace * section in the sessions list, where the existing sessions for the * workspace were created by a specific provider). * @param options.persist Whether to persist the selection as a recent workspace. Defaults to true. */ setSelectedWorkspace(folderUri: URI, options?: { fireEvent?: boolean; providerId?: string; persist?: boolean; preferDevContainer?: boolean; origin?: WorkspaceSelectionOrigin; }): void; private _setTriggerExpanded; private _hidePicker; /** * Clears the selected project. */ clearSelection(): void; isNoWorkspaceSelected(): boolean; selectNoWorkspace(userSelection?: boolean): void; /** * Clears the selection if it matches the given URI. */ removeFromRecents(uri: URI): void; private _selectFolder; protected _shouldPersistSelection(): boolean; /** * Apply a restored selection without firing events or persisting. Used * during construction and after provider list changes. */ private _applySelection; private _watchSelectedGitHubInfo; private _getSelectedRepositoryWorkspace; private _getSelectedRepositoryWorkspaceCandidates; private _getRepositoryIdForResolvedWorkspace; private _getRepositoryWorkspaceCandidates; /** * Iterate providers and return the first resolution of the folder URI. * When `preferredProviderId` is given, that provider is tried first so a * user's historical pick survives provider iteration order changes. */ private _resolveFolder; /** * Executes a provider browse action referenced directly or by picker index. */ private _executeBrowseAction; private _canSelectWorkspace; /** * Collects browse actions from all registered providers, scoped to the * currently active tab when tabs are shown. */ protected _getAllBrowseActions(): ISessionWorkspaceBrowseAction[]; private _isWorkspaceProviderVisible; private _getEnvironment; getEnvironmentWorkspace(environment: ISessionCreationEnvironment, reader?: IReader, preferredFolderUri?: URI): IResolvedFolderWorkspace | undefined; private _getWorkspaceIcon; private _getTabGroup; private _isGroupInActiveTab; /** * Opens a folder picker dialog and returns the chosen URI. The folder's * provider is rediscovered later by the management service when the * session is created — no provider quick-pick is needed here. */ private _browseForLocalFolder; /** True when the picker is currently scoped to a single tab. */ protected _isTabFiltered(): boolean; private _getActivePickerGroup; /** * Builds the picker items list from recent workspaces. * * Items are shown in a flat recency-sorted list (most recently used first) * without source grouping. Own recents come first, followed by VS Code * recent folders. */ protected _buildItems(): IActionListItem[]; protected _getNoWorkspaceOption(): IWorkspacePickerNoWorkspaceOption | undefined; protected _getNoWorkspaceLabel(): string; private _getSelectedNoWorkspaceLabel; getEnvironmentActions(environment: ISessionCreationEnvironment): IAction[]; private _showRemoteHostOptionsDelayed; protected _updateTriggerLabel(): void; refreshTriggerLabel(): void; protected _renderTriggerLabel(trigger: HTMLElement): void; private _getWorkspaceLabel; private _isDevContainerWorkspaceAvailable; whenDevContainerWorkspaceAvailable(folderUri: URI, providerId: string): Promise; private _getDevContainerProvider; getDevContainerWorkspaceAvailability(folderUri: URI, providerId: string): boolean | "error" | undefined; private _clearDevContainerAvailability; /** * Returns whether the given provider is a remote that is currently unavailable * (incompatible, or disconnected/still connecting without on-demand connect). * Returns false for providers without connection status (e.g. local providers). */ protected _isProviderUnavailable(providerId: string): boolean; private _connectProviderOnDemand; protected _isSelectedFolder(folderUri: URI | undefined): boolean; private _restoreSelectedWorkspace; protected _resetAutomaticSelection(): void; /** Re-runs automatic selection and reports whether it changed synchronously. */ refreshAutomaticSelection(): boolean; /** Waits for history and the latest session-workspace lookup and reports whether both completed successfully. */ whenWorkspaceRestored(token: CancellationToken): Promise; private _restoreAutomaticSelection; private _scheduleSessionWorkspaceRestore; private _canRestoreProviderWorkspace; private _canRestoreWorkspace; /** * Restore only the checked (previously selected) workspace if any * provider can resolve its URI. The provider's connection status is * intentionally NOT checked — we honor the user's explicit pick even * if the remote is still connecting or currently disconnected. The * trigger label reflects the connection state separately * (spinner / grayed). */ private _restoreCheckedWorkspace; /** * When restoring a workspace whose provider isn't currently Connected, * watch the connection status. Fires `onDidSelectWorkspace(undefined)` * (which the view pane converts to `unsetNewSession()`) if: * - the status transitions to Disconnected after we start watching, or * - the status is still not Connected after a short grace period. * * The grace period covers a race: provider state can transition synchronously * inside provider registration before our autorun's first read, so we may * never observe an explicit Disconnected transition. The timer ensures we * eventually fall back instead of leaving the picker showing an unreachable * remote with no session. * * Has no effect once the user makes an explicit pick (`_userHasPicked`). */ private _watchForConnectionFailure; protected _workspaceFilter: string; protected _matchesWorkspaceFilter(workspace: ISessionWorkspace): boolean; protected _getRecentWorkspaces(includeOlder?: boolean): IResolvedFolderWorkspace[]; protected _removeRecentWorkspace(folderUri: URI): void; }