@codingame/monaco-vscode-katex-common 26.1.2 → 26.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (17) hide show
  1. package/package.json +2 -2
  2. package/vscode/src/vs/workbench/contrib/interactive/browser/interactiveCommon.d.ts +7 -0
  3. package/vscode/src/vs/workbench/contrib/interactive/browser/interactiveCommon.js +11 -0
  4. package/vscode/src/vs/workbench/contrib/interactive/browser/replInputHintContentWidget.d.ts +20 -0
  5. package/vscode/src/vs/workbench/contrib/interactive/browser/replInputHintContentWidget.js +150 -0
  6. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.d.ts +22 -0
  7. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js +338 -0
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.d.ts +18 -0
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.js +58 -0
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.d.ts +75 -0
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.js +364 -0
  12. package/vscode/src/vs/workbench/contrib/replNotebook/browser/interactiveEditor.css +21 -0
  13. package/vscode/src/vs/workbench/contrib/replNotebook/browser/media/interactive.css +36 -0
  14. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditor.d.ts +110 -0
  15. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditor.js +692 -0
  16. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditorInput.d.ts +40 -0
  17. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditorInput.js +158 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-katex-common",
3
- "version": "26.1.2",
3
+ "version": "26.2.0",
4
4
  "private": false,
5
5
  "description": "VSCode public API plugged on the monaco editor - common package depending on katex",
6
6
  "keywords": [],
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "type": "module",
17
17
  "dependencies": {
18
- "@codingame/monaco-vscode-api": "26.1.2",
18
+ "@codingame/monaco-vscode-api": "26.2.0",
19
19
  "katex": "0.16.27",
20
20
  "marked": "14.0.0"
21
21
  },
@@ -0,0 +1,7 @@
1
+ import { RawContextKey } from "@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey";
2
+ export declare const INTERACTIVE_INPUT_CURSOR_BOUNDARY: RawContextKey<"top" | "none" | "bottom" | "both">;
3
+ export declare const ReplEditorSettings: {
4
+ interactiveWindowAlwaysScrollOnNewCell: string;
5
+ executeWithShiftEnter: string;
6
+ showExecutionHint: string;
7
+ };
@@ -0,0 +1,11 @@
1
+
2
+ import { RawContextKey } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey';
3
+
4
+ const INTERACTIVE_INPUT_CURSOR_BOUNDARY = ( new RawContextKey("interactiveInputCursorAtBoundary", "none"));
5
+ const ReplEditorSettings = {
6
+ interactiveWindowAlwaysScrollOnNewCell: "interactiveWindow.alwaysScrollOnNewCell",
7
+ executeWithShiftEnter: "interactiveWindow.executeWithShiftEnter",
8
+ showExecutionHint: "interactiveWindow.showExecutionHint"
9
+ };
10
+
11
+ export { INTERACTIVE_INPUT_CURSOR_BOUNDARY, ReplEditorSettings };
@@ -0,0 +1,20 @@
1
+ import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
2
+ import { ICodeEditor, IContentWidget, IContentWidgetPosition } from "@codingame/monaco-vscode-api/vscode/vs/editor/browser/editorBrowser";
3
+ import { IConfigurationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service";
4
+ import { IKeybindingService } from "@codingame/monaco-vscode-api/vscode/vs/platform/keybinding/common/keybinding.service";
5
+ export declare class ReplInputHintContentWidget extends Disposable implements IContentWidget {
6
+ private readonly editor;
7
+ private readonly configurationService;
8
+ private readonly keybindingService;
9
+ private static readonly ID;
10
+ private domNode;
11
+ private ariaLabel;
12
+ private label;
13
+ constructor(editor: ICodeEditor, configurationService: IConfigurationService, keybindingService: IKeybindingService);
14
+ getId(): string;
15
+ getPosition(): IContentWidgetPosition | null;
16
+ getDomNode(): HTMLElement;
17
+ private setHint;
18
+ private getKeybinding;
19
+ dispose(): void;
20
+ }
@@ -0,0 +1,150 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { $, addDisposableListener } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/dom';
4
+ import { status } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/aria/aria';
5
+ import { KeybindingLabel } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/keybindingLabel/keybindingLabel';
6
+ import { Event } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
7
+ import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
8
+ import { OS } from '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
9
+ import { ContentWidgetPositionPreference } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/editorBrowser';
10
+ import { EditorOption } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/config/editorOptions';
11
+ import { Position } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/position';
12
+ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
13
+ import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
14
+ import { IKeybindingService } from '@codingame/monaco-vscode-api/vscode/vs/platform/keybinding/common/keybinding.service';
15
+ import { AccessibilityVerbositySettingId } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
16
+ import { AccessibilityCommandId } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/accessibility/common/accessibilityCommands';
17
+ import { ReplEditorSettings } from './interactiveCommon.js';
18
+
19
+ var ReplInputHintContentWidget_1;
20
+ let ReplInputHintContentWidget = class ReplInputHintContentWidget extends Disposable {
21
+ static {
22
+ ReplInputHintContentWidget_1 = this;
23
+ }
24
+ static {
25
+ this.ID = "replInput.widget.emptyHint";
26
+ }
27
+ constructor(editor, configurationService, keybindingService) {
28
+ super();
29
+ this.editor = editor;
30
+ this.configurationService = configurationService;
31
+ this.keybindingService = keybindingService;
32
+ this.ariaLabel = "";
33
+ this._register(this.editor.onDidChangeConfiguration(e => {
34
+ if (this.domNode && e.hasChanged(EditorOption.fontInfo)) {
35
+ this.editor.applyFontInfo(this.domNode);
36
+ }
37
+ }));
38
+ const onDidFocusEditorText = Event.debounce(this.editor.onDidFocusEditorText, () => undefined, 500);
39
+ this._register(onDidFocusEditorText(() => {
40
+ if (this.editor.hasTextFocus() && this.ariaLabel && configurationService.getValue(AccessibilityVerbositySettingId.ReplEditor)) {
41
+ status(this.ariaLabel);
42
+ }
43
+ }));
44
+ this._register(configurationService.onDidChangeConfiguration(e => {
45
+ if (e.affectsConfiguration(ReplEditorSettings.executeWithShiftEnter)) {
46
+ this.setHint();
47
+ }
48
+ }));
49
+ this.editor.addContentWidget(this);
50
+ }
51
+ getId() {
52
+ return ReplInputHintContentWidget_1.ID;
53
+ }
54
+ getPosition() {
55
+ return {
56
+ position: {
57
+ lineNumber: 1,
58
+ column: 1
59
+ },
60
+ preference: [ContentWidgetPositionPreference.EXACT]
61
+ };
62
+ }
63
+ getDomNode() {
64
+ if (!this.domNode) {
65
+ this.domNode = $(".empty-editor-hint");
66
+ this.domNode.style.width = "max-content";
67
+ this.domNode.style.paddingLeft = "4px";
68
+ this.setHint();
69
+ this._register(addDisposableListener(this.domNode, "click", () => {
70
+ this.editor.focus();
71
+ }));
72
+ this.editor.applyFontInfo(this.domNode);
73
+ const lineHeight = this.editor.getLineHeightForPosition(( new Position(1, 1)));
74
+ this.domNode.style.lineHeight = lineHeight + "px";
75
+ }
76
+ return this.domNode;
77
+ }
78
+ setHint() {
79
+ if (!this.domNode) {
80
+ return;
81
+ }
82
+ while (this.domNode.firstChild) {
83
+ this.domNode.removeChild(this.domNode.firstChild);
84
+ }
85
+ const hintElement = $("div.empty-hint-text");
86
+ hintElement.style.cursor = "text";
87
+ hintElement.style.whiteSpace = "nowrap";
88
+ const keybinding = this.getKeybinding();
89
+ const keybindingHintLabel = keybinding?.getLabel();
90
+ if (keybinding && keybindingHintLabel) {
91
+ const actionPart = ( localize(8901, "Press {0} to execute. ", keybindingHintLabel));
92
+ const [before, after] = ( actionPart.split(keybindingHintLabel).map(fragment => {
93
+ const hintPart = $("span", undefined, fragment);
94
+ hintPart.style.fontStyle = "italic";
95
+ return hintPart;
96
+ }));
97
+ hintElement.appendChild(before);
98
+ if (this.label) {
99
+ this.label.dispose();
100
+ }
101
+ this.label = this._register(( new KeybindingLabel(hintElement, OS)));
102
+ this.label.set(keybinding);
103
+ this.label.element.style.width = "min-content";
104
+ this.label.element.style.display = "inline";
105
+ hintElement.appendChild(after);
106
+ this.domNode.append(hintElement);
107
+ const helpKeybinding = this.keybindingService.lookupKeybinding(AccessibilityCommandId.OpenAccessibilityHelp)?.getLabel();
108
+ const helpInfo = helpKeybinding ? ( localize(8902, "Use {0} for accessibility help. ", helpKeybinding)) : ( localize(8903, "Run the Open Accessibility Help command for more information. "));
109
+ this.ariaLabel = actionPart.concat(helpInfo, ( localize(
110
+ 8904,
111
+ " Toggle {0} in settings to disable this hint.",
112
+ AccessibilityVerbositySettingId.ReplEditor
113
+ )));
114
+ }
115
+ }
116
+ getKeybinding() {
117
+ const keybindings = this.keybindingService.lookupKeybindings("interactive.execute");
118
+ const shiftEnterConfig = this.configurationService.getValue(ReplEditorSettings.executeWithShiftEnter);
119
+ const hasEnterChord = (kb, modifier = "") => {
120
+ const chords = kb.getDispatchChords();
121
+ const chord = modifier + "Enter";
122
+ const chordAlt = modifier + "[Enter]";
123
+ return chords.length === 1 && (chords[0] === chord || chords[0] === chordAlt);
124
+ };
125
+ if (shiftEnterConfig) {
126
+ const keybinding = keybindings.find(kb => hasEnterChord(kb, "shift+"));
127
+ if (keybinding) {
128
+ return keybinding;
129
+ }
130
+ } else {
131
+ let keybinding = keybindings.find(kb => hasEnterChord(kb));
132
+ if (keybinding) {
133
+ return keybinding;
134
+ }
135
+ keybinding = this.keybindingService.lookupKeybindings("python.execInREPLEnter").find(kb => hasEnterChord(kb));
136
+ if (keybinding) {
137
+ return keybinding;
138
+ }
139
+ }
140
+ return keybindings?.[0];
141
+ }
142
+ dispose() {
143
+ super.dispose();
144
+ this.editor.removeContentWidget(this);
145
+ this.label?.dispose();
146
+ }
147
+ };
148
+ ReplInputHintContentWidget = ReplInputHintContentWidget_1 = ( __decorate([( __param(1, IConfigurationService)), ( __param(2, IKeybindingService))], ReplInputHintContentWidget));
149
+
150
+ export { ReplInputHintContentWidget };
@@ -0,0 +1,22 @@
1
+ import { Disposable, IDisposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
2
+ import { IInstantiationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
3
+ import { ICellViewModel, INotebookEditor, INotebookEditorContribution, INotebookViewModel } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser";
4
+ export declare function formatCellDuration(duration: number, showMilliseconds?: boolean): string;
5
+ export declare class NotebookStatusBarController extends Disposable {
6
+ private readonly _notebookEditor;
7
+ private readonly _itemFactory;
8
+ private readonly _visibleCells;
9
+ private readonly _observer;
10
+ constructor(_notebookEditor: INotebookEditor, _itemFactory: (vm: INotebookViewModel, cell: ICellViewModel) => IDisposable);
11
+ private _updateEverything;
12
+ private _updateVisibleCells;
13
+ dispose(): void;
14
+ }
15
+ export declare class ExecutionStateCellStatusBarContrib extends Disposable implements INotebookEditorContribution {
16
+ static id: string;
17
+ constructor(notebookEditor: INotebookEditor, instantiationService: IInstantiationService);
18
+ }
19
+ export declare class TimerCellStatusBarContrib extends Disposable implements INotebookEditorContribution {
20
+ static id: string;
21
+ constructor(notebookEditor: INotebookEditor, instantiationService: IInstantiationService);
22
+ }
@@ -0,0 +1,338 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { disposableTimeout, RunOnceScheduler } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
4
+ import { Disposable, dispose, MutableDisposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
5
+ import { language } from '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
6
+ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
7
+ import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
8
+ import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
9
+ import { themeColorFromId } from '@codingame/monaco-vscode-api/vscode/vs/platform/theme/common/themeService';
10
+ import { ThemeIcon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/themables';
11
+ import { NotebookVisibleCellObserver } from './notebookVisibleCellObserver.js';
12
+ import { registerNotebookContribution } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
13
+ import { cellStatusIconSuccess, cellStatusIconError } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookEditorWidget';
14
+ import { successStateIcon, errorStateIcon, pendingStateIcon, executingStateIcon } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookIcons';
15
+ import { NotebookCellExecutionState, CellStatusbarAlignment, NotebookSetting } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
16
+ import { NotebookExecutionType } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService';
17
+ import { INotebookExecutionStateService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService.service';
18
+ import { INotebookService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookService.service';
19
+
20
+ var ExecutionStateCellStatusBarItem_1, TimerCellStatusBarItem_1;
21
+ function formatCellDuration(duration, showMilliseconds = true) {
22
+ if (showMilliseconds && duration < 1000) {
23
+ return `${duration}ms`;
24
+ }
25
+ const minutes = Math.floor(duration / 1000 / 60);
26
+ const seconds = Math.floor(duration / 1000) % 60;
27
+ const tenths = Math.floor((duration % 1000) / 100);
28
+ if (minutes > 0) {
29
+ return `${minutes}m ${seconds}.${tenths}s`;
30
+ } else {
31
+ return `${seconds}.${tenths}s`;
32
+ }
33
+ }
34
+ class NotebookStatusBarController extends Disposable {
35
+ constructor(_notebookEditor, _itemFactory) {
36
+ super();
37
+ this._notebookEditor = _notebookEditor;
38
+ this._itemFactory = _itemFactory;
39
+ this._visibleCells = ( new Map());
40
+ this._observer = this._register(( new NotebookVisibleCellObserver(this._notebookEditor)));
41
+ this._register(this._observer.onDidChangeVisibleCells(this._updateVisibleCells, this));
42
+ this._updateEverything();
43
+ }
44
+ _updateEverything() {
45
+ this._visibleCells.forEach(dispose);
46
+ this._visibleCells.clear();
47
+ this._updateVisibleCells({
48
+ added: this._observer.visibleCells,
49
+ removed: []
50
+ });
51
+ }
52
+ _updateVisibleCells(e) {
53
+ const vm = this._notebookEditor.getViewModel();
54
+ if (!vm) {
55
+ return;
56
+ }
57
+ for (const oldCell of e.removed) {
58
+ this._visibleCells.get(oldCell.handle)?.dispose();
59
+ this._visibleCells.delete(oldCell.handle);
60
+ }
61
+ for (const newCell of e.added) {
62
+ this._visibleCells.set(newCell.handle, this._itemFactory(vm, newCell));
63
+ }
64
+ }
65
+ dispose() {
66
+ super.dispose();
67
+ this._visibleCells.forEach(dispose);
68
+ this._visibleCells.clear();
69
+ }
70
+ }
71
+ let ExecutionStateCellStatusBarContrib = class ExecutionStateCellStatusBarContrib extends Disposable {
72
+ static {
73
+ this.id = "workbench.notebook.statusBar.execState";
74
+ }
75
+ constructor(notebookEditor, instantiationService) {
76
+ super();
77
+ this._register(( new NotebookStatusBarController(
78
+ notebookEditor,
79
+ (vm, cell) => instantiationService.createInstance(ExecutionStateCellStatusBarItem, vm, cell)
80
+ )));
81
+ }
82
+ };
83
+ ExecutionStateCellStatusBarContrib = ( __decorate([( __param(1, IInstantiationService))], ExecutionStateCellStatusBarContrib));
84
+ registerNotebookContribution(ExecutionStateCellStatusBarContrib.id, ExecutionStateCellStatusBarContrib);
85
+ let ExecutionStateCellStatusBarItem = class ExecutionStateCellStatusBarItem extends Disposable {
86
+ static {
87
+ ExecutionStateCellStatusBarItem_1 = this;
88
+ }
89
+ static {
90
+ this.MIN_SPINNER_TIME = 500;
91
+ }
92
+ constructor(_notebookViewModel, _cell, _executionStateService) {
93
+ super();
94
+ this._notebookViewModel = _notebookViewModel;
95
+ this._cell = _cell;
96
+ this._executionStateService = _executionStateService;
97
+ this._currentItemIds = [];
98
+ this._clearExecutingStateTimer = this._register(( new MutableDisposable()));
99
+ this._update();
100
+ this._register(this._executionStateService.onDidChangeExecution(e => {
101
+ if (e.type === NotebookExecutionType.cell && e.affectsCell(this._cell.uri)) {
102
+ this._update();
103
+ }
104
+ }));
105
+ this._register(this._cell.model.onDidChangeInternalMetadata(() => this._update()));
106
+ }
107
+ async _update() {
108
+ const items = this._getItemsForCell();
109
+ if (Array.isArray(items)) {
110
+ this._currentItemIds = this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{
111
+ handle: this._cell.handle,
112
+ items
113
+ }]);
114
+ }
115
+ }
116
+ _getItemsForCell() {
117
+ const runState = this._executionStateService.getCellExecution(this._cell.uri);
118
+ if (runState?.state === NotebookCellExecutionState.Executing && typeof this._showedExecutingStateTime !== "number") {
119
+ this._showedExecutingStateTime = Date.now();
120
+ } else if (runState?.state !== NotebookCellExecutionState.Executing && typeof this._showedExecutingStateTime === "number") {
121
+ const timeUntilMin = ExecutionStateCellStatusBarItem_1.MIN_SPINNER_TIME - (Date.now() - this._showedExecutingStateTime);
122
+ if (timeUntilMin > 0) {
123
+ if (!this._clearExecutingStateTimer.value) {
124
+ this._clearExecutingStateTimer.value = disposableTimeout(() => {
125
+ this._showedExecutingStateTime = undefined;
126
+ this._clearExecutingStateTimer.clear();
127
+ this._update();
128
+ }, timeUntilMin);
129
+ }
130
+ return undefined;
131
+ } else {
132
+ this._showedExecutingStateTime = undefined;
133
+ }
134
+ }
135
+ const items = this._getItemForState(runState, this._cell.internalMetadata);
136
+ return items;
137
+ }
138
+ _getItemForState(runState, internalMetadata) {
139
+ const state = runState?.state;
140
+ const {
141
+ lastRunSuccess
142
+ } = internalMetadata;
143
+ if (!state && lastRunSuccess) {
144
+ return [{
145
+ text: `$(${successStateIcon.id})`,
146
+ color: themeColorFromId(cellStatusIconSuccess),
147
+ tooltip: ( localize(9753, "Success")),
148
+ alignment: CellStatusbarAlignment.Left,
149
+ priority: Number.MAX_SAFE_INTEGER
150
+ }];
151
+ } else if (!state && lastRunSuccess === false) {
152
+ return [{
153
+ text: `$(${errorStateIcon.id})`,
154
+ color: themeColorFromId(cellStatusIconError),
155
+ tooltip: ( localize(9754, "Failed")),
156
+ alignment: CellStatusbarAlignment.Left,
157
+ priority: Number.MAX_SAFE_INTEGER
158
+ }];
159
+ } else if (state === NotebookCellExecutionState.Pending || state === NotebookCellExecutionState.Unconfirmed) {
160
+ return [{
161
+ text: `$(${pendingStateIcon.id})`,
162
+ tooltip: ( localize(9755, "Pending")),
163
+ alignment: CellStatusbarAlignment.Left,
164
+ priority: Number.MAX_SAFE_INTEGER
165
+ }];
166
+ } else if (state === NotebookCellExecutionState.Executing) {
167
+ const icon = runState?.didPause ? executingStateIcon : ThemeIcon.modify(executingStateIcon, "spin");
168
+ return [{
169
+ text: `$(${icon.id})`,
170
+ tooltip: ( localize(9756, "Executing")),
171
+ alignment: CellStatusbarAlignment.Left,
172
+ priority: Number.MAX_SAFE_INTEGER
173
+ }];
174
+ }
175
+ return [];
176
+ }
177
+ dispose() {
178
+ super.dispose();
179
+ this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{
180
+ handle: this._cell.handle,
181
+ items: []
182
+ }]);
183
+ }
184
+ };
185
+ ExecutionStateCellStatusBarItem = ExecutionStateCellStatusBarItem_1 = ( __decorate([( __param(2, INotebookExecutionStateService))], ExecutionStateCellStatusBarItem));
186
+ let TimerCellStatusBarContrib = class TimerCellStatusBarContrib extends Disposable {
187
+ static {
188
+ this.id = "workbench.notebook.statusBar.execTimer";
189
+ }
190
+ constructor(notebookEditor, instantiationService) {
191
+ super();
192
+ this._register(( new NotebookStatusBarController(
193
+ notebookEditor,
194
+ (vm, cell) => instantiationService.createInstance(TimerCellStatusBarItem, vm, cell)
195
+ )));
196
+ }
197
+ };
198
+ TimerCellStatusBarContrib = ( __decorate([( __param(1, IInstantiationService))], TimerCellStatusBarContrib));
199
+ registerNotebookContribution(TimerCellStatusBarContrib.id, TimerCellStatusBarContrib);
200
+ const UPDATE_TIMER_GRACE_PERIOD = 200;
201
+ let TimerCellStatusBarItem = class TimerCellStatusBarItem extends Disposable {
202
+ static {
203
+ TimerCellStatusBarItem_1 = this;
204
+ }
205
+ static {
206
+ this.UPDATE_INTERVAL = 100;
207
+ }
208
+ constructor(
209
+ _notebookViewModel,
210
+ _cell,
211
+ _executionStateService,
212
+ _notebookService,
213
+ _configurationService
214
+ ) {
215
+ super();
216
+ this._notebookViewModel = _notebookViewModel;
217
+ this._cell = _cell;
218
+ this._executionStateService = _executionStateService;
219
+ this._notebookService = _notebookService;
220
+ this._configurationService = _configurationService;
221
+ this._currentItemIds = [];
222
+ this._isVerbose = this._configurationService.getValue(NotebookSetting.cellExecutionTimeVerbosity) === "verbose";
223
+ this._scheduler = this._register(( new RunOnceScheduler(() => this._update(), TimerCellStatusBarItem_1.UPDATE_INTERVAL)));
224
+ this._update();
225
+ this._register(this._cell.model.onDidChangeInternalMetadata(() => this._update()));
226
+ this._register(this._configurationService.onDidChangeConfiguration(e => {
227
+ if (e.affectsConfiguration(NotebookSetting.cellExecutionTimeVerbosity)) {
228
+ this._isVerbose = this._configurationService.getValue(NotebookSetting.cellExecutionTimeVerbosity) === "verbose";
229
+ this._update();
230
+ }
231
+ }));
232
+ }
233
+ async _update() {
234
+ let timerItem;
235
+ const runState = this._executionStateService.getCellExecution(this._cell.uri);
236
+ const state = runState?.state;
237
+ const startTime = this._cell.internalMetadata.runStartTime;
238
+ const adjustment = this._cell.internalMetadata.runStartTimeAdjustment ?? 0;
239
+ const endTime = this._cell.internalMetadata.runEndTime;
240
+ if (runState?.didPause) {
241
+ timerItem = undefined;
242
+ } else if (state === NotebookCellExecutionState.Executing) {
243
+ if (typeof startTime === "number") {
244
+ timerItem = this._getTimeItem(startTime, Date.now(), adjustment);
245
+ this._scheduler.schedule();
246
+ }
247
+ } else if (!state) {
248
+ if (typeof startTime === "number" && typeof endTime === "number") {
249
+ const timerDuration = Date.now() - startTime + adjustment;
250
+ const executionDuration = endTime - startTime;
251
+ const renderDuration = this._cell.internalMetadata.renderDuration ?? {};
252
+ timerItem = this._getTimeItem(startTime, endTime, undefined, {
253
+ timerDuration,
254
+ executionDuration,
255
+ renderDuration
256
+ });
257
+ }
258
+ }
259
+ const items = timerItem ? [timerItem] : [];
260
+ if (!items.length && !!runState) {
261
+ if (!this._deferredUpdate) {
262
+ this._deferredUpdate = disposableTimeout(() => {
263
+ this._deferredUpdate = undefined;
264
+ this._currentItemIds = this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{
265
+ handle: this._cell.handle,
266
+ items
267
+ }]);
268
+ }, UPDATE_TIMER_GRACE_PERIOD, this._store);
269
+ }
270
+ } else {
271
+ this._deferredUpdate?.dispose();
272
+ this._deferredUpdate = undefined;
273
+ this._currentItemIds = this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{
274
+ handle: this._cell.handle,
275
+ items
276
+ }]);
277
+ }
278
+ }
279
+ _getTimeItem(startTime, endTime, adjustment = 0, runtimeInformation) {
280
+ const duration = endTime - startTime + adjustment;
281
+ let tooltip;
282
+ const lastExecution = ( new Date(endTime)).toLocaleTimeString(language);
283
+ if (runtimeInformation) {
284
+ const {
285
+ renderDuration,
286
+ executionDuration,
287
+ timerDuration
288
+ } = runtimeInformation;
289
+ let renderTimes = "";
290
+ for (const key in renderDuration) {
291
+ const rendererInfo = this._notebookService.getRendererInfo(key);
292
+ const args = encodeURIComponent(JSON.stringify({
293
+ extensionId: rendererInfo?.extensionId.value ?? "",
294
+ issueBody: `Auto-generated text from notebook cell performance - Please add an explanation for the performance issue, including cell content if possible.\n` + `The duration for the renderer, ${rendererInfo?.displayName ?? key}, is slower than expected.\n` + `Execution Time: ${formatCellDuration(executionDuration)}\n` + `Renderer Duration: ${formatCellDuration(renderDuration[key])}\n`
295
+ }));
296
+ const renderIssueLink = (renderDuration[key] > 200 && executionDuration < 2000) || renderDuration[key] > 1000;
297
+ const linkText = rendererInfo?.displayName ?? key;
298
+ const rendererTitle = renderIssueLink ? `[${linkText}](command:workbench.action.openIssueReporter?${args})` : `**${linkText}**`;
299
+ renderTimes += `- ${rendererTitle} ${formatCellDuration(renderDuration[key])}\n`;
300
+ }
301
+ renderTimes += `\n*${( localize(9757, "Use the links above to file an issue using the issue reporter."))}*\n`;
302
+ tooltip = {
303
+ value: ( localize(
304
+ 9758,
305
+ "**Last Execution** {0}\n\n**Execution Time** {1}\n\n**Overhead Time** {2}\n\n**Render Times**\n\n{3}",
306
+ lastExecution,
307
+ formatCellDuration(executionDuration),
308
+ formatCellDuration(timerDuration - executionDuration),
309
+ renderTimes
310
+ )),
311
+ isTrusted: true
312
+ };
313
+ }
314
+ const executionText = this._isVerbose ? ( localize(
315
+ 9759,
316
+ "Last Execution: {0}, Duration: {1}",
317
+ lastExecution,
318
+ formatCellDuration(duration, false)
319
+ )) : formatCellDuration(duration, false);
320
+ return {
321
+ text: executionText,
322
+ alignment: CellStatusbarAlignment.Left,
323
+ priority: Number.MAX_SAFE_INTEGER - 5,
324
+ tooltip
325
+ };
326
+ }
327
+ dispose() {
328
+ super.dispose();
329
+ this._deferredUpdate?.dispose();
330
+ this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{
331
+ handle: this._cell.handle,
332
+ items: []
333
+ }]);
334
+ }
335
+ };
336
+ TimerCellStatusBarItem = TimerCellStatusBarItem_1 = ( __decorate([( __param(2, INotebookExecutionStateService)), ( __param(3, INotebookService)), ( __param(4, IConfigurationService))], TimerCellStatusBarItem));
337
+
338
+ export { ExecutionStateCellStatusBarContrib, NotebookStatusBarController, TimerCellStatusBarContrib, formatCellDuration };
@@ -0,0 +1,18 @@
1
+ import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
2
+ import { ICellViewModel, INotebookEditor } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser";
3
+ export interface ICellVisibilityChangeEvent {
4
+ added: ICellViewModel[];
5
+ removed: ICellViewModel[];
6
+ }
7
+ export declare class NotebookVisibleCellObserver extends Disposable {
8
+ private readonly _notebookEditor;
9
+ private readonly _onDidChangeVisibleCells;
10
+ readonly onDidChangeVisibleCells: import("@codingame/monaco-vscode-api/vscode/vs/base/common/event").Event<ICellVisibilityChangeEvent>;
11
+ private readonly _viewModelDisposables;
12
+ private _visibleCells;
13
+ get visibleCells(): ICellViewModel[];
14
+ constructor(_notebookEditor: INotebookEditor);
15
+ private _onModelChange;
16
+ protected updateEverything(): void;
17
+ private _updateVisibleCells;
18
+ }
@@ -0,0 +1,58 @@
1
+
2
+ import { diffSets } from '@codingame/monaco-vscode-api/vscode/vs/base/common/collections';
3
+ import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
4
+ import { Disposable, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
5
+ import { isDefined } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
6
+ import { cellRangesToIndexes } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookRange';
7
+
8
+ class NotebookVisibleCellObserver extends Disposable {
9
+ get visibleCells() {
10
+ return this._visibleCells;
11
+ }
12
+ constructor(_notebookEditor) {
13
+ super();
14
+ this._notebookEditor = _notebookEditor;
15
+ this._onDidChangeVisibleCells = this._register(( new Emitter()));
16
+ this.onDidChangeVisibleCells = this._onDidChangeVisibleCells.event;
17
+ this._viewModelDisposables = this._register(( new DisposableStore()));
18
+ this._visibleCells = [];
19
+ this._register(
20
+ this._notebookEditor.onDidChangeVisibleRanges(this._updateVisibleCells, this)
21
+ );
22
+ this._register(this._notebookEditor.onDidChangeModel(this._onModelChange, this));
23
+ this._updateVisibleCells();
24
+ }
25
+ _onModelChange() {
26
+ this._viewModelDisposables.clear();
27
+ if (this._notebookEditor.hasModel()) {
28
+ this._viewModelDisposables.add(this._notebookEditor.onDidChangeViewCells(() => this.updateEverything()));
29
+ }
30
+ this.updateEverything();
31
+ }
32
+ updateEverything() {
33
+ this._onDidChangeVisibleCells.fire({
34
+ added: [],
35
+ removed: Array.from(this._visibleCells)
36
+ });
37
+ this._visibleCells = [];
38
+ this._updateVisibleCells();
39
+ }
40
+ _updateVisibleCells() {
41
+ if (!this._notebookEditor.hasModel()) {
42
+ return;
43
+ }
44
+ const newVisibleCells = ( cellRangesToIndexes(this._notebookEditor.visibleRanges).map(index => this._notebookEditor.cellAt(index))).filter(isDefined);
45
+ const newVisibleHandles = ( new Set(( newVisibleCells.map(cell => cell.handle))));
46
+ const oldVisibleHandles = ( new Set(( this._visibleCells.map(cell => cell.handle))));
47
+ const diff = diffSets(oldVisibleHandles, newVisibleHandles);
48
+ const added = ( diff.added.map(handle => this._notebookEditor.getCellByHandle(handle))).filter(isDefined);
49
+ const removed = ( diff.removed.map(handle => this._notebookEditor.getCellByHandle(handle))).filter(isDefined);
50
+ this._visibleCells = newVisibleCells;
51
+ this._onDidChangeVisibleCells.fire({
52
+ added,
53
+ removed
54
+ });
55
+ }
56
+ }
57
+
58
+ export { NotebookVisibleCellObserver };