Path: blob/main/src/vs/workbench/api/common/extHostChatStatus.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 type * as vscode from 'vscode';6import * as extHostProtocol from './extHost.protocol.js';7import { ExtensionIdentifier, IExtensionDescription } from '../../../platform/extensions/common/extensions.js';89export class ExtHostChatStatus {1011private readonly _proxy: extHostProtocol.MainThreadChatStatusShape;1213private readonly _items = new Map<string, vscode.ChatStatusItem>();1415constructor(16mainContext: extHostProtocol.IMainContext17) {18this._proxy = mainContext.getProxy(extHostProtocol.MainContext.MainThreadChatStatus);19}2021createChatStatusItem(extension: IExtensionDescription, id: string): vscode.ChatStatusItem {22const internalId = asChatItemIdentifier(extension.identifier, id);23if (this._items.has(internalId)) {24throw new Error(`Chat status item '${id}' already exists`);25}2627const state: extHostProtocol.ChatStatusItemDto = {28id: internalId,29title: '',30description: '',31detail: '',32};3334let disposed = false;35let visible = false;36const syncState = () => {37if (disposed) {38throw new Error('Chat status item is disposed');39}4041if (!visible) {42return;43}4445this._proxy.$setEntry(id, state);46};4748const item = Object.freeze<vscode.ChatStatusItem>({49id: id,5051get title(): string | { label: string; link: string } {52return state.title;53},54set title(value: string | { label: string; link: string }) {55state.title = value;56syncState();57},5859get description(): string {60return state.description;61},62set description(value: string) {63state.description = value;64syncState();65},6667get detail(): string | undefined {68return state.detail;69},70set detail(value: string | undefined) {71state.detail = value;72syncState();73},7475show: () => {76visible = true;77syncState();78},79hide: () => {80visible = false;81this._proxy.$disposeEntry(id);82},83dispose: () => {84disposed = true;85this._proxy.$disposeEntry(id);86this._items.delete(internalId);87},88});8990this._items.set(internalId, item);91return item;92}93}9495function asChatItemIdentifier(extension: ExtensionIdentifier, id: string): string {96return `${ExtensionIdentifier.toKey(extension)}.${id}`;97}9899100101