@theia/notebook 1.41.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.
- package/README.md +30 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts +27 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-actions-contribution.js +172 -0
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +30 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +200 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -0
- package/lib/browser/contributions/notebook-color-contribution.d.ts +6 -0
- package/lib/browser/contributions/notebook-color-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-color-contribution.js +252 -0
- package/lib/browser/contributions/notebook-color-contribution.js.map +1 -0
- package/lib/browser/contributions/notebook-context-keys.d.ts +38 -0
- package/lib/browser/contributions/notebook-context-keys.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-context-keys.js +95 -0
- package/lib/browser/contributions/notebook-context-keys.js.map +1 -0
- package/lib/browser/index.d.ts +11 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +38 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/notebook-cell-resource-resolver.d.ts +20 -0
- package/lib/browser/notebook-cell-resource-resolver.d.ts.map +1 -0
- package/lib/browser/notebook-cell-resource-resolver.js +75 -0
- package/lib/browser/notebook-cell-resource-resolver.js.map +1 -0
- package/lib/browser/notebook-editor-widget-factory.d.ts +17 -0
- package/lib/browser/notebook-editor-widget-factory.d.ts.map +1 -0
- package/lib/browser/notebook-editor-widget-factory.js +78 -0
- package/lib/browser/notebook-editor-widget-factory.js.map +1 -0
- package/lib/browser/notebook-editor-widget.d.ts +49 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -0
- package/lib/browser/notebook-editor-widget.js +150 -0
- package/lib/browser/notebook-editor-widget.js.map +1 -0
- package/lib/browser/notebook-frontend-module.d.ts +5 -0
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -0
- package/lib/browser/notebook-frontend-module.js +81 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -0
- package/lib/browser/notebook-open-handler.d.ts +18 -0
- package/lib/browser/notebook-open-handler.d.ts.map +1 -0
- package/lib/browser/notebook-open-handler.js +94 -0
- package/lib/browser/notebook-open-handler.js.map +1 -0
- package/lib/browser/notebook-renderer-registry.d.ts +17 -0
- package/lib/browser/notebook-renderer-registry.d.ts.map +1 -0
- package/lib/browser/notebook-renderer-registry.js +63 -0
- package/lib/browser/notebook-renderer-registry.js.map +1 -0
- package/lib/browser/notebook-type-registry.d.ts +7 -0
- package/lib/browser/notebook-type-registry.d.ts.map +1 -0
- package/lib/browser/notebook-type-registry.js +42 -0
- package/lib/browser/notebook-type-registry.js.map +1 -0
- package/lib/browser/renderers/cell-output-webview.d.ts +12 -0
- package/lib/browser/renderers/cell-output-webview.d.ts.map +1 -0
- package/lib/browser/renderers/cell-output-webview.js +20 -0
- package/lib/browser/renderers/cell-output-webview.js.map +1 -0
- package/lib/browser/service/notebook-cell-context-manager.d.ts +16 -0
- package/lib/browser/service/notebook-cell-context-manager.d.ts.map +1 -0
- package/lib/browser/service/notebook-cell-context-manager.js +83 -0
- package/lib/browser/service/notebook-cell-context-manager.js.map +1 -0
- package/lib/browser/service/notebook-editor-service.d.ts +22 -0
- package/lib/browser/service/notebook-editor-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-editor-service.js +95 -0
- package/lib/browser/service/notebook-editor-service.js.map +1 -0
- package/lib/browser/service/notebook-execution-service.d.ts +25 -0
- package/lib/browser/service/notebook-execution-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-execution-service.js +140 -0
- package/lib/browser/service/notebook-execution-service.js.map +1 -0
- package/lib/browser/service/notebook-execution-state-service.d.ts +94 -0
- package/lib/browser/service/notebook-execution-state-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-execution-state-service.js +250 -0
- package/lib/browser/service/notebook-execution-state-service.js.map +1 -0
- package/lib/browser/service/notebook-kernel-history-service.d.ts +23 -0
- package/lib/browser/service/notebook-kernel-history-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-kernel-history-service.js +109 -0
- package/lib/browser/service/notebook-kernel-history-service.js.map +1 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.d.ts +65 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.js +430 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.js.map +1 -0
- package/lib/browser/service/notebook-kernel-service.d.ts +112 -0
- package/lib/browser/service/notebook-kernel-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-kernel-service.js +274 -0
- package/lib/browser/service/notebook-kernel-service.js.map +1 -0
- package/lib/browser/service/notebook-model-resolver-service.d.ts +26 -0
- package/lib/browser/service/notebook-model-resolver-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-model-resolver-service.js +139 -0
- package/lib/browser/service/notebook-model-resolver-service.js.map +1 -0
- package/lib/browser/service/notebook-renderer-messaging-service.d.ts +30 -0
- package/lib/browser/service/notebook-renderer-messaging-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-renderer-messaging-service.js +94 -0
- package/lib/browser/service/notebook-renderer-messaging-service.js.map +1 -0
- package/lib/browser/service/notebook-service.d.ts +64 -0
- package/lib/browser/service/notebook-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-service.js +162 -0
- package/lib/browser/service/notebook-service.js.map +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts +26 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-editor.js +79 -0
- package/lib/browser/view/notebook-cell-editor.js.map +1 -0
- package/lib/browser/view/notebook-cell-list-view.d.ts +43 -0
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-list-view.js +111 -0
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.d.ts +25 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.js +93 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.js.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar.d.ts +25 -0
- package/lib/browser/view/notebook-cell-toolbar.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar.js +50 -0
- package/lib/browser/view/notebook-cell-toolbar.js.map +1 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts +47 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -0
- package/lib/browser/view/notebook-code-cell-view.js +166 -0
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -0
- package/lib/browser/view/notebook-main-toolbar.d.ts +31 -0
- package/lib/browser/view/notebook-main-toolbar.d.ts.map +1 -0
- package/lib/browser/view/notebook-main-toolbar.js +118 -0
- package/lib/browser/view/notebook-main-toolbar.js.map +1 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts +12 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -0
- package/lib/browser/view/notebook-markdown-cell-view.js +70 -0
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -0
- package/lib/browser/view-model/notebook-cell-model.d.ts +74 -0
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -0
- package/lib/browser/view-model/notebook-cell-model.js +226 -0
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -0
- package/lib/browser/view-model/notebook-cell-output-model.d.ts +19 -0
- package/lib/browser/view-model/notebook-cell-output-model.d.ts.map +1 -0
- package/lib/browser/view-model/notebook-cell-output-model.js +61 -0
- package/lib/browser/view-model/notebook-cell-output-model.js.map +1 -0
- package/lib/browser/view-model/notebook-model.d.ts +59 -0
- package/lib/browser/view-model/notebook-model.d.ts.map +1 -0
- package/lib/browser/view-model/notebook-model.js +315 -0
- package/lib/browser/view-model/notebook-model.js.map +1 -0
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +30 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/notebook-common.d.ts +344 -0
- package/lib/common/notebook-common.d.ts.map +1 -0
- package/lib/common/notebook-common.js +112 -0
- package/lib/common/notebook-common.js.map +1 -0
- package/lib/common/notebook-protocol.d.ts +21 -0
- package/lib/common/notebook-protocol.d.ts.map +1 -0
- package/lib/common/notebook-protocol.js +18 -0
- package/lib/common/notebook-protocol.js.map +1 -0
- package/lib/common/notebook-range.d.ts +14 -0
- package/lib/common/notebook-range.d.ts.map +1 -0
- package/lib/common/notebook-range.js +18 -0
- package/lib/common/notebook-range.js.map +1 -0
- package/package.json +52 -0
- package/src/browser/contributions/notebook-actions-contribution.ts +171 -0
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +204 -0
- package/src/browser/contributions/notebook-color-contribution.ts +268 -0
- package/src/browser/contributions/notebook-context-keys.ts +99 -0
- package/src/browser/index.ts +26 -0
- package/src/browser/notebook-cell-resource-resolver.ts +79 -0
- package/src/browser/notebook-editor-widget-factory.ts +70 -0
- package/src/browser/notebook-editor-widget.tsx +157 -0
- package/src/browser/notebook-frontend-module.ts +95 -0
- package/src/browser/notebook-open-handler.ts +87 -0
- package/src/browser/notebook-renderer-registry.ts +62 -0
- package/src/browser/notebook-type-registry.ts +30 -0
- package/src/browser/renderers/cell-output-webview.ts +32 -0
- package/src/browser/service/notebook-cell-context-manager.ts +70 -0
- package/src/browser/service/notebook-editor-service.ts +86 -0
- package/src/browser/service/notebook-execution-service.ts +139 -0
- package/src/browser/service/notebook-execution-state-service.ts +322 -0
- package/src/browser/service/notebook-kernel-history-service.ts +109 -0
- package/src/browser/service/notebook-kernel-quick-pick-service.ts +494 -0
- package/src/browser/service/notebook-kernel-service.ts +357 -0
- package/src/browser/service/notebook-model-resolver-service.ts +141 -0
- package/src/browser/service/notebook-renderer-messaging-service.ts +111 -0
- package/src/browser/service/notebook-service.ts +178 -0
- package/src/browser/style/index.css +236 -0
- package/src/browser/view/notebook-cell-editor.tsx +97 -0
- package/src/browser/view/notebook-cell-list-view.tsx +171 -0
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +91 -0
- package/src/browser/view/notebook-cell-toolbar.tsx +70 -0
- package/src/browser/view/notebook-code-cell-view.tsx +190 -0
- package/src/browser/view/notebook-main-toolbar.tsx +115 -0
- package/src/browser/view/notebook-markdown-cell-view.tsx +73 -0
- package/src/browser/view-model/notebook-cell-model.ts +271 -0
- package/src/browser/view-model/notebook-cell-output-model.ts +69 -0
- package/src/browser/view-model/notebook-model.ts +372 -0
- package/src/common/index.ts +18 -0
- package/src/common/notebook-common.ts +462 -0
- package/src/common/notebook-protocol.ts +35 -0
- package/src/common/notebook-range.ts +30 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
/*---------------------------------------------------------------------------------------------
|
|
17
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
18
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
19
|
+
*--------------------------------------------------------------------------------------------*/
|
|
20
|
+
|
|
21
|
+
import { Disposable, Emitter, URI } from '@theia/core';
|
|
22
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
23
|
+
import { NotebookService } from './notebook-service';
|
|
24
|
+
import {
|
|
25
|
+
CellEditType, CellExecuteOutputEdit, CellExecuteOutputItemEdit, CellExecutionUpdateType,
|
|
26
|
+
CellUri, CellPartialInternalMetadataEditByHandle, NotebookCellExecutionState, CellEditOperation, NotebookCellInternalMetadata
|
|
27
|
+
} from '../../common';
|
|
28
|
+
import { NotebookModel } from '../view-model/notebook-model';
|
|
29
|
+
import { v4 } from 'uuid';
|
|
30
|
+
|
|
31
|
+
export type CellExecuteUpdate = CellExecuteOutputEdit | CellExecuteOutputItemEdit | CellExecutionStateUpdate;
|
|
32
|
+
|
|
33
|
+
export interface CellExecutionComplete {
|
|
34
|
+
runEndTime?: number;
|
|
35
|
+
lastRunSuccess?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CellExecutionStateUpdate {
|
|
39
|
+
editType: CellExecutionUpdateType.ExecutionState;
|
|
40
|
+
executionOrder?: number;
|
|
41
|
+
runStartTime?: number;
|
|
42
|
+
didPause?: boolean;
|
|
43
|
+
isPaused?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ICellExecutionStateUpdate {
|
|
47
|
+
editType: CellExecutionUpdateType.ExecutionState;
|
|
48
|
+
executionOrder?: number;
|
|
49
|
+
runStartTime?: number;
|
|
50
|
+
didPause?: boolean;
|
|
51
|
+
isPaused?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ICellExecutionStateUpdate {
|
|
55
|
+
editType: CellExecutionUpdateType.ExecutionState;
|
|
56
|
+
executionOrder?: number;
|
|
57
|
+
runStartTime?: number;
|
|
58
|
+
didPause?: boolean;
|
|
59
|
+
isPaused?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ICellExecutionComplete {
|
|
63
|
+
runEndTime?: number;
|
|
64
|
+
lastRunSuccess?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export enum NotebookExecutionType {
|
|
67
|
+
cell,
|
|
68
|
+
notebook
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface NotebookFailStateChangedEvent {
|
|
72
|
+
visible: boolean;
|
|
73
|
+
notebook: URI;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface FailedCellInfo {
|
|
77
|
+
cellHandle: number;
|
|
78
|
+
disposable: Disposable;
|
|
79
|
+
visible: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@injectable()
|
|
83
|
+
export class NotebookExecutionStateService implements Disposable {
|
|
84
|
+
|
|
85
|
+
@inject(NotebookService)
|
|
86
|
+
protected notebookService: NotebookService;
|
|
87
|
+
|
|
88
|
+
protected readonly executions = new Map<string, CellExecution>();
|
|
89
|
+
|
|
90
|
+
private readonly onDidChangeExecutionEmitter = new Emitter<CellExecutionStateChangedEvent>();
|
|
91
|
+
onDidChangeExecution = this.onDidChangeExecutionEmitter.event;
|
|
92
|
+
|
|
93
|
+
private readonly onDidChangeLastRunFailStateEmitter = new Emitter<NotebookFailStateChangedEvent>();
|
|
94
|
+
onDidChangeLastRunFailState = this.onDidChangeLastRunFailStateEmitter.event;
|
|
95
|
+
|
|
96
|
+
createCellExecution(notebookUri: URI, cellHandle: number): CellExecution {
|
|
97
|
+
const notebook = this.notebookService.getNotebookEditorModel(notebookUri);
|
|
98
|
+
|
|
99
|
+
if (!notebook) {
|
|
100
|
+
throw new Error(`Notebook not found: ${notebookUri.toString()}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let execution = this.executions.get(`${notebookUri}/${cellHandle}`);
|
|
104
|
+
|
|
105
|
+
if (!execution) {
|
|
106
|
+
execution = this.createNotebookCellExecution(notebook, cellHandle);
|
|
107
|
+
this.executions.set(`${notebookUri}/${cellHandle}`, execution);
|
|
108
|
+
execution.initialize();
|
|
109
|
+
this.onDidChangeExecutionEmitter.fire(new CellExecutionStateChangedEvent(notebookUri, cellHandle, execution));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return execution;
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private createNotebookCellExecution(notebook: NotebookModel, cellHandle: number): CellExecution {
|
|
117
|
+
const notebookUri = notebook.uri;
|
|
118
|
+
const execution = new CellExecution(cellHandle, notebook);
|
|
119
|
+
execution.onDidUpdate(() => this.onDidChangeExecutionEmitter.fire(new CellExecutionStateChangedEvent(notebookUri, cellHandle, execution)));
|
|
120
|
+
execution.onDidComplete(lastRunSuccess => this.onCellExecutionDidComplete(notebookUri, cellHandle, execution, lastRunSuccess));
|
|
121
|
+
|
|
122
|
+
return execution;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private onCellExecutionDidComplete(notebookUri: URI, cellHandle: number, exe: CellExecution, lastRunSuccess?: boolean): void {
|
|
126
|
+
const notebookExecutions = this.executions.get(`${notebookUri}/${cellHandle}`);
|
|
127
|
+
if (!notebookExecutions) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
exe.dispose();
|
|
132
|
+
this.executions.delete(`${notebookUri}/${cellHandle}`);
|
|
133
|
+
|
|
134
|
+
this.onDidChangeExecutionEmitter.fire(new CellExecutionStateChangedEvent(notebookUri, cellHandle));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getCellExecution(cellUri: URI): CellExecution | undefined {
|
|
138
|
+
const parsed = CellUri.parse(cellUri);
|
|
139
|
+
if (!parsed) {
|
|
140
|
+
throw new Error(`Not a cell URI: ${cellUri}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return this.executions.get(`${parsed.notebook.toString()}/${parsed.handle}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
dispose(): void {
|
|
147
|
+
this.onDidChangeExecutionEmitter.dispose();
|
|
148
|
+
this.onDidChangeLastRunFailStateEmitter.dispose();
|
|
149
|
+
|
|
150
|
+
this.executions.forEach(cellExecution => cellExecution.dispose());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export class CellExecution implements Disposable {
|
|
156
|
+
private readonly onDidUpdateEmitter = new Emitter<void>();
|
|
157
|
+
readonly onDidUpdate = this.onDidUpdateEmitter.event;
|
|
158
|
+
|
|
159
|
+
private readonly onDidCompleteEmitter = new Emitter<boolean | undefined>();
|
|
160
|
+
readonly onDidComplete = this.onDidCompleteEmitter.event;
|
|
161
|
+
|
|
162
|
+
private _state: NotebookCellExecutionState = NotebookCellExecutionState.Unconfirmed;
|
|
163
|
+
get state(): NotebookCellExecutionState {
|
|
164
|
+
return this._state;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get notebookURI(): URI {
|
|
168
|
+
return this.notebook.uri;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private _didPause = false;
|
|
172
|
+
get didPause(): boolean {
|
|
173
|
+
return this._didPause;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private _isPaused = false;
|
|
177
|
+
get isPaused(): boolean {
|
|
178
|
+
return this._isPaused;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
constructor(
|
|
182
|
+
readonly cellHandle: number,
|
|
183
|
+
private readonly notebook: NotebookModel,
|
|
184
|
+
) {
|
|
185
|
+
console.debug(`CellExecution#ctor ${this.getCellLog()}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
initialize(): void {
|
|
189
|
+
const startExecuteEdit: CellPartialInternalMetadataEditByHandle = {
|
|
190
|
+
editType: CellEditType.PartialInternalMetadata,
|
|
191
|
+
handle: this.cellHandle,
|
|
192
|
+
internalMetadata: {
|
|
193
|
+
executionId: v4(),
|
|
194
|
+
runStartTime: undefined,
|
|
195
|
+
runEndTime: undefined,
|
|
196
|
+
lastRunSuccess: undefined,
|
|
197
|
+
executionOrder: undefined,
|
|
198
|
+
renderDuration: undefined,
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
this.applyExecutionEdits([startExecuteEdit]);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private getCellLog(): string {
|
|
205
|
+
return `${this.notebookURI.toString()}, ${this.cellHandle}`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
confirm(): void {
|
|
209
|
+
this._state = NotebookCellExecutionState.Pending;
|
|
210
|
+
this.onDidUpdateEmitter.fire();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
update(updates: CellExecuteUpdate[]): void {
|
|
214
|
+
if (updates.some(u => u.editType === CellExecutionUpdateType.ExecutionState)) {
|
|
215
|
+
this._state = NotebookCellExecutionState.Executing;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!this._didPause && updates.some(u => u.editType === CellExecutionUpdateType.ExecutionState && u.didPause)) {
|
|
219
|
+
this._didPause = true;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const lastIsPausedUpdate = [...updates].reverse().find(u => u.editType === CellExecutionUpdateType.ExecutionState && typeof u.isPaused === 'boolean');
|
|
223
|
+
if (lastIsPausedUpdate) {
|
|
224
|
+
this._isPaused = (lastIsPausedUpdate as ICellExecutionStateUpdate).isPaused!;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const cellModel = this.notebook.cells.find(c => c.handle === this.cellHandle);
|
|
228
|
+
if (!cellModel) {
|
|
229
|
+
console.debug(`CellExecution#update, updating cell not in notebook: ${this.notebook.uri.toString()}, ${this.cellHandle}`);
|
|
230
|
+
} else {
|
|
231
|
+
const edits = updates.map(update => updateToEdit(update, this.cellHandle));
|
|
232
|
+
this.applyExecutionEdits(edits);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (updates.some(u => u.editType === CellExecutionUpdateType.ExecutionState)) {
|
|
236
|
+
this.onDidUpdateEmitter.fire();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
complete(completionData: CellExecutionComplete): void {
|
|
242
|
+
const cellModel = this.notebook.cells.find(c => c.handle === this.cellHandle);
|
|
243
|
+
if (!cellModel) {
|
|
244
|
+
console.debug(`CellExecution#complete, completing cell not in notebook: ${this.notebook.uri.toString()}, ${this.cellHandle}`);
|
|
245
|
+
} else {
|
|
246
|
+
const edit: CellEditOperation = {
|
|
247
|
+
editType: CellEditType.PartialInternalMetadata,
|
|
248
|
+
handle: this.cellHandle,
|
|
249
|
+
internalMetadata: {
|
|
250
|
+
lastRunSuccess: completionData.lastRunSuccess,
|
|
251
|
+
// eslint-disable-next-line no-null/no-null
|
|
252
|
+
runStartTime: this._didPause ? null : cellModel.internalMetadata.runStartTime,
|
|
253
|
+
// eslint-disable-next-line no-null/no-null
|
|
254
|
+
runEndTime: this._didPause ? null : completionData.runEndTime,
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
this.applyExecutionEdits([edit]);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
this.onDidCompleteEmitter.fire(completionData.lastRunSuccess);
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
dispose(): void {
|
|
265
|
+
this.onDidUpdateEmitter.dispose();
|
|
266
|
+
this.onDidCompleteEmitter.dispose();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private applyExecutionEdits(edits: CellEditOperation[]): void {
|
|
270
|
+
this.notebook.applyEdits(edits, false);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export class CellExecutionStateChangedEvent {
|
|
275
|
+
readonly type = NotebookExecutionType.cell;
|
|
276
|
+
constructor(
|
|
277
|
+
readonly notebook: URI,
|
|
278
|
+
readonly cellHandle: number,
|
|
279
|
+
readonly changed?: CellExecution
|
|
280
|
+
) { }
|
|
281
|
+
|
|
282
|
+
affectsCell(cell: URI): boolean {
|
|
283
|
+
const parsedUri = CellUri.parse(cell);
|
|
284
|
+
return !!parsedUri && this.notebook.isEqual(parsedUri.notebook) && this.cellHandle === parsedUri.handle;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
affectsNotebook(notebook: URI): boolean {
|
|
288
|
+
return this.notebook.toString() === notebook.toString();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function updateToEdit(update: CellExecuteUpdate, cellHandle: number): CellEditOperation {
|
|
293
|
+
if (update.editType === CellExecutionUpdateType.Output) {
|
|
294
|
+
return {
|
|
295
|
+
editType: CellEditType.Output,
|
|
296
|
+
handle: update.cellHandle,
|
|
297
|
+
append: update.append,
|
|
298
|
+
outputs: update.outputs,
|
|
299
|
+
};
|
|
300
|
+
} else if (update.editType === CellExecutionUpdateType.OutputItems) {
|
|
301
|
+
return {
|
|
302
|
+
editType: CellEditType.OutputItems,
|
|
303
|
+
items: update.items,
|
|
304
|
+
append: update.append,
|
|
305
|
+
};
|
|
306
|
+
} else if (update.editType === CellExecutionUpdateType.ExecutionState) {
|
|
307
|
+
const newInternalMetadata: Partial<NotebookCellInternalMetadata> = {};
|
|
308
|
+
if (typeof update.executionOrder !== 'undefined') {
|
|
309
|
+
newInternalMetadata.executionOrder = update.executionOrder;
|
|
310
|
+
}
|
|
311
|
+
if (typeof update.runStartTime !== 'undefined') {
|
|
312
|
+
newInternalMetadata.runStartTime = update.runStartTime;
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
editType: CellEditType.PartialInternalMetadata,
|
|
316
|
+
handle: cellHandle,
|
|
317
|
+
internalMetadata: newInternalMetadata
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
throw new Error('Unknown cell update type');
|
|
322
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
/*---------------------------------------------------------------------------------------------
|
|
17
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
18
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
19
|
+
*--------------------------------------------------------------------------------------------*/
|
|
20
|
+
|
|
21
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
22
|
+
import { StorageService } from '@theia/core/lib/browser';
|
|
23
|
+
import { NotebookKernel, NotebookTextModelLike, NotebookKernelService } from './notebook-kernel-service';
|
|
24
|
+
import { Disposable } from '@theia/core';
|
|
25
|
+
|
|
26
|
+
interface KernelsList {
|
|
27
|
+
[viewType: string]: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface MostRecentKernelsResult {
|
|
31
|
+
selected?: NotebookKernel,
|
|
32
|
+
all: NotebookKernel[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const MAX_KERNELS_IN_HISTORY = 5;
|
|
36
|
+
|
|
37
|
+
@injectable()
|
|
38
|
+
export class NotebookKernelHistoryService implements Disposable {
|
|
39
|
+
|
|
40
|
+
@inject(StorageService)
|
|
41
|
+
protected storageService: StorageService;
|
|
42
|
+
|
|
43
|
+
@inject(NotebookKernelService)
|
|
44
|
+
protected notebookKernelService: NotebookKernelService;
|
|
45
|
+
|
|
46
|
+
declare serviceBrand: undefined;
|
|
47
|
+
|
|
48
|
+
private static STORAGE_KEY = 'notebook.kernelHistory';
|
|
49
|
+
private mostRecentKernelsMap: KernelsList = {};
|
|
50
|
+
|
|
51
|
+
@postConstruct()
|
|
52
|
+
protected init(): void {
|
|
53
|
+
this.loadState();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getKernels(notebook: NotebookTextModelLike): MostRecentKernelsResult {
|
|
57
|
+
const allAvailableKernels = this.notebookKernelService.getMatchingKernel(notebook);
|
|
58
|
+
const allKernels = allAvailableKernels.all;
|
|
59
|
+
const selectedKernel = allAvailableKernels.selected;
|
|
60
|
+
// We will suggest the only kernel
|
|
61
|
+
const suggested = allAvailableKernels.all.length === 1 ? allAvailableKernels.all[0] : undefined;
|
|
62
|
+
const mostRecentKernelIds = this.mostRecentKernelsMap[notebook.viewType] ? this.mostRecentKernelsMap[notebook.viewType].map(kernel => kernel[1]) : [];
|
|
63
|
+
const all = mostRecentKernelIds.map(kernelId => allKernels.find(kernel => kernel.id === kernelId)).filter(kernel => !!kernel) as NotebookKernel[];
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
selected: selectedKernel ?? suggested,
|
|
67
|
+
all
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
addMostRecentKernel(kernel: NotebookKernel): void {
|
|
72
|
+
const viewType = kernel.viewType;
|
|
73
|
+
const recentKernels = this.mostRecentKernelsMap[viewType] ?? [kernel.id];
|
|
74
|
+
|
|
75
|
+
if (recentKernels.length > MAX_KERNELS_IN_HISTORY) {
|
|
76
|
+
recentKernels.splice(MAX_KERNELS_IN_HISTORY);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.mostRecentKernelsMap[viewType] = recentKernels;
|
|
80
|
+
this.saveState();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private saveState(): void {
|
|
84
|
+
let notEmpty = false;
|
|
85
|
+
for (const [_, kernels] of Object.entries(this.mostRecentKernelsMap)) {
|
|
86
|
+
notEmpty = notEmpty || Object.entries(kernels).length > 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.storageService.setData(NotebookKernelHistoryService.STORAGE_KEY, notEmpty ? this.mostRecentKernelsMap : undefined);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private async loadState(): Promise<void> {
|
|
93
|
+
const kernelMap = await this.storageService.getData(NotebookKernelHistoryService.STORAGE_KEY);
|
|
94
|
+
if (kernelMap) {
|
|
95
|
+
this.mostRecentKernelsMap = kernelMap as KernelsList;
|
|
96
|
+
} else {
|
|
97
|
+
this.mostRecentKernelsMap = {};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
clear(): void {
|
|
102
|
+
this.mostRecentKernelsMap = {};
|
|
103
|
+
this.saveState();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
dispose(): void {
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
}
|