Path: blob/main/src/vs/workbench/contrib/inlineCompletions/browser/inlineCompletionLanguageStatusBarContribution.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 { 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 { IEditorService } from '../../../services/editor/common/editorService.js';14import { ILanguageStatusService } from '../../../services/languageStatus/common/languageStatusService.js';1516export class InlineCompletionLanguageStatusBarContribution extends Disposable implements IWorkbenchContribution {17public static readonly hot = createHotClass(InlineCompletionLanguageStatusBarContribution);1819public static Id = 'vs.contrib.inlineCompletionLanguageStatusBarContribution';20public static readonly languageStatusBarDisposables = new Set<DisposableStore>();2122private _activeEditor;23private _state;2425constructor(26@ILanguageStatusService private readonly _languageStatusService: ILanguageStatusService,27@IEditorService private readonly _editorService: IEditorService,28) {29super();303132this._activeEditor = observableFromEvent(this, _editorService.onDidActiveEditorChange, () => this._editorService.activeTextEditorControl);33this._state = derived(this, reader => {34const editor = this._activeEditor.read(reader);35if (!editor || !isCodeEditor(editor)) {36return undefined;37}3839const c = InlineCompletionsController.get(editor);40const model = c?.model.read(reader);41if (!model) {42return undefined;43}4445return {46model,47status: debouncedObservable(model.status, 300),48};49});5051this._register(autorunWithStore((reader, store) => {52const state = this._state.read(reader);53if (!state) {54return;55}5657const status = state.status.read(reader);5859const statusMap: Record<typeof status, { shortLabel: string; label: string; loading: boolean }> = {60loading: { shortLabel: '', label: localize('inlineSuggestionLoading', "Loading..."), loading: true, },61ghostText: { shortLabel: '$(lightbulb)', label: '$(copilot) ' + localize('inlineCompletionAvailable', "Inline completion available"), loading: false, },62inlineEdit: { shortLabel: '$(lightbulb-sparkle)', label: '$(copilot) ' + localize('inlineEditAvailable', "Inline edit available"), loading: false, },63noSuggestion: { shortLabel: '$(circle-slash)', label: '$(copilot) ' + localize('noInlineSuggestionAvailable', "No inline suggestion available"), loading: false, },64};6566store.add(this._languageStatusService.addStatus({67accessibilityInfo: undefined,68busy: statusMap[status].loading,69command: undefined,70detail: localize('inlineSuggestionsSmall', "Inline suggestions"),71id: 'inlineSuggestions',72label: { value: statusMap[status].label, shortValue: statusMap[status].shortLabel },73name: localize('inlineSuggestions', "Inline Suggestions"),74selector: { pattern: state.model.textModel.uri.fsPath },75severity: Severity.Info,76source: 'inlineSuggestions',77}));78}));79}80}818283