Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/inlineCompletions/browser/inlineCompletionLanguageStatusBarContribution.ts
5257 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { createHotClass } from '../../../../base/common/hotReloadHelpers.js';
7
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
8
import { autorunWithStore, debouncedObservable, derived, observableFromEvent } from '../../../../base/common/observable.js';
9
import Severity from '../../../../base/common/severity.js';
10
import { isCodeEditor } from '../../../../editor/browser/editorBrowser.js';
11
import { InlineCompletionsController } from '../../../../editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.js';
12
import { localize } from '../../../../nls.js';
13
import { IWorkbenchContribution } from '../../../common/contributions.js';
14
import { IChatEntitlementService } from '../../../services/chat/common/chatEntitlementService.js';
15
import { IEditorService } from '../../../services/editor/common/editorService.js';
16
import { ILanguageStatusService } from '../../../services/languageStatus/common/languageStatusService.js';
17
18
export class InlineCompletionLanguageStatusBarContribution extends Disposable implements IWorkbenchContribution {
19
public static readonly hot = createHotClass(this);
20
21
public static Id = 'vs.contrib.inlineCompletionLanguageStatusBarContribution';
22
public static readonly languageStatusBarDisposables = new Set<DisposableStore>();
23
24
private _activeEditor;
25
private _state;
26
private _sentiment;
27
28
constructor(
29
@ILanguageStatusService private readonly _languageStatusService: ILanguageStatusService,
30
@IEditorService private readonly _editorService: IEditorService,
31
@IChatEntitlementService private readonly _chatEntitlementService: IChatEntitlementService,
32
) {
33
super();
34
35
36
this._activeEditor = observableFromEvent(this, _editorService.onDidActiveEditorChange, () => this._editorService.activeTextEditorControl);
37
this._sentiment = this._chatEntitlementService.sentimentObs;
38
this._state = derived(this, reader => {
39
const editor = this._activeEditor.read(reader);
40
if (!editor || !isCodeEditor(editor)) {
41
return undefined;
42
}
43
44
const c = InlineCompletionsController.get(editor);
45
const model = c?.model.read(reader);
46
if (!model) {
47
return undefined;
48
}
49
50
return {
51
model,
52
status: debouncedObservable(model.status, 300),
53
};
54
});
55
56
this._register(autorunWithStore((reader, store) => {
57
// Do not show the Copilot icon in the language status when AI features are disabled
58
const sentiment = this._sentiment.read(reader);
59
if (sentiment.hidden) {
60
return;
61
}
62
63
const state = this._state.read(reader);
64
if (!state) {
65
return;
66
}
67
68
const status = state.status.read(reader);
69
70
const statusMap: Record<typeof status, { shortLabel: string; label: string; loading: boolean }> = {
71
loading: { shortLabel: '', label: localize('inlineSuggestionLoading', "Loading..."), loading: true, },
72
ghostText: { shortLabel: '$(lightbulb)', label: '$(copilot) ' + localize('inlineCompletionAvailable', "Inline completion available"), loading: false, },
73
inlineEdit: { shortLabel: '$(lightbulb-sparkle)', label: '$(copilot) ' + localize('inlineEditAvailable', "Inline edit available"), loading: false, },
74
noSuggestion: { shortLabel: '$(circle-slash)', label: '$(copilot) ' + localize('noInlineSuggestionAvailable', "No inline suggestion available"), loading: false, },
75
};
76
77
store.add(this._languageStatusService.addStatus({
78
accessibilityInfo: undefined,
79
busy: statusMap[status].loading,
80
command: undefined,
81
detail: localize('inlineSuggestionsSmall', "Inline suggestions"),
82
id: 'inlineSuggestions',
83
label: { value: statusMap[status].label, shortValue: statusMap[status].shortLabel },
84
name: localize('inlineSuggestions', "Inline Suggestions"),
85
selector: { pattern: state.model.textModel.uri.fsPath },
86
severity: Severity.Info,
87
source: 'inlineSuggestions',
88
}));
89
}));
90
}
91
}
92
93