Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/browser/mainThreadAiRelatedInformation.ts
3296 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, DisposableMap } from '../../../base/common/lifecycle.js';
8
import { ExtHostAiRelatedInformationShape, ExtHostContext, MainContext, MainThreadAiRelatedInformationShape } from '../common/extHost.protocol.js';
9
import { RelatedInformationType } from '../common/extHostTypes.js';
10
import { IAiRelatedInformationProvider, IAiRelatedInformationService, RelatedInformationResult } from '../../services/aiRelatedInformation/common/aiRelatedInformation.js';
11
import { IExtHostContext, extHostNamedCustomer } from '../../services/extensions/common/extHostCustomers.js';
12
13
@extHostNamedCustomer(MainContext.MainThreadAiRelatedInformation)
14
export class MainThreadAiRelatedInformation extends Disposable implements MainThreadAiRelatedInformationShape {
15
private readonly _proxy: ExtHostAiRelatedInformationShape;
16
private readonly _registrations = this._register(new DisposableMap<number>());
17
18
constructor(
19
context: IExtHostContext,
20
@IAiRelatedInformationService private readonly _aiRelatedInformationService: IAiRelatedInformationService,
21
) {
22
super();
23
this._proxy = context.getProxy(ExtHostContext.ExtHostAiRelatedInformation);
24
}
25
26
$getAiRelatedInformation(query: string, types: RelatedInformationType[]): Promise<RelatedInformationResult[]> {
27
// TODO: use a real cancellation token
28
return this._aiRelatedInformationService.getRelatedInformation(query, types, CancellationToken.None);
29
}
30
31
$registerAiRelatedInformationProvider(handle: number, type: RelatedInformationType): void {
32
const provider: IAiRelatedInformationProvider = {
33
provideAiRelatedInformation: (query, token) => {
34
return this._proxy.$provideAiRelatedInformation(handle, query, token);
35
},
36
};
37
this._registrations.set(handle, this._aiRelatedInformationService.registerAiRelatedInformationProvider(type, provider));
38
}
39
40
$unregisterAiRelatedInformationProvider(handle: number): void {
41
this._registrations.deleteAndDispose(handle);
42
}
43
}
44
45