Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/common/extHostAiRelatedInformation.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 { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
7
import { ExtHostAiRelatedInformationShape, IMainContext, MainContext, MainThreadAiRelatedInformationShape } from './extHost.protocol.js';
8
import type { CancellationToken, RelatedInformationProvider, RelatedInformationType, RelatedInformationResult } from 'vscode';
9
import { Disposable } from './extHostTypes.js';
10
11
export class ExtHostRelatedInformation implements ExtHostAiRelatedInformationShape {
12
private _relatedInformationProviders: Map<number, RelatedInformationProvider> = new Map();
13
private _nextHandle = 0;
14
15
private readonly _proxy: MainThreadAiRelatedInformationShape;
16
17
constructor(mainContext: IMainContext) {
18
this._proxy = mainContext.getProxy(MainContext.MainThreadAiRelatedInformation);
19
}
20
21
async $provideAiRelatedInformation(handle: number, query: string, token: CancellationToken): Promise<RelatedInformationResult[]> {
22
if (this._relatedInformationProviders.size === 0) {
23
throw new Error('No related information providers registered');
24
}
25
26
const provider = this._relatedInformationProviders.get(handle);
27
if (!provider) {
28
throw new Error('related information provider not found');
29
}
30
31
const result = await provider.provideRelatedInformation(query, token) ?? [];
32
return result;
33
}
34
35
getRelatedInformation(extension: IExtensionDescription, query: string, types: RelatedInformationType[]): Promise<RelatedInformationResult[]> {
36
return this._proxy.$getAiRelatedInformation(query, types);
37
}
38
39
registerRelatedInformationProvider(extension: IExtensionDescription, type: RelatedInformationType, provider: RelatedInformationProvider): Disposable {
40
const handle = this._nextHandle;
41
this._nextHandle++;
42
this._relatedInformationProviders.set(handle, provider);
43
this._proxy.$registerAiRelatedInformationProvider(handle, type);
44
return new Disposable(() => {
45
this._proxy.$unregisterAiRelatedInformationProvider(handle);
46
this._relatedInformationProviders.delete(handle);
47
});
48
}
49
}
50
51