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
3296 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 { IEditorService } from '../../../services/editor/common/editorService.js';
15
import { ILanguageStatusService } from '../../../services/languageStatus/common/languageStatusService.js';
16
17
export class InlineCompletionLanguageStatusBarContribution extends Disposable implements IWorkbenchContribution {
18
public static readonly hot = createHotClass(InlineCompletionLanguageStatusBarContribution);
19
20
public static Id = 'vs.contrib.inlineCompletionLanguageStatusBarContribution';
21
public static readonly languageStatusBarDisposables = new Set<DisposableStore>();
22
23
private _activeEditor;
24
private _state;
25
26
constructor(
27
@ILanguageStatusService private readonly _languageStatusService: ILanguageStatusService,
28
@IEditorService private readonly _editorService: IEditorService,
29
) {
30
super();
31
32
33
this._activeEditor = observableFromEvent(this, _editorService.onDidActiveEditorChange, () => this._editorService.activeTextEditorControl);
34
this._state = derived(this, reader => {
35
const editor = this._activeEditor.read(reader);
36
if (!editor || !isCodeEditor(editor)) {
37
return undefined;
38
}
39
40
const c = InlineCompletionsController.get(editor);
41
const model = c?.model.read(reader);
42
if (!model) {
43
return undefined;
44
}
45
46
return {
47
model,
48
status: debouncedObservable(model.status, 300),
49
};
50
});
51
52
this._register(autorunWithStore((reader, store) => {
53
const state = this._state.read(reader);
54
if (!state) {
55
return;
56
}
57
58
const status = state.status.read(reader);
59
60
const statusMap: Record<typeof status, { shortLabel: string; label: string; loading: boolean }> = {
61
loading: { shortLabel: '', label: localize('inlineSuggestionLoading', "Loading..."), loading: true, },
62
ghostText: { shortLabel: '$(lightbulb)', label: '$(copilot) ' + localize('inlineCompletionAvailable', "Inline completion available"), loading: false, },
63
inlineEdit: { shortLabel: '$(lightbulb-sparkle)', label: '$(copilot) ' + localize('inlineEditAvailable', "Inline edit available"), loading: false, },
64
noSuggestion: { shortLabel: '$(circle-slash)', label: '$(copilot) ' + localize('noInlineSuggestionAvailable', "No inline suggestion available"), loading: false, },
65
};
66
67
store.add(this._languageStatusService.addStatus({
68
accessibilityInfo: undefined,
69
busy: statusMap[status].loading,
70
command: undefined,
71
detail: localize('inlineSuggestionsSmall', "Inline suggestions"),
72
id: 'inlineSuggestions',
73
label: { value: statusMap[status].label, shortValue: statusMap[status].shortLabel },
74
name: localize('inlineSuggestions', "Inline Suggestions"),
75
selector: { pattern: state.model.textModel.uri.fsPath },
76
severity: Severity.Info,
77
source: 'inlineSuggestions',
78
}));
79
}));
80
}
81
}
82
83