Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/commands/pickSession.ts
13406 views
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 * as vscode from 'vscode';
7
import * as l10n from '@vscode/l10n';
8
import { ILogger } from '../../../../../platform/log/common/logService';
9
import { ICopilotCLISessionTracker } from '../copilotCLISessionTracker';
10
import { InProcHttpServer } from '../inProcHttpServer';
11
12
/**
13
* Picks a connected CLI session to send to.
14
* Returns the sessionId, or undefined if none are connected or the user dismissed the picker.
15
* If only one session is connected, returns it directly without showing a picker.
16
*/
17
export async function pickSession(logger: ILogger, httpServer: InProcHttpServer, sessionTracker: ICopilotCLISessionTracker): Promise<string | undefined> {
18
const sessionIds = httpServer.getConnectedSessionIds();
19
20
if (sessionIds.length === 0) {
21
logger.debug('No connected CLI sessions');
22
vscode.window.showWarningMessage(l10n.t('No Copilot CLI sessions are connected.'));
23
return undefined;
24
}
25
26
if (sessionIds.length === 1) {
27
return sessionIds[0];
28
}
29
30
const items = sessionIds.map(id => ({
31
label: sessionTracker.getSessionDisplayName(id),
32
description: sessionTracker.getSessionDisplayName(id) !== id ? id : undefined,
33
sessionId: id,
34
}));
35
36
const picked = await vscode.window.showQuickPick(items, {
37
placeHolder: l10n.t('Select a CLI session to send to'),
38
});
39
40
return picked?.sessionId;
41
}
42
43