Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/actions/chatClear.ts
5284 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 { Schemas } from '../../../../../base/common/network.js';
7
import { generateUuid } from '../../../../../base/common/uuid.js';
8
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
9
import { IEditorService } from '../../../../services/editor/common/editorService.js';
10
import { IChatEditorOptions } from '../widgetHosts/editor/chatEditor.js';
11
import { ChatEditorInput } from '../widgetHosts/editor/chatEditorInput.js';
12
13
export async function clearChatEditor(accessor: ServicesAccessor, chatEditorInput?: ChatEditorInput): Promise<void> {
14
const editorService = accessor.get(IEditorService);
15
16
if (!chatEditorInput) {
17
const editorInput = editorService.activeEditor;
18
chatEditorInput = editorInput instanceof ChatEditorInput ? editorInput : undefined;
19
}
20
21
if (chatEditorInput instanceof ChatEditorInput) {
22
// If we have a contributed session, make sure we create an untitled session for it.
23
// Otherwise create a generic new chat editor.
24
const resource = chatEditorInput.sessionResource && chatEditorInput.sessionResource.scheme !== Schemas.vscodeLocalChatSession
25
? chatEditorInput.sessionResource.with({ path: `/untitled-${generateUuid()}` })
26
: ChatEditorInput.getNewEditorUri();
27
28
// A chat editor can only be open in one group
29
const identifier = editorService.findEditors(chatEditorInput.resource)[0];
30
await editorService.replaceEditors([{
31
editor: chatEditorInput,
32
replacement: { resource, options: { pinned: true } satisfies IChatEditorOptions }
33
}], identifier.groupId);
34
}
35
}
36
37