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