@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,62 @@
|
|
|
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, Path } from '@theia/core';
|
|
22
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
23
|
+
import { NotebookRendererDescriptor } from '../common/notebook-protocol';
|
|
24
|
+
|
|
25
|
+
export interface NotebookRendererInfo {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly displayName: string;
|
|
28
|
+
readonly mimeTypes: string[];
|
|
29
|
+
readonly entrypoint: { readonly extends?: string; readonly uri: string };
|
|
30
|
+
readonly requiresMessaging: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@injectable()
|
|
34
|
+
export class NotebookRendererRegistry {
|
|
35
|
+
|
|
36
|
+
readonly notebookRenderers: NotebookRendererInfo[] = [];
|
|
37
|
+
|
|
38
|
+
registerNotebookRenderer(type: NotebookRendererDescriptor, basePath: string): Disposable {
|
|
39
|
+
let entrypoint;
|
|
40
|
+
if (typeof type.entrypoint === 'string') {
|
|
41
|
+
entrypoint = {
|
|
42
|
+
uri: new Path(basePath).join(type.entrypoint).toString()
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
entrypoint = {
|
|
46
|
+
uri: new Path(basePath).join(type.entrypoint.path).toString(),
|
|
47
|
+
extends: type.entrypoint.extends
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.notebookRenderers.push({
|
|
52
|
+
...type,
|
|
53
|
+
mimeTypes: type.mimeTypes || [],
|
|
54
|
+
requiresMessaging: type.requiresMessaging === 'always' || type.requiresMessaging === 'optional',
|
|
55
|
+
entrypoint
|
|
56
|
+
});
|
|
57
|
+
return Disposable.create(() => {
|
|
58
|
+
this.notebookRenderers.splice(this.notebookRenderers.findIndex(renderer => renderer.id === type.id), 1);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import { Disposable } from '@theia/core';
|
|
17
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { NotebookTypeDescriptor } from '../common/notebook-protocol';
|
|
19
|
+
|
|
20
|
+
@injectable()
|
|
21
|
+
export class NotebookTypeRegistry {
|
|
22
|
+
readonly notebookTypes: NotebookTypeDescriptor[] = [];
|
|
23
|
+
|
|
24
|
+
registerNotebookType(type: NotebookTypeDescriptor): Disposable {
|
|
25
|
+
this.notebookTypes.push(type);
|
|
26
|
+
return Disposable.create(() => {
|
|
27
|
+
this.notebookTypes.splice(this.notebookTypes.indexOf(type), 1);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
import { Disposable } from '@theia/core';
|
|
18
|
+
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
19
|
+
|
|
20
|
+
export const CellOutputWebviewFactory = Symbol('outputWebviewFactory');
|
|
21
|
+
|
|
22
|
+
export type CellOutputWebviewFactory = (cell: NotebookCellModel) => Promise<CellOutputWebview>;
|
|
23
|
+
|
|
24
|
+
export interface CellOutputWebview extends Disposable {
|
|
25
|
+
|
|
26
|
+
readonly id: string;
|
|
27
|
+
|
|
28
|
+
render(): React.JSX.Element;
|
|
29
|
+
|
|
30
|
+
attachWebview(): void;
|
|
31
|
+
isAttached(): boolean
|
|
32
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ContextKeyService, ScopedValueStore } from '@theia/core/lib/browser/context-key-service';
|
|
19
|
+
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
20
|
+
import { NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_TYPE } from '../contributions/notebook-context-keys';
|
|
21
|
+
import { Disposable, DisposableCollection, Emitter } from '@theia/core';
|
|
22
|
+
import { CellKind } from '../../common';
|
|
23
|
+
import { NotebookExecutionStateService } from '../service/notebook-execution-state-service';
|
|
24
|
+
|
|
25
|
+
@injectable()
|
|
26
|
+
export class NotebookCellContextManager implements Disposable {
|
|
27
|
+
@inject(ContextKeyService) protected contextKeyService: ContextKeyService;
|
|
28
|
+
|
|
29
|
+
@inject(NotebookExecutionStateService)
|
|
30
|
+
protected readonly executionStateService: NotebookExecutionStateService;
|
|
31
|
+
|
|
32
|
+
protected readonly toDispose = new DisposableCollection();
|
|
33
|
+
|
|
34
|
+
protected currentStore: ScopedValueStore;
|
|
35
|
+
protected currentContext: HTMLLIElement;
|
|
36
|
+
|
|
37
|
+
protected readonly onDidChangeContextEmitter = new Emitter<void>();
|
|
38
|
+
readonly onDidChangeContext = this.onDidChangeContextEmitter.event;
|
|
39
|
+
|
|
40
|
+
updateCellContext(cell: NotebookCellModel, newHtmlContext: HTMLLIElement): void {
|
|
41
|
+
if (newHtmlContext !== this.currentContext) {
|
|
42
|
+
this.toDispose.dispose();
|
|
43
|
+
this.currentStore?.dispose();
|
|
44
|
+
|
|
45
|
+
this.currentContext = newHtmlContext;
|
|
46
|
+
this.currentStore = this.contextKeyService.createScoped(newHtmlContext);
|
|
47
|
+
|
|
48
|
+
this.currentStore.setContext(NOTEBOOK_CELL_TYPE, cell.cellKind === CellKind.Code ? 'code' : 'markdown');
|
|
49
|
+
|
|
50
|
+
this.toDispose.push(cell.onDidRequestCellEditChange(cellEdit => {
|
|
51
|
+
this.currentStore?.setContext(NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, cellEdit);
|
|
52
|
+
this.onDidChangeContextEmitter.fire();
|
|
53
|
+
}));
|
|
54
|
+
this.toDispose.push(this.executionStateService.onDidChangeExecution(e => {
|
|
55
|
+
if (e.affectsCell(cell.uri)) {
|
|
56
|
+
this.currentStore?.setContext(NOTEBOOK_CELL_EXECUTING, !!e.changed);
|
|
57
|
+
this.currentStore?.setContext(NOTEBOOK_CELL_EXECUTION_STATE, e.changed?.state ?? 'idle');
|
|
58
|
+
this.onDidChangeContextEmitter.fire();
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
this.onDidChangeContextEmitter.fire();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dispose(): void {
|
|
66
|
+
this.toDispose.dispose();
|
|
67
|
+
this.currentStore?.dispose();
|
|
68
|
+
this.onDidChangeContextEmitter.dispose();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
/*---------------------------------------------------------------------------------------------
|
|
18
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
20
|
+
*--------------------------------------------------------------------------------------------*/
|
|
21
|
+
|
|
22
|
+
import { Disposable, DisposableCollection, Emitter } from '@theia/core';
|
|
23
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
24
|
+
import { ApplicationShell } from '@theia/core/lib/browser';
|
|
25
|
+
import { NotebookEditorWidget, NOTEBOOK_EDITOR_ID_PREFIX } from '../notebook-editor-widget';
|
|
26
|
+
|
|
27
|
+
@injectable()
|
|
28
|
+
export class NotebookEditorWidgetService implements Disposable {
|
|
29
|
+
|
|
30
|
+
@inject(ApplicationShell)
|
|
31
|
+
protected applicationShell: ApplicationShell;
|
|
32
|
+
|
|
33
|
+
private readonly notebookEditors = new Map<string, NotebookEditorWidget>();
|
|
34
|
+
|
|
35
|
+
private readonly onNotebookEditorAddEmitter = new Emitter<NotebookEditorWidget>();
|
|
36
|
+
private readonly onNotebookEditorsRemoveEmitter = new Emitter<NotebookEditorWidget>();
|
|
37
|
+
readonly onDidAddNotebookEditor = this.onNotebookEditorAddEmitter.event;
|
|
38
|
+
readonly onDidRemoveNotebookEditor = this.onNotebookEditorsRemoveEmitter.event;
|
|
39
|
+
|
|
40
|
+
private readonly onFocusedEditorChangedEmitter = new Emitter<NotebookEditorWidget>();
|
|
41
|
+
readonly onFocusedEditorChanged = this.onFocusedEditorChangedEmitter.event;
|
|
42
|
+
|
|
43
|
+
private readonly toDispose = new DisposableCollection();
|
|
44
|
+
|
|
45
|
+
currentFocusedEditor?: NotebookEditorWidget = undefined;
|
|
46
|
+
|
|
47
|
+
@postConstruct()
|
|
48
|
+
protected init(): void {
|
|
49
|
+
this.toDispose.push(this.applicationShell.onDidChangeActiveWidget(event => {
|
|
50
|
+
if (event.newValue?.id.startsWith(NOTEBOOK_EDITOR_ID_PREFIX) && event.newValue !== this.currentFocusedEditor) {
|
|
51
|
+
this.currentFocusedEditor = event.newValue as NotebookEditorWidget;
|
|
52
|
+
this.onFocusedEditorChangedEmitter.fire(this.currentFocusedEditor);
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
dispose(): void {
|
|
58
|
+
this.onNotebookEditorAddEmitter.dispose();
|
|
59
|
+
this.onNotebookEditorsRemoveEmitter.dispose();
|
|
60
|
+
this.onFocusedEditorChangedEmitter.dispose();
|
|
61
|
+
this.toDispose.dispose();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// --- editor management
|
|
65
|
+
|
|
66
|
+
addNotebookEditor(editor: NotebookEditorWidget): void {
|
|
67
|
+
this.notebookEditors.set(editor.id, editor);
|
|
68
|
+
this.onNotebookEditorAddEmitter.fire(editor);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
removeNotebookEditor(editor: NotebookEditorWidget): void {
|
|
72
|
+
if (this.notebookEditors.has(editor.id)) {
|
|
73
|
+
this.notebookEditors.delete(editor.id);
|
|
74
|
+
this.onNotebookEditorsRemoveEmitter.fire(editor);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getNotebookEditor(editorId: string): NotebookEditorWidget | undefined {
|
|
79
|
+
return this.notebookEditors.get(editorId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
listNotebookEditors(): readonly NotebookEditorWidget[] {
|
|
83
|
+
return [...this.notebookEditors].map(e => e[1]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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 } from '@theia/core/shared/inversify';
|
|
22
|
+
import { CellExecution, NotebookExecutionStateService } from '../service/notebook-execution-state-service';
|
|
23
|
+
import { CellKind, NotebookCellExecutionState } from '../../common';
|
|
24
|
+
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
25
|
+
import { NotebookModel } from '../view-model/notebook-model';
|
|
26
|
+
import { NotebookKernelService, NotebookKernel } from './notebook-kernel-service';
|
|
27
|
+
import { CommandService, Disposable } from '@theia/core';
|
|
28
|
+
import { NotebookKernelQuickPickService, NotebookKernelQuickPickServiceImpl } from './notebook-kernel-quick-pick-service';
|
|
29
|
+
import { NotebookKernelHistoryService } from './notebook-kernel-history-service';
|
|
30
|
+
import { NotebookCommands } from '../contributions/notebook-actions-contribution';
|
|
31
|
+
|
|
32
|
+
export interface CellExecutionParticipant {
|
|
33
|
+
onWillExecuteCell(executions: CellExecution[]): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@injectable()
|
|
37
|
+
export class NotebookExecutionService {
|
|
38
|
+
|
|
39
|
+
@inject(NotebookExecutionStateService)
|
|
40
|
+
protected notebookExecutionStateService: NotebookExecutionStateService;
|
|
41
|
+
|
|
42
|
+
@inject(NotebookKernelService)
|
|
43
|
+
protected notebookKernelService: NotebookKernelService;
|
|
44
|
+
|
|
45
|
+
@inject(NotebookKernelHistoryService)
|
|
46
|
+
protected notebookKernelHistoryService: NotebookKernelHistoryService;
|
|
47
|
+
|
|
48
|
+
@inject(CommandService)
|
|
49
|
+
protected commandService: CommandService;
|
|
50
|
+
|
|
51
|
+
@inject(NotebookKernelQuickPickService)
|
|
52
|
+
protected notebookKernelQuickPickService: NotebookKernelQuickPickServiceImpl;
|
|
53
|
+
|
|
54
|
+
private readonly cellExecutionParticipants = new Set<CellExecutionParticipant>();
|
|
55
|
+
|
|
56
|
+
async executeNotebookCells(notebook: NotebookModel, cells: Iterable<NotebookCellModel>): Promise<void> {
|
|
57
|
+
const cellsArr = Array.from(cells)
|
|
58
|
+
.filter(c => c.cellKind === CellKind.Code);
|
|
59
|
+
if (!cellsArr.length) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// create cell executions
|
|
64
|
+
const cellExecutions: [NotebookCellModel, CellExecution][] = [];
|
|
65
|
+
for (const cell of cellsArr) {
|
|
66
|
+
const cellExe = this.notebookExecutionStateService.getCellExecution(cell.uri);
|
|
67
|
+
if (!cellExe) {
|
|
68
|
+
cellExecutions.push([cell, this.notebookExecutionStateService.createCellExecution(notebook.uri, cell.handle)]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const kernel = await this.resolveKernel(notebook);
|
|
73
|
+
|
|
74
|
+
if (!kernel) {
|
|
75
|
+
// clear all pending cell executions
|
|
76
|
+
cellExecutions.forEach(cellExe => cellExe[1].complete({}));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// filter cell executions based on selected kernel
|
|
81
|
+
const validCellExecutions: CellExecution[] = [];
|
|
82
|
+
for (const [cell, cellExecution] of cellExecutions) {
|
|
83
|
+
if (!kernel.supportedLanguages.includes(cell.language)) {
|
|
84
|
+
cellExecution.complete({});
|
|
85
|
+
} else {
|
|
86
|
+
validCellExecutions.push(cellExecution);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// request execution
|
|
91
|
+
if (validCellExecutions.length > 0) {
|
|
92
|
+
await this.runExecutionParticipants(validCellExecutions);
|
|
93
|
+
|
|
94
|
+
this.notebookKernelService.selectKernelForNotebook(kernel, notebook);
|
|
95
|
+
await kernel.executeNotebookCellsRequest(notebook.uri, validCellExecutions.map(c => c.cellHandle));
|
|
96
|
+
// the connecting state can change before the kernel resolves executeNotebookCellsRequest
|
|
97
|
+
const unconfirmed = validCellExecutions.filter(exe => exe.state === NotebookCellExecutionState.Unconfirmed);
|
|
98
|
+
if (unconfirmed.length) {
|
|
99
|
+
unconfirmed.forEach(exe => exe.complete({}));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
registerExecutionParticipant(participant: CellExecutionParticipant): Disposable {
|
|
105
|
+
this.cellExecutionParticipants.add(participant);
|
|
106
|
+
return Disposable.create(() => this.cellExecutionParticipants.delete(participant));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private async runExecutionParticipants(executions: CellExecution[]): Promise<void> {
|
|
110
|
+
for (const participant of this.cellExecutionParticipants) {
|
|
111
|
+
await participant.onWillExecuteCell(executions);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async cancelNotebookCellHandles(notebook: NotebookModel, cells: Iterable<number>): Promise<void> {
|
|
117
|
+
const cellsArr = Array.from(cells);
|
|
118
|
+
const kernel = this.notebookKernelService.getSelectedOrSuggestedKernel(notebook);
|
|
119
|
+
if (kernel) {
|
|
120
|
+
await kernel.cancelNotebookCellExecution(notebook.uri, cellsArr);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async cancelNotebookCells(notebook: NotebookModel, cells: Iterable<NotebookCellModel>): Promise<void> {
|
|
125
|
+
this.cancelNotebookCellHandles(notebook, Array.from(cells, cell => cell.handle));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async resolveKernel(notebook: NotebookModel): Promise<NotebookKernel | undefined> {
|
|
129
|
+
const alreadySelected = this.notebookKernelHistoryService.getKernels(notebook);
|
|
130
|
+
|
|
131
|
+
if (alreadySelected.selected) {
|
|
132
|
+
return alreadySelected.selected;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await this.commandService.executeCommand(NotebookCommands.SELECT_KERNEL_COMMAND.id, notebook);
|
|
136
|
+
const { selected } = this.notebookKernelHistoryService.getKernels(notebook);
|
|
137
|
+
return selected;
|
|
138
|
+
}
|
|
139
|
+
}
|