Path: blob/main/src/vs/workbench/contrib/chat/browser/enablementStatusWidget.ts
13401 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 { reset } from '../../../../base/browser/dom.js';6import { Codicon } from '../../../../base/common/codicons.js';7import { MarkdownString } from '../../../../base/common/htmlContent.js';8import { Disposable, MutableDisposable } from '../../../../base/common/lifecycle.js';9import { IObservable, autorun } from '../../../../base/common/observable.js';10import { localize } from '../../../../nls.js';11import { IMarkdownRendererService } from '../../../../platform/markdown/browser/markdownRenderer.js';12import { ContributionEnablementState } from '../common/enablement.js';1314/**15* A small reusable widget that renders an enablement status message inside16* a `.status` container, matching the style used by the extension and MCP17* server editors. The message is shown only when the contribution is18* disabled and is rendered as markdown with a theme icon prefix.19*/20export class EnablementStatusWidget extends Disposable {2122private readonly _renderDisposables = this._register(new MutableDisposable());2324constructor(25private readonly _container: HTMLElement,26enablement: IObservable<ContributionEnablementState>,27private readonly _labels: {28disabledProfile: string;29disabledWorkspace: string;30},31@IMarkdownRendererService private readonly _markdownRendererService: IMarkdownRendererService,32) {33super();34this._register(autorun(reader => {35this._render(enablement.read(reader));36}));37}3839private _render(state: ContributionEnablementState): void {40reset(this._container);41this._renderDisposables.value = undefined;4243let message: string | undefined;44if (state === ContributionEnablementState.DisabledProfile) {45message = this._labels.disabledProfile;46} else if (state === ContributionEnablementState.DisabledWorkspace) {47message = this._labels.disabledWorkspace;48}4950if (!message) {51return;52}5354const markdown = new MarkdownString('', { isTrusted: true, supportThemeIcons: true });55markdown.appendMarkdown(`$(${Codicon.info.id}) `);56markdown.appendText(message);57const rendered = this._markdownRendererService.render(markdown);58this._renderDisposables.value = rendered;59this._container.appendChild(rendered.element);60}61}6263/** Default labels for plugin enablement status. */64export const pluginEnablementLabels = {65disabledProfile: localize('pluginDisabled', "This plugin is disabled."),66disabledWorkspace: localize('pluginDisabledWorkspace', "This plugin is disabled for this workspace."),67};6869/** Default labels for MCP server enablement status. */70export const mcpServerEnablementLabels = {71disabledProfile: localize('mcpServerDisabled', "This MCP server is disabled."),72disabledWorkspace: localize('mcpServerDisabledWorkspace', "This MCP server is disabled for this workspace."),73};747576