Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/chat/browser/sessionsOpenerParticipant.ts
13401 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 { Disposable } from '../../../../base/common/lifecycle.js';
7
import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js';
8
import { IWorkbenchContribution } from '../../../../workbench/common/contributions.js';
9
import { IAgentSession } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js';
10
import { ISessionOpenerParticipant, ISessionOpenOptions, sessionOpenerRegistry } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsOpener.js';
11
import { ISessionsManagementService } from '../../../services/sessions/common/sessionsManagement.js';
12
13
/**
14
* Routes session open requests in the Agents window through the
15
* {@link ISessionsManagementService} so that the active session/chat state is
16
* properly updated. Without this, the default opener tries to load the chat
17
* directly into the `ChatViewId` view, which is hidden behind a `when` clause
18
* tied to the new-chat context keys and may simply do nothing.
19
*/
20
class SessionsOpenerParticipant implements ISessionOpenerParticipant {
21
22
async handleOpenSession(accessor: ServicesAccessor, session: IAgentSession, openOptions?: ISessionOpenOptions): Promise<boolean> {
23
const sessionsManagementService = accessor.get(ISessionsManagementService);
24
const target = sessionsManagementService.getSession(session.resource);
25
if (!target) {
26
return false;
27
}
28
29
await sessionsManagementService.openSession(session.resource, { preserveFocus: openOptions?.editorOptions?.preserveFocus });
30
return true;
31
}
32
}
33
34
export class SessionsOpenerParticipantContribution extends Disposable implements IWorkbenchContribution {
35
36
static readonly ID = 'sessions.sessionOpenerParticipant';
37
38
constructor() {
39
super();
40
this._register(sessionOpenerRegistry.registerParticipant(new SessionsOpenerParticipant()));
41
}
42
}
43
44