Path: blob/main/src/vs/workbench/api/browser/mainThreadAiRelatedInformation.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 { CancellationToken } from '../../../base/common/cancellation.js';6import { Disposable, DisposableMap } from '../../../base/common/lifecycle.js';7import { ExtHostAiRelatedInformationShape, ExtHostContext, MainContext, MainThreadAiRelatedInformationShape } from '../common/extHost.protocol.js';8import { RelatedInformationType } from '../common/extHostTypes.js';9import { IAiRelatedInformationProvider, IAiRelatedInformationService, RelatedInformationResult } from '../../services/aiRelatedInformation/common/aiRelatedInformation.js';10import { IExtHostContext, extHostNamedCustomer } from '../../services/extensions/common/extHostCustomers.js';1112@extHostNamedCustomer(MainContext.MainThreadAiRelatedInformation)13export class MainThreadAiRelatedInformation extends Disposable implements MainThreadAiRelatedInformationShape {14private readonly _proxy: ExtHostAiRelatedInformationShape;15private readonly _registrations = this._register(new DisposableMap<number>());1617constructor(18context: IExtHostContext,19@IAiRelatedInformationService private readonly _aiRelatedInformationService: IAiRelatedInformationService,20) {21super();22this._proxy = context.getProxy(ExtHostContext.ExtHostAiRelatedInformation);23}2425$getAiRelatedInformation(query: string, types: RelatedInformationType[]): Promise<RelatedInformationResult[]> {26// TODO: use a real cancellation token27return this._aiRelatedInformationService.getRelatedInformation(query, types, CancellationToken.None);28}2930$registerAiRelatedInformationProvider(handle: number, type: RelatedInformationType): void {31const provider: IAiRelatedInformationProvider = {32provideAiRelatedInformation: (query, token) => {33return this._proxy.$provideAiRelatedInformation(handle, query, token);34},35};36this._registrations.set(handle, this._aiRelatedInformationService.registerAiRelatedInformationProvider(type, provider));37}3839$unregisterAiRelatedInformationProvider(handle: number): void {40this._registrations.deleteAndDispose(handle);41}42}434445