Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/chatDebug/browser/chatDebug.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 { Codicon } from '../../../../base/common/codicons.js';
7
import { Disposable } from '../../../../base/common/lifecycle.js';
8
import { localize, localize2 } from '../../../../nls.js';
9
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
10
import { Registry } from '../../../../platform/registry/common/platform.js';
11
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
12
import { ViewPaneContainer } from '../../../../workbench/browser/parts/views/viewPaneContainer.js';
13
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../../workbench/common/contributions.js';
14
import { IViewContainersRegistry, IViewDescriptor, IViewsRegistry, ViewContainerLocation, Extensions as ViewContainerExtensions, WindowEnablement } from '../../../../workbench/common/views.js';
15
16
const COPILOT_CHAT_VIEW_CONTAINER_ID = 'workbench.view.extension.copilot-chat';
17
const COPILOT_CHAT_VIEW_ID = 'copilot-chat';
18
const SESSIONS_CHAT_DEBUG_CONTAINER_ID = 'workbench.sessions.panel.chatDebugContainer';
19
20
const chatDebugViewIcon = registerIcon('sessions-chat-debug-view-icon', Codicon.debug, localize('sessionsChatDebugViewIcon', 'View icon of the chat debug view in the sessions window.'));
21
22
class RegisterChatDebugViewContribution extends Disposable implements IWorkbenchContribution {
23
24
static readonly ID = 'sessions.registerChatDebugView';
25
26
constructor() {
27
super();
28
29
const viewContainerRegistry = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry);
30
const viewsRegistry = Registry.as<IViewsRegistry>(ViewContainerExtensions.ViewsRegistry);
31
32
// The copilot-chat view is contributed by the Copilot Chat extension,
33
// which may register after this contribution runs. Handle both cases.
34
if (!this.tryMoveView(viewContainerRegistry, viewsRegistry)) {
35
const listener = viewsRegistry.onViewsRegistered(e => {
36
for (const { views } of e) {
37
if (views.some(v => v.id === COPILOT_CHAT_VIEW_ID)) {
38
if (this.tryMoveView(viewContainerRegistry, viewsRegistry)) {
39
listener.dispose();
40
}
41
break;
42
}
43
}
44
});
45
this._register(listener);
46
}
47
}
48
49
private tryMoveView(viewContainerRegistry: IViewContainersRegistry, viewsRegistry: IViewsRegistry): boolean {
50
const viewContainer = viewContainerRegistry.get(COPILOT_CHAT_VIEW_CONTAINER_ID);
51
if (!viewContainer) {
52
return false;
53
}
54
55
const view = viewsRegistry.getView(COPILOT_CHAT_VIEW_ID);
56
if (!view) {
57
return false;
58
}
59
60
// Deregister the view from its original extension container
61
viewsRegistry.deregisterViews([view], viewContainer);
62
viewContainerRegistry.deregisterViewContainer(viewContainer);
63
64
// Register a new chat debug view container in the Panel for the sessions window
65
const chatDebugViewContainer = viewContainerRegistry.registerViewContainer({
66
id: SESSIONS_CHAT_DEBUG_CONTAINER_ID,
67
title: localize2('chatDebug', "Chat Debug"),
68
icon: chatDebugViewIcon,
69
order: 3,
70
ctorDescriptor: new SyncDescriptor(ViewPaneContainer, [SESSIONS_CHAT_DEBUG_CONTAINER_ID, { mergeViewWithContainerWhenSingleView: true }]),
71
storageId: SESSIONS_CHAT_DEBUG_CONTAINER_ID,
72
hideIfEmpty: true,
73
windowEnablement: WindowEnablement.Sessions,
74
}, ViewContainerLocation.Panel, { doNotRegisterOpenCommand: true });
75
76
// Re-register the view inside the new sessions container
77
const sessionsView: IViewDescriptor = {
78
...view,
79
canMoveView: false,
80
windowEnablement: WindowEnablement.Sessions,
81
};
82
viewsRegistry.registerViews([sessionsView], chatDebugViewContainer);
83
84
return true;
85
}
86
}
87
88
registerWorkbenchContribution2(RegisterChatDebugViewContribution.ID, RegisterChatDebugViewContribution, WorkbenchPhase.BlockRestore);
89
90