Path: blob/main/src/vs/workbench/api/common/extHostAiRelatedInformation.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';6import { ExtHostAiRelatedInformationShape, IMainContext, MainContext, MainThreadAiRelatedInformationShape } from './extHost.protocol.js';7import type { CancellationToken, RelatedInformationProvider, RelatedInformationType, RelatedInformationResult } from 'vscode';8import { Disposable } from './extHostTypes.js';910export class ExtHostRelatedInformation implements ExtHostAiRelatedInformationShape {11private _relatedInformationProviders: Map<number, RelatedInformationProvider> = new Map();12private _nextHandle = 0;1314private readonly _proxy: MainThreadAiRelatedInformationShape;1516constructor(mainContext: IMainContext) {17this._proxy = mainContext.getProxy(MainContext.MainThreadAiRelatedInformation);18}1920async $provideAiRelatedInformation(handle: number, query: string, token: CancellationToken): Promise<RelatedInformationResult[]> {21if (this._relatedInformationProviders.size === 0) {22throw new Error('No related information providers registered');23}2425const provider = this._relatedInformationProviders.get(handle);26if (!provider) {27throw new Error('related information provider not found');28}2930const result = await provider.provideRelatedInformation(query, token) ?? [];31return result;32}3334getRelatedInformation(extension: IExtensionDescription, query: string, types: RelatedInformationType[]): Promise<RelatedInformationResult[]> {35return this._proxy.$getAiRelatedInformation(query, types);36}3738registerRelatedInformationProvider(extension: IExtensionDescription, type: RelatedInformationType, provider: RelatedInformationProvider): Disposable {39const handle = this._nextHandle;40this._nextHandle++;41this._relatedInformationProviders.set(handle, provider);42this._proxy.$registerAiRelatedInformationProvider(handle, type);43return new Disposable(() => {44this._proxy.$unregisterAiRelatedInformationProvider(handle);45this._relatedInformationProviders.delete(handle);46});47}48}495051