Path: blob/main/src/vs/workbench/contrib/inlineCompletions/browser/inlineCompletionLanguageStatusBarContribution.ts
5257 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 { createHotClass } from '../../../../base/common/hotReloadHelpers.js';6import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';7import { autorunWithStore, debouncedObservable, derived, observableFromEvent } from '../../../../base/common/observable.js';8import Severity from '../../../../base/common/severity.js';9import { isCodeEditor } from '../../../../editor/browser/editorBrowser.js';10import { InlineCompletionsController } from '../../../../editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.js';11import { localize } from '../../../../nls.js';12import { IWorkbenchContribution } from '../../../common/contributions.js';13import { IChatEntitlementService } from '../../../services/chat/common/chatEntitlementService.js';14import { IEditorService } from '../../../services/editor/common/editorService.js';15import { ILanguageStatusService } from '../../../services/languageStatus/common/languageStatusService.js';1617export class InlineCompletionLanguageStatusBarContribution extends Disposable implements IWorkbenchContribution {18public static readonly hot = createHotClass(this);1920public static Id = 'vs.contrib.inlineCompletionLanguageStatusBarContribution';21public static readonly languageStatusBarDisposables = new Set<DisposableStore>();2223private _activeEditor;24private _state;25private _sentiment;2627constructor(28@ILanguageStatusService private readonly _languageStatusService: ILanguageStatusService,29@IEditorService private readonly _editorService: IEditorService,30@IChatEntitlementService private readonly _chatEntitlementService: IChatEntitlementService,31) {32super();333435this._activeEditor = observableFromEvent(this, _editorService.onDidActiveEditorChange, () => this._editorService.activeTextEditorControl);36this._sentiment = this._chatEntitlementService.sentimentObs;37this._state = derived(this, reader => {38const editor = this._activeEditor.read(reader);39if (!editor || !isCodeEditor(editor)) {40return undefined;41}4243const c = InlineCompletionsController.get(editor);44const model = c?.model.read(reader);45if (!model) {46return undefined;47}4849return {50model,51status: debouncedObservable(model.status, 300),52};53});5455this._register(autorunWithStore((reader, store) => {56// Do not show the Copilot icon in the language status when AI features are disabled57const sentiment = this._sentiment.read(reader);58if (sentiment.hidden) {59return;60}6162const state = this._state.read(reader);63if (!state) {64return;65}6667const status = state.status.read(reader);6869const statusMap: Record<typeof status, { shortLabel: string; label: string; loading: boolean }> = {70loading: { shortLabel: '', label: localize('inlineSuggestionLoading', "Loading..."), loading: true, },71ghostText: { shortLabel: '$(lightbulb)', label: '$(copilot) ' + localize('inlineCompletionAvailable', "Inline completion available"), loading: false, },72inlineEdit: { shortLabel: '$(lightbulb-sparkle)', label: '$(copilot) ' + localize('inlineEditAvailable', "Inline edit available"), loading: false, },73noSuggestion: { shortLabel: '$(circle-slash)', label: '$(copilot) ' + localize('noInlineSuggestionAvailable', "No inline suggestion available"), loading: false, },74};7576store.add(this._languageStatusService.addStatus({77accessibilityInfo: undefined,78busy: statusMap[status].loading,79command: undefined,80detail: localize('inlineSuggestionsSmall', "Inline suggestions"),81id: 'inlineSuggestions',82label: { value: statusMap[status].label, shortValue: statusMap[status].shortLabel },83name: localize('inlineSuggestions', "Inline Suggestions"),84selector: { pattern: state.model.textModel.uri.fsPath },85severity: Severity.Info,86source: 'inlineSuggestions',87}));88}));89}90}919293