Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/agentHost/browser/agentSessionSettings.contribution.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 { localize, localize2 } from '../../../../nls.js';
8
import { Action2, registerAction2 } from '../../../../platform/actions/common/actions.js';
9
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
10
import { IFileService } from '../../../../platform/files/common/files.js';
11
import { IInstantiationService, ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
12
import { ILabelService } from '../../../../platform/label/common/label.js';
13
import { IEditorService } from '../../../../workbench/services/editor/common/editorService.js';
14
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../../workbench/common/contributions.js';
15
import { ChatSessionProviderIdContext } from '../../../common/contextkeys.js';
16
import { ISession } from '../../../services/sessions/common/session.js';
17
import { SessionItemContextMenuId } from '../../sessions/browser/views/sessionsList.js';
18
import { agentSessionSettingsUri, AGENT_SESSION_SETTINGS_SCHEME, AgentSessionSettingsFileSystemProvider, AgentSessionSettingsSchemaRegistrar } from './agentSessionSettingsFileSystemProvider.js';
19
import { ANY_AGENT_HOST_PROVIDER_RE } from '../../../common/agentHostSessionsProvider.js';
20
21
/**
22
* Registers the {@link AgentSessionSettingsFileSystemProvider} with the
23
* {@link IFileService} and contributes the "Open Session Settings" action.
24
*/
25
class AgentSessionSettingsContribution extends Disposable implements IWorkbenchContribution {
26
27
static readonly ID = 'sessions.contrib.agentSessionSettingsContribution';
28
29
constructor(
30
@IFileService fileService: IFileService,
31
@IInstantiationService instantiationService: IInstantiationService,
32
@ILabelService labelService: ILabelService,
33
) {
34
super();
35
36
const schemaRegistrar = this._register(instantiationService.createInstance(AgentSessionSettingsSchemaRegistrar));
37
const provider = this._register(instantiationService.createInstance(AgentSessionSettingsFileSystemProvider, schemaRegistrar));
38
this._register(fileService.registerProvider(AGENT_SESSION_SETTINGS_SCHEME, provider));
39
40
this._register(labelService.registerFormatter({
41
scheme: AGENT_SESSION_SETTINGS_SCHEME,
42
formatting: {
43
label: localize('agentSessionSettings.label', "Session Settings"),
44
separator: '/',
45
},
46
}));
47
}
48
}
49
50
registerWorkbenchContribution2(AgentSessionSettingsContribution.ID, AgentSessionSettingsContribution, WorkbenchPhase.AfterRestored);
51
52
registerAction2(class OpenSessionSettingsAction extends Action2 {
53
constructor() {
54
super({
55
id: 'sessionsViewPane.openSessionSettings',
56
title: localize2('openSessionSettings', "Open Session Settings"),
57
menu: [{
58
id: SessionItemContextMenuId,
59
group: '2_settings',
60
order: 1,
61
when: ContextKeyExpr.regex(ChatSessionProviderIdContext.key, ANY_AGENT_HOST_PROVIDER_RE),
62
}]
63
});
64
}
65
async run(accessor: ServicesAccessor, context?: ISession | ISession[]): Promise<void> {
66
const session = Array.isArray(context) ? context[0] : context;
67
if (!session) {
68
return;
69
}
70
const editorService = accessor.get(IEditorService);
71
const resource = agentSessionSettingsUri(session);
72
await editorService.openEditor({ resource, options: { pinned: true } });
73
}
74
});
75
76