Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/browser/mainThreadChatContext.ts
4778 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 { CancellationToken } from '../../../base/common/cancellation.js';
7
import { Disposable } from '../../../base/common/lifecycle.js';
8
import { ThemeIcon } from '../../../base/common/themables.js';
9
import { IChatContextItem, IChatContextSupport } from '../../contrib/chat/common/contextContrib/chatContext.js';
10
import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';
11
import { ExtHostChatContextShape, ExtHostContext, IDocumentFilterDto, MainContext, MainThreadChatContextShape } from '../common/extHost.protocol.js';
12
import { IChatContextService } from '../../contrib/chat/browser/contextContrib/chatContextService.js';
13
import { URI } from '../../../base/common/uri.js';
14
15
@extHostNamedCustomer(MainContext.MainThreadChatContext)
16
export class MainThreadChatContext extends Disposable implements MainThreadChatContextShape {
17
private readonly _proxy: ExtHostChatContextShape;
18
private readonly _providers = new Map<number, { id: string; selector: IDocumentFilterDto[] | undefined; support: IChatContextSupport }>();
19
20
constructor(
21
extHostContext: IExtHostContext,
22
@IChatContextService private readonly _chatContextService: IChatContextService
23
) {
24
super();
25
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostChatContext);
26
}
27
28
$registerChatContextProvider(handle: number, id: string, selector: IDocumentFilterDto[] | undefined, _options: { icon: ThemeIcon }, support: IChatContextSupport): void {
29
this._providers.set(handle, { selector, support, id });
30
this._chatContextService.registerChatContextProvider(id, selector, {
31
provideChatContext: (token: CancellationToken) => {
32
return this._proxy.$provideChatContext(handle, token);
33
},
34
resolveChatContext: support.supportsResolve ? (context: IChatContextItem, token: CancellationToken) => {
35
return this._proxy.$resolveChatContext(handle, context, token);
36
} : undefined,
37
provideChatContextForResource: support.supportsResource ? (resource: URI, withValue: boolean, token: CancellationToken) => {
38
return this._proxy.$provideChatContextForResource(handle, { resource, withValue }, token);
39
} : undefined
40
});
41
}
42
43
$unregisterChatContextProvider(handle: number): void {
44
const provider = this._providers.get(handle);
45
if (!provider) {
46
return;
47
}
48
this._chatContextService.unregisterChatContextProvider(provider.id);
49
this._providers.delete(handle);
50
}
51
52
$updateWorkspaceContextItems(handle: number, items: IChatContextItem[]): void {
53
const provider = this._providers.get(handle);
54
if (!provider) {
55
return;
56
}
57
this._chatContextService.updateWorkspaceContextItems(provider.id, items);
58
}
59
}
60
61