@theia/plugin-ext 1.40.1 → 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/lib/common/collections.d.ts +4 -0
- package/lib/common/collections.d.ts.map +1 -1
- package/lib/common/collections.js +17 -1
- package/lib/common/collections.js.map +1 -1
- package/lib/common/errors.d.ts +14 -0
- package/lib/common/errors.d.ts.map +1 -1
- package/lib/common/errors.js +17 -1
- package/lib/common/errors.js.map +1 -1
- package/lib/common/plugin-api-rpc.d.ts +286 -6
- package/lib/common/plugin-api-rpc.d.ts.map +1 -1
- package/lib/common/plugin-api-rpc.js +20 -1
- package/lib/common/plugin-api-rpc.js.map +1 -1
- package/lib/common/plugin-protocol.d.ts +27 -5
- package/lib/common/plugin-protocol.d.ts.map +1 -1
- package/lib/common/plugin-protocol.js.map +1 -1
- package/lib/hosted/browser/hosted-plugin.d.ts +5 -2
- package/lib/hosted/browser/hosted-plugin.d.ts.map +1 -1
- package/lib/hosted/browser/hosted-plugin.js +21 -12
- package/lib/hosted/browser/hosted-plugin.js.map +1 -1
- package/lib/hosted/node/hosted-plugin-deployer-handler.js +1 -1
- package/lib/hosted/node/hosted-plugin-deployer-handler.js.map +1 -1
- package/lib/hosted/node/plugin-reader.d.ts +1 -1
- package/lib/hosted/node/plugin-reader.d.ts.map +1 -1
- package/lib/hosted/node/plugin-reader.js +1 -1
- package/lib/hosted/node/plugin-reader.js.map +1 -1
- package/lib/hosted/node/scanners/grammars-reader.d.ts +1 -1
- package/lib/hosted/node/scanners/grammars-reader.d.ts.map +1 -1
- package/lib/hosted/node/scanners/grammars-reader.js +5 -5
- package/lib/hosted/node/scanners/grammars-reader.js.map +1 -1
- package/lib/hosted/node/scanners/scanner-theia.d.ts +6 -6
- package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
- package/lib/hosted/node/scanners/scanner-theia.js +54 -41
- package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
- package/lib/main/browser/custom-editors/custom-editor-widget.d.ts +1 -1
- package/lib/main/browser/custom-editors/custom-editor-widget.d.ts.map +1 -1
- package/lib/main/browser/custom-editors/custom-editor-widget.js +1 -1
- package/lib/main/browser/custom-editors/custom-editor-widget.js.map +1 -1
- package/lib/main/browser/custom-editors/custom-editors-main.d.ts +1 -1
- package/lib/main/browser/custom-editors/custom-editors-main.d.ts.map +1 -1
- package/lib/main/browser/custom-editors/custom-editors-main.js +1 -1
- package/lib/main/browser/custom-editors/custom-editors-main.js.map +1 -1
- package/lib/main/browser/editors-and-documents-main.d.ts.map +1 -1
- package/lib/main/browser/editors-and-documents-main.js +1 -0
- package/lib/main/browser/editors-and-documents-main.js.map +1 -1
- package/lib/main/browser/languages-main.d.ts.map +1 -1
- package/lib/main/browser/languages-main.js +6 -4
- package/lib/main/browser/languages-main.js.map +1 -1
- package/lib/main/browser/main-context.d.ts.map +1 -1
- package/lib/main/browser/main-context.js +18 -0
- package/lib/main/browser/main-context.js.map +1 -1
- package/lib/main/browser/menus/menus-contribution-handler.d.ts.map +1 -1
- package/lib/main/browser/menus/menus-contribution-handler.js +6 -3
- package/lib/main/browser/menus/menus-contribution-handler.js.map +1 -1
- package/lib/main/browser/notebooks/notebook-documents-and-editors-main.d.ts +50 -0
- package/lib/main/browser/notebooks/notebook-documents-and-editors-main.d.ts.map +1 -0
- package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js +189 -0
- package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js.map +1 -0
- package/lib/main/browser/notebooks/notebook-documents-main.d.ts +22 -0
- package/lib/main/browser/notebooks/notebook-documents-main.d.ts.map +1 -0
- package/lib/main/browser/notebooks/notebook-documents-main.js +133 -0
- package/lib/main/browser/notebooks/notebook-documents-main.js.map +1 -0
- package/lib/main/browser/notebooks/notebook-dto.d.ts +15 -0
- package/lib/main/browser/notebooks/notebook-dto.d.ts.map +1 -0
- package/lib/main/browser/notebooks/notebook-dto.js +138 -0
- package/lib/main/browser/notebooks/notebook-dto.js.map +1 -0
- package/lib/main/browser/notebooks/notebook-editors-main.d.ts +20 -0
- package/lib/main/browser/notebooks/notebook-editors-main.d.ts.map +1 -0
- package/lib/main/browser/notebooks/notebook-editors-main.js +58 -0
- package/lib/main/browser/notebooks/notebook-editors-main.js.map +1 -0
- package/lib/main/browser/notebooks/notebook-kernels-main.d.ts +42 -0
- package/lib/main/browser/notebooks/notebook-kernels-main.d.ts.map +1 -0
- package/lib/main/browser/notebooks/notebook-kernels-main.js +230 -0
- package/lib/main/browser/notebooks/notebook-kernels-main.js.map +1 -0
- package/lib/main/browser/notebooks/notebook-renderers-main.d.ts +12 -0
- package/lib/main/browser/notebooks/notebook-renderers-main.d.ts.map +1 -0
- package/lib/main/browser/notebooks/notebook-renderers-main.js +39 -0
- package/lib/main/browser/notebooks/notebook-renderers-main.js.map +1 -0
- package/lib/main/browser/notebooks/notebooks-main.d.ts +20 -0
- package/lib/main/browser/notebooks/notebooks-main.d.ts.map +1 -0
- package/lib/main/browser/notebooks/notebooks-main.js +103 -0
- package/lib/main/browser/notebooks/notebooks-main.js.map +1 -0
- package/lib/main/browser/notebooks/renderers/cell-output-webview.d.ts +35 -0
- package/lib/main/browser/notebooks/renderers/cell-output-webview.d.ts.map +1 -0
- package/lib/main/browser/notebooks/renderers/cell-output-webview.js +204 -0
- package/lib/main/browser/notebooks/renderers/cell-output-webview.js.map +1 -0
- package/lib/main/browser/notebooks/renderers/output-webview-internal.d.ts +13 -0
- package/lib/main/browser/notebooks/renderers/output-webview-internal.d.ts.map +1 -0
- package/lib/main/browser/notebooks/renderers/output-webview-internal.js +375 -0
- package/lib/main/browser/notebooks/renderers/output-webview-internal.js.map +1 -0
- package/lib/main/browser/notebooks/renderers/webview-communication.d.ts +52 -0
- package/lib/main/browser/notebooks/renderers/webview-communication.d.ts.map +1 -0
- package/{src/typings/index.d.ts → lib/main/browser/notebooks/renderers/webview-communication.js} +8 -11
- package/lib/main/browser/notebooks/renderers/webview-communication.js.map +1 -0
- package/lib/main/browser/plugin-contribution-handler.d.ts +3 -0
- package/lib/main/browser/plugin-contribution-handler.d.ts.map +1 -1
- package/lib/main/browser/plugin-contribution-handler.js +31 -3
- package/lib/main/browser/plugin-contribution-handler.js.map +1 -1
- package/lib/main/browser/plugin-ext-frontend-module.d.ts.map +1 -1
- package/lib/main/browser/plugin-ext-frontend-module.js +3 -2
- package/lib/main/browser/plugin-ext-frontend-module.js.map +1 -1
- package/lib/main/browser/plugin-icon-theme-service.d.ts.map +1 -1
- package/lib/main/browser/plugin-icon-theme-service.js +6 -0
- package/lib/main/browser/plugin-icon-theme-service.js.map +1 -1
- package/lib/main/browser/plugin-shared-style.d.ts.map +1 -1
- package/lib/main/browser/plugin-shared-style.js +2 -1
- package/lib/main/browser/plugin-shared-style.js.map +1 -1
- package/lib/main/browser/tasks-main.js +2 -2
- package/lib/main/browser/tasks-main.js.map +1 -1
- package/lib/main/browser/terminal-main.d.ts +2 -2
- package/lib/main/browser/terminal-main.d.ts.map +1 -1
- package/lib/main/browser/terminal-main.js +4 -4
- package/lib/main/browser/terminal-main.js.map +1 -1
- package/lib/main/browser/view/tree-view-widget.d.ts +3 -1
- package/lib/main/browser/view/tree-view-widget.d.ts.map +1 -1
- package/lib/main/browser/view/tree-view-widget.js +32 -1
- package/lib/main/browser/view/tree-view-widget.js.map +1 -1
- package/lib/main/browser/view/tree-views-main.d.ts +2 -1
- package/lib/main/browser/view/tree-views-main.d.ts.map +1 -1
- package/lib/main/browser/view/tree-views-main.js +10 -0
- package/lib/main/browser/view/tree-views-main.js.map +1 -1
- package/lib/main/browser/webview/webview.d.ts +1 -0
- package/lib/main/browser/webview/webview.d.ts.map +1 -1
- package/lib/main/browser/webview/webview.js +5 -0
- package/lib/main/browser/webview/webview.js.map +1 -1
- package/lib/main/node/errors.spec.d.ts +2 -0
- package/lib/main/node/errors.spec.d.ts.map +1 -0
- package/lib/main/node/errors.spec.js +36 -0
- package/lib/main/node/errors.spec.js.map +1 -0
- package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts +5 -2
- package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts.map +1 -1
- package/lib/main/node/handlers/plugin-theia-directory-handler.js +14 -8
- package/lib/main/node/handlers/plugin-theia-directory-handler.js.map +1 -1
- package/lib/main/node/handlers/plugin-theia-file-handler.d.ts +2 -1
- package/lib/main/node/handlers/plugin-theia-file-handler.d.ts.map +1 -1
- package/lib/main/node/handlers/plugin-theia-file-handler.js +13 -5
- package/lib/main/node/handlers/plugin-theia-file-handler.js.map +1 -1
- package/lib/main/node/paths/plugin-paths-service.d.ts.map +1 -1
- package/lib/main/node/paths/plugin-paths-service.js +4 -9
- package/lib/main/node/paths/plugin-paths-service.js.map +1 -1
- package/lib/main/node/plugin-deployer-directory-handler-context-impl.js +8 -8
- package/lib/main/node/plugin-deployer-directory-handler-context-impl.js.map +1 -1
- package/lib/main/node/plugin-deployer-entry-impl.d.ts +2 -2
- package/lib/main/node/plugin-deployer-entry-impl.d.ts.map +1 -1
- package/lib/main/node/plugin-deployer-entry-impl.js +9 -7
- package/lib/main/node/plugin-deployer-entry-impl.js.map +1 -1
- package/lib/main/node/plugin-deployer-impl.d.ts +2 -2
- package/lib/main/node/plugin-deployer-impl.d.ts.map +1 -1
- package/lib/main/node/plugin-deployer-impl.js +16 -24
- package/lib/main/node/plugin-deployer-impl.js.map +1 -1
- package/lib/main/node/plugin-deployer-proxy-entry-impl.d.ts +2 -2
- package/lib/main/node/plugin-deployer-proxy-entry-impl.d.ts.map +1 -1
- package/lib/main/node/plugin-github-resolver.d.ts.map +1 -1
- package/lib/main/node/plugin-github-resolver.js +14 -6
- package/lib/main/node/plugin-github-resolver.js.map +1 -1
- package/lib/main/node/plugin-http-resolver.d.ts.map +1 -1
- package/lib/main/node/plugin-http-resolver.js +14 -6
- package/lib/main/node/plugin-http-resolver.js.map +1 -1
- package/lib/main/node/temp-dir-util.d.ts +1 -0
- package/lib/main/node/temp-dir-util.d.ts.map +1 -1
- package/lib/main/node/temp-dir-util.js +12 -3
- package/lib/main/node/temp-dir-util.js.map +1 -1
- package/lib/plugin/editors-and-documents.d.ts +1 -1
- package/lib/plugin/editors-and-documents.d.ts.map +1 -1
- package/lib/plugin/editors-and-documents.js +1 -1
- package/lib/plugin/editors-and-documents.js.map +1 -1
- package/lib/plugin/notebook/notebook-document.d.ts +62 -0
- package/lib/plugin/notebook/notebook-document.d.ts.map +1 -0
- package/lib/plugin/notebook/notebook-document.js +373 -0
- package/lib/plugin/notebook/notebook-document.js.map +1 -0
- package/lib/plugin/notebook/notebook-documents.d.ts +17 -0
- package/lib/plugin/notebook/notebook-documents.d.ts.map +1 -0
- package/lib/plugin/notebook/notebook-documents.js +48 -0
- package/lib/plugin/notebook/notebook-documents.js.map +1 -0
- package/lib/plugin/notebook/notebook-editor.d.ts +21 -0
- package/lib/plugin/notebook/notebook-editor.d.ts.map +1 -0
- package/lib/plugin/notebook/notebook-editor.js +99 -0
- package/lib/plugin/notebook/notebook-editor.js.map +1 -0
- package/lib/plugin/notebook/notebook-editors.d.ts +14 -0
- package/lib/plugin/notebook/notebook-editors.d.ts.map +1 -0
- package/lib/plugin/notebook/notebook-editors.js +65 -0
- package/lib/plugin/notebook/notebook-editors.js.map +1 -0
- package/lib/plugin/notebook/notebook-kernels.d.ts +37 -0
- package/lib/plugin/notebook/notebook-kernels.d.ts.map +1 -0
- package/lib/plugin/notebook/notebook-kernels.js +516 -0
- package/lib/plugin/notebook/notebook-kernels.js.map +1 -0
- package/lib/plugin/notebook/notebook-renderers.d.ts +14 -0
- package/lib/plugin/notebook/notebook-renderers.d.ts.map +1 -0
- package/lib/plugin/notebook/notebook-renderers.js +63 -0
- package/lib/plugin/notebook/notebook-renderers.js.map +1 -0
- package/lib/plugin/notebook/notebooks.d.ts +57 -0
- package/lib/plugin/notebook/notebooks.d.ts.map +1 -0
- package/lib/plugin/notebook/notebooks.js +295 -0
- package/lib/plugin/notebook/notebooks.js.map +1 -0
- package/lib/plugin/plugin-context.d.ts +2 -2
- package/lib/plugin/plugin-context.d.ts.map +1 -1
- package/lib/plugin/plugin-context.js +79 -59
- package/lib/plugin/plugin-context.js.map +1 -1
- package/lib/plugin/plugin-manager.d.ts +2 -0
- package/lib/plugin/plugin-manager.d.ts.map +1 -1
- package/lib/plugin/plugin-manager.js +9 -1
- package/lib/plugin/plugin-manager.js.map +1 -1
- package/lib/plugin/tasks/task-provider.d.ts +2 -2
- package/lib/plugin/tasks/task-provider.d.ts.map +1 -1
- package/lib/plugin/tasks/task-provider.js +7 -10
- package/lib/plugin/tasks/task-provider.js.map +1 -1
- package/lib/plugin/tasks/tasks.d.ts +3 -2
- package/lib/plugin/tasks/tasks.d.ts.map +1 -1
- package/lib/plugin/tasks/tasks.js +18 -13
- package/lib/plugin/tasks/tasks.js.map +1 -1
- package/lib/plugin/terminal-ext.d.ts +3 -0
- package/lib/plugin/terminal-ext.d.ts.map +1 -1
- package/lib/plugin/terminal-ext.js +11 -1
- package/lib/plugin/terminal-ext.js.map +1 -1
- package/lib/plugin/tree/tree-views.d.ts +15 -5
- package/lib/plugin/tree/tree-views.d.ts.map +1 -1
- package/lib/plugin/tree/tree-views.js +52 -3
- package/lib/plugin/tree/tree-views.js.map +1 -1
- package/lib/plugin/type-converters.d.ts +60 -0
- package/lib/plugin/type-converters.d.ts.map +1 -1
- package/lib/plugin/type-converters.js +372 -13
- package/lib/plugin/type-converters.js.map +1 -1
- package/lib/plugin/types-impl.d.ts +68 -29
- package/lib/plugin/types-impl.d.ts.map +1 -1
- package/lib/plugin/types-impl.js +123 -44
- package/lib/plugin/types-impl.js.map +1 -1
- package/package.json +31 -29
- package/src/common/collections.ts +17 -0
- package/src/common/errors.ts +26 -0
- package/src/common/plugin-api-rpc.ts +340 -5
- package/src/common/plugin-protocol.ts +23 -5
- package/src/hosted/browser/hosted-plugin.ts +21 -14
- package/src/hosted/node/hosted-plugin-deployer-handler.ts +1 -1
- package/src/hosted/node/plugin-reader.ts +1 -1
- package/src/hosted/node/scanners/grammars-reader.ts +6 -5
- package/src/hosted/node/scanners/scanner-theia.ts +55 -41
- package/src/main/browser/custom-editors/custom-editor-widget.ts +1 -1
- package/src/main/browser/custom-editors/custom-editors-main.ts +1 -1
- package/src/main/browser/editors-and-documents-main.ts +1 -0
- package/src/main/browser/languages-main.ts +7 -4
- package/src/main/browser/main-context.ts +19 -0
- package/src/main/browser/menus/menus-contribution-handler.ts +7 -4
- package/src/main/browser/notebooks/notebook-documents-and-editors-main.ts +238 -0
- package/src/main/browser/notebooks/notebook-documents-main.ts +166 -0
- package/src/main/browser/notebooks/notebook-dto.ts +141 -0
- package/src/main/browser/notebooks/notebook-editors-main.ts +70 -0
- package/src/main/browser/notebooks/notebook-kernels-main.ts +291 -0
- package/src/main/browser/notebooks/notebook-renderers-main.ts +47 -0
- package/src/main/browser/notebooks/notebooks-main.ts +124 -0
- package/src/main/browser/notebooks/renderers/cell-output-webview.tsx +198 -0
- package/src/main/browser/notebooks/renderers/output-webview-internal.ts +476 -0
- package/src/main/browser/notebooks/renderers/webview-communication.ts +79 -0
- package/src/main/browser/plugin-contribution-handler.ts +36 -3
- package/src/main/browser/plugin-ext-frontend-module.ts +7 -3
- package/src/main/browser/plugin-icon-theme-service.ts +6 -0
- package/src/main/browser/plugin-shared-style.ts +2 -1
- package/src/main/browser/tasks-main.ts +4 -4
- package/src/main/browser/terminal-main.ts +5 -5
- package/src/main/browser/view/tree-view-widget.tsx +36 -2
- package/src/main/browser/view/tree-views-main.ts +8 -0
- package/src/main/browser/webview/webview.ts +6 -0
- package/src/main/node/errors.spec.ts +37 -0
- package/src/main/node/handlers/plugin-theia-directory-handler.ts +18 -8
- package/src/main/node/handlers/plugin-theia-file-handler.ts +18 -6
- package/src/main/node/paths/plugin-paths-service.ts +5 -10
- package/src/main/node/plugin-deployer-directory-handler-context-impl.ts +8 -8
- package/src/main/node/plugin-deployer-entry-impl.ts +9 -7
- package/src/main/node/plugin-deployer-impl.ts +20 -28
- package/src/main/node/plugin-deployer-proxy-entry-impl.ts +2 -2
- package/src/main/node/plugin-github-resolver.ts +15 -8
- package/src/main/node/plugin-http-resolver.ts +15 -8
- package/src/main/node/temp-dir-util.ts +11 -2
- package/src/plugin/editors-and-documents.ts +1 -1
- package/src/plugin/notebook/notebook-document.ts +438 -0
- package/src/plugin/notebook/notebook-documents.ts +58 -0
- package/src/plugin/notebook/notebook-editor.ts +116 -0
- package/src/plugin/notebook/notebook-editors.ts +71 -0
- package/src/plugin/notebook/notebook-kernels.ts +616 -0
- package/src/plugin/notebook/notebook-renderers.ts +72 -0
- package/src/plugin/notebook/notebooks.ts +385 -0
- package/src/plugin/plugin-context.ts +77 -70
- package/src/plugin/plugin-manager.ts +9 -1
- package/src/plugin/tasks/task-provider.ts +9 -12
- package/src/plugin/tasks/tasks.ts +18 -13
- package/src/plugin/terminal-ext.ts +13 -1
- package/src/plugin/tree/tree-views.ts +57 -7
- package/src/plugin/type-converters.ts +370 -12
- package/src/plugin/types-impl.ts +162 -58
- package/lib/main/browser/custom-editors/undo-redo-service.d.ts +0 -24
- package/lib/main/browser/custom-editors/undo-redo-service.d.ts.map +0 -1
- package/lib/main/browser/custom-editors/undo-redo-service.js +0 -111
- package/lib/main/browser/custom-editors/undo-redo-service.js.map +0 -1
- package/src/main/browser/custom-editors/undo-redo-service.ts +0 -120
|
@@ -0,0 +1,291 @@
|
|
|
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 { CancellationToken, Disposable, Emitter, Event, URI } from '@theia/core';
|
|
22
|
+
import { UriComponents } from '@theia/core/lib/common/uri';
|
|
23
|
+
import { LanguageService } from '@theia/core/lib/browser/language-service';
|
|
24
|
+
import { CellExecuteUpdateDto, CellExecutionCompleteDto, MAIN_RPC_CONTEXT, NotebookKernelDto, NotebookKernelsExt, NotebookKernelsMain } from '../../../common';
|
|
25
|
+
import { RPCProtocol } from '../../../common/rpc-protocol';
|
|
26
|
+
import { CellExecution, NotebookExecutionStateService, NotebookKernelChangeEvent, NotebookKernelService, NotebookService } from '@theia/notebook/lib/browser';
|
|
27
|
+
import { combinedDisposable } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
|
|
28
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
29
|
+
import { NotebookKernelSourceAction } from '@theia/notebook/lib/common';
|
|
30
|
+
import { NotebookDto } from '../../../plugin/type-converters';
|
|
31
|
+
|
|
32
|
+
abstract class NotebookKernel {
|
|
33
|
+
private readonly onDidChangeEmitter = new Emitter<NotebookKernelChangeEvent>();
|
|
34
|
+
private readonly preloads: { uri: URI; provides: readonly string[] }[];
|
|
35
|
+
readonly onDidChange: Event<NotebookKernelChangeEvent> = this.onDidChangeEmitter.event;
|
|
36
|
+
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly viewType: string;
|
|
39
|
+
readonly extension: string;
|
|
40
|
+
|
|
41
|
+
implementsInterrupt: boolean;
|
|
42
|
+
label: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
detail?: string;
|
|
45
|
+
supportedLanguages: string[];
|
|
46
|
+
implementsExecutionOrder: boolean;
|
|
47
|
+
localResourceRoot: URI;
|
|
48
|
+
|
|
49
|
+
public get preloadUris(): URI[] {
|
|
50
|
+
return this.preloads.map(p => p.uri);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public get preloadProvides(): string[] {
|
|
54
|
+
return this.preloads.map(p => p.provides).flat();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
constructor(data: NotebookKernelDto, private languageService: LanguageService) {
|
|
58
|
+
this.id = data.id;
|
|
59
|
+
this.viewType = data.notebookType;
|
|
60
|
+
this.extension = data.extensionId;
|
|
61
|
+
|
|
62
|
+
this.implementsInterrupt = data.supportsInterrupt ?? false;
|
|
63
|
+
this.label = data.label;
|
|
64
|
+
this.description = data.description;
|
|
65
|
+
this.detail = data.detail;
|
|
66
|
+
this.supportedLanguages = (data.supportedLanguages && data.supportedLanguages.length > 0) ? data.supportedLanguages : languageService.languages.map(lang => lang.id);
|
|
67
|
+
this.implementsExecutionOrder = data.supportsExecutionOrder ?? false;
|
|
68
|
+
this.preloads = data.preloads?.map(u => ({ uri: URI.fromComponents(u.uri), provides: u.provides })) ?? [];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
update(data: Partial<NotebookKernelDto>): void {
|
|
72
|
+
|
|
73
|
+
const event: NotebookKernelChangeEvent = Object.create(null);
|
|
74
|
+
if (data.label !== undefined) {
|
|
75
|
+
this.label = data.label;
|
|
76
|
+
event.label = true;
|
|
77
|
+
}
|
|
78
|
+
if (data.description !== undefined) {
|
|
79
|
+
this.description = data.description;
|
|
80
|
+
event.description = true;
|
|
81
|
+
}
|
|
82
|
+
if (data.detail !== undefined) {
|
|
83
|
+
this.detail = data.detail;
|
|
84
|
+
event.detail = true;
|
|
85
|
+
}
|
|
86
|
+
if (data.supportedLanguages !== undefined) {
|
|
87
|
+
this.supportedLanguages = (data.supportedLanguages && data.supportedLanguages.length > 0) ?
|
|
88
|
+
data.supportedLanguages :
|
|
89
|
+
this.languageService.languages.map(lang => lang.id);
|
|
90
|
+
event.supportedLanguages = true;
|
|
91
|
+
}
|
|
92
|
+
if (data.supportsExecutionOrder !== undefined) {
|
|
93
|
+
this.implementsExecutionOrder = data.supportsExecutionOrder;
|
|
94
|
+
event.hasExecutionOrder = true;
|
|
95
|
+
}
|
|
96
|
+
if (data.supportsInterrupt !== undefined) {
|
|
97
|
+
this.implementsInterrupt = data.supportsInterrupt;
|
|
98
|
+
event.hasInterruptHandler = true;
|
|
99
|
+
}
|
|
100
|
+
this.onDidChangeEmitter.fire(event);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
abstract executeNotebookCellsRequest(uri: URI, cellHandles: number[]): Promise<void>;
|
|
104
|
+
abstract cancelNotebookCellExecution(uri: URI, cellHandles: number[]): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
class KernelDetectionTask {
|
|
108
|
+
constructor(readonly notebookType: string) { }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface KernelSourceActionProvider {
|
|
112
|
+
readonly viewType: string;
|
|
113
|
+
onDidChangeSourceActions?: Event<void>;
|
|
114
|
+
provideKernelSourceActions(): Promise<NotebookKernelSourceAction[]>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export class NotebookKernelsMainImpl implements NotebookKernelsMain {
|
|
118
|
+
|
|
119
|
+
private readonly proxy: NotebookKernelsExt;
|
|
120
|
+
|
|
121
|
+
private readonly kernels = new Map<number, [kernel: NotebookKernel, registration: Disposable]>();
|
|
122
|
+
|
|
123
|
+
private readonly kernelDetectionTasks = new Map<number, [task: KernelDetectionTask, registration: Disposable]>();
|
|
124
|
+
|
|
125
|
+
private readonly kernelSourceActionProviders = new Map<number, [provider: KernelSourceActionProvider, registration: Disposable]>();
|
|
126
|
+
private readonly kernelSourceActionProvidersEventRegistrations = new Map<number, Disposable>();
|
|
127
|
+
|
|
128
|
+
private notebookKernelService: NotebookKernelService;
|
|
129
|
+
private notebookService: NotebookService;
|
|
130
|
+
private languageService: LanguageService;
|
|
131
|
+
private notebookExecutionStateService: NotebookExecutionStateService;
|
|
132
|
+
|
|
133
|
+
private readonly executions = new Map<number, CellExecution>();
|
|
134
|
+
|
|
135
|
+
constructor(
|
|
136
|
+
rpc: RPCProtocol,
|
|
137
|
+
container: interfaces.Container,
|
|
138
|
+
) {
|
|
139
|
+
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOK_KERNELS_EXT);
|
|
140
|
+
|
|
141
|
+
this.notebookKernelService = container.get(NotebookKernelService);
|
|
142
|
+
this.notebookExecutionStateService = container.get(NotebookExecutionStateService);
|
|
143
|
+
this.notebookService = container.get(NotebookService);
|
|
144
|
+
this.languageService = container.get(LanguageService);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
$postMessage(handle: number, editorId: string | undefined, message: unknown): Promise<boolean> {
|
|
148
|
+
throw new Error('Method not implemented.');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async $addKernel(handle: number, data: NotebookKernelDto): Promise<void> {
|
|
152
|
+
const that = this;
|
|
153
|
+
const kernel = new class extends NotebookKernel {
|
|
154
|
+
async executeNotebookCellsRequest(uri: URI, handles: number[]): Promise<void> {
|
|
155
|
+
await that.proxy.$executeCells(handle, uri.toComponents(), handles);
|
|
156
|
+
}
|
|
157
|
+
async cancelNotebookCellExecution(uri: URI, handles: number[]): Promise<void> {
|
|
158
|
+
await that.proxy.$cancelCells(handle, uri.toComponents(), handles);
|
|
159
|
+
}
|
|
160
|
+
}(data, this.languageService);
|
|
161
|
+
|
|
162
|
+
const listener = this.notebookKernelService.onDidChangeSelectedKernel(e => {
|
|
163
|
+
if (e.oldKernel === kernel.id) {
|
|
164
|
+
this.proxy.$acceptNotebookAssociation(handle, e.notebook.toComponents(), false);
|
|
165
|
+
} else if (e.newKernel === kernel.id) {
|
|
166
|
+
this.proxy.$acceptNotebookAssociation(handle, e.notebook.toComponents(), true);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const registration = this.notebookKernelService.registerKernel(kernel);
|
|
171
|
+
this.kernels.set(handle, [kernel, combinedDisposable(listener, registration)]);
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
$updateKernel(handle: number, data: Partial<NotebookKernelDto>): void {
|
|
176
|
+
const tuple = this.kernels.get(handle);
|
|
177
|
+
if (tuple) {
|
|
178
|
+
tuple[0].update(data);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
$removeKernel(handle: number): void {
|
|
183
|
+
const tuple = this.kernels.get(handle);
|
|
184
|
+
if (tuple) {
|
|
185
|
+
tuple[1].dispose();
|
|
186
|
+
this.kernels.delete(handle);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
$updateNotebookPriority(handle: number, uri: UriComponents, value: number | undefined): void {
|
|
191
|
+
throw new Error('Method not implemented.');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
$createExecution(handle: number, controllerId: string, uriComponents: UriComponents, cellHandle: number): void {
|
|
195
|
+
const uri = URI.fromComponents(uriComponents);
|
|
196
|
+
const notebook = this.notebookService.getNotebookEditorModel(uri);
|
|
197
|
+
if (!notebook) {
|
|
198
|
+
throw new Error(`Notebook not found: ${uri.toString()}`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const kernel = this.notebookKernelService.getMatchingKernel(notebook);
|
|
202
|
+
if (!kernel.selected || kernel.selected.id !== controllerId) {
|
|
203
|
+
throw new Error(`Kernel is not selected: ${kernel.selected?.id} !== ${controllerId}`);
|
|
204
|
+
}
|
|
205
|
+
const execution = this.notebookExecutionStateService.createCellExecution(uri, cellHandle);
|
|
206
|
+
execution.confirm();
|
|
207
|
+
this.executions.set(handle, execution);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
$updateExecution(handle: number, updates: CellExecuteUpdateDto[]): void {
|
|
211
|
+
const execution = this.executions.get(handle);
|
|
212
|
+
execution?.update(updates.map(NotebookDto.fromCellExecuteUpdateDto));
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
$completeExecution(handle: number, data: CellExecutionCompleteDto): void {
|
|
216
|
+
try {
|
|
217
|
+
const execution = this.executions.get(handle);
|
|
218
|
+
execution?.complete(NotebookDto.fromCellExecuteCompleteDto(data));
|
|
219
|
+
} finally {
|
|
220
|
+
this.executions.delete(handle);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// TODO implement notebook execution (special api for executing full notebook instead of just cells)
|
|
226
|
+
$createNotebookExecution(handle: number, controllerId: string, uri: UriComponents): void {
|
|
227
|
+
throw new Error('Method not implemented.');
|
|
228
|
+
}
|
|
229
|
+
$beginNotebookExecution(handle: number): void {
|
|
230
|
+
throw new Error('Method not implemented.');
|
|
231
|
+
}
|
|
232
|
+
$completeNotebookExecution(handle: number): void {
|
|
233
|
+
throw new Error('Method not implemented.');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async $addKernelDetectionTask(handle: number, notebookType: string): Promise<void> {
|
|
237
|
+
const kernelDetectionTask = new KernelDetectionTask(notebookType);
|
|
238
|
+
const registration = this.notebookKernelService.registerNotebookKernelDetectionTask(kernelDetectionTask);
|
|
239
|
+
this.kernelDetectionTasks.set(handle, [kernelDetectionTask, registration]);
|
|
240
|
+
}
|
|
241
|
+
$removeKernelDetectionTask(handle: number): void {
|
|
242
|
+
const tuple = this.kernelDetectionTasks.get(handle);
|
|
243
|
+
if (tuple) {
|
|
244
|
+
tuple[1].dispose();
|
|
245
|
+
this.kernelDetectionTasks.delete(handle);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async $addKernelSourceActionProvider(handle: number, eventHandle: number, notebookType: string): Promise<void> {
|
|
249
|
+
const kernelSourceActionProvider: KernelSourceActionProvider = {
|
|
250
|
+
viewType: notebookType,
|
|
251
|
+
provideKernelSourceActions: async () => {
|
|
252
|
+
const actions = await this.proxy.$provideKernelSourceActions(handle, CancellationToken.None);
|
|
253
|
+
|
|
254
|
+
return actions.map(action => ({
|
|
255
|
+
label: action.label,
|
|
256
|
+
command: action.command,
|
|
257
|
+
description: action.description,
|
|
258
|
+
detail: action.detail,
|
|
259
|
+
documentation: action.documentation,
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
if (typeof eventHandle === 'number') {
|
|
265
|
+
const emitter = new Emitter<void>();
|
|
266
|
+
this.kernelSourceActionProvidersEventRegistrations.set(eventHandle, emitter);
|
|
267
|
+
kernelSourceActionProvider.onDidChangeSourceActions = emitter.event;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const registration = this.notebookKernelService.registerKernelSourceActionProvider(notebookType, kernelSourceActionProvider);
|
|
271
|
+
this.kernelSourceActionProviders.set(handle, [kernelSourceActionProvider, registration]);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
$removeKernelSourceActionProvider(handle: number, eventHandle: number): void {
|
|
275
|
+
const tuple = this.kernelSourceActionProviders.get(handle);
|
|
276
|
+
if (tuple) {
|
|
277
|
+
tuple[1].dispose();
|
|
278
|
+
this.kernelSourceActionProviders.delete(handle);
|
|
279
|
+
}
|
|
280
|
+
if (typeof eventHandle === 'number') {
|
|
281
|
+
this.kernelSourceActionProvidersEventRegistrations.delete(eventHandle);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
$emitNotebookKernelSourceActionsChangeEvent(eventHandle: number): void {
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
dispose(): void {
|
|
288
|
+
this.kernels.forEach(kernel => kernel[1].dispose());
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { DisposableCollection } from '@theia/core';
|
|
18
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
19
|
+
import { NotebookRendererMessagingService } from '@theia/notebook/lib/browser';
|
|
20
|
+
import { MAIN_RPC_CONTEXT, NotebookRenderersExt, NotebookRenderersMain } from '../../../common';
|
|
21
|
+
import { RPCProtocol } from '../../../common/rpc-protocol';
|
|
22
|
+
|
|
23
|
+
export class NotebookRenderersMainImpl implements NotebookRenderersMain {
|
|
24
|
+
private readonly proxy: NotebookRenderersExt;
|
|
25
|
+
private readonly rendererMessagingService: NotebookRendererMessagingService;
|
|
26
|
+
|
|
27
|
+
private readonly disposables = new DisposableCollection();
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
rpc: RPCProtocol,
|
|
31
|
+
container: interfaces.Container
|
|
32
|
+
) {
|
|
33
|
+
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOK_RENDERERS_EXT);
|
|
34
|
+
this.rendererMessagingService = container.get(NotebookRendererMessagingService);
|
|
35
|
+
this.rendererMessagingService.onShouldPostMessage(e => {
|
|
36
|
+
this.proxy.$postRendererMessage(e.editorId, e.rendererId, e.message);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
$postMessage(editorId: string | undefined, rendererId: string, message: unknown): Promise<boolean> {
|
|
41
|
+
return this.rendererMessagingService.receiveMessage(editorId, rendererId, message);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dispose(): void {
|
|
45
|
+
this.disposables.dispose();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { CancellationToken, DisposableCollection, Emitter } from '@theia/core';
|
|
18
|
+
import { BinaryBuffer } from '@theia/core/lib/common/buffer';
|
|
19
|
+
import { NotebookCellStatusBarItemList, NotebookCellStatusBarItemProvider, NotebookData, NotebookExtensionDescription, TransientOptions } from '@theia/notebook/lib/common';
|
|
20
|
+
import { NotebookService } from '@theia/notebook/lib/browser';
|
|
21
|
+
import { Disposable } from '@theia/plugin';
|
|
22
|
+
import { MAIN_RPC_CONTEXT, NotebooksExt, NotebooksMain } from '../../../common';
|
|
23
|
+
import { RPCProtocol } from '../../../common/rpc-protocol';
|
|
24
|
+
import { NotebookDto } from './notebook-dto';
|
|
25
|
+
import { UriComponents } from '@theia/core/lib/common/uri';
|
|
26
|
+
import { HostedPluginSupport } from '../../../hosted/browser/hosted-plugin';
|
|
27
|
+
|
|
28
|
+
export class NotebooksMainImpl implements NotebooksMain {
|
|
29
|
+
|
|
30
|
+
private readonly disposables = new DisposableCollection();
|
|
31
|
+
|
|
32
|
+
private readonly proxy: NotebooksExt;
|
|
33
|
+
private readonly notebookSerializer = new Map<number, Disposable>();
|
|
34
|
+
private readonly notebookCellStatusBarRegistrations = new Map<number, Disposable>();
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
rpc: RPCProtocol,
|
|
38
|
+
private notebookService: NotebookService,
|
|
39
|
+
plugins: HostedPluginSupport
|
|
40
|
+
) {
|
|
41
|
+
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOKS_EXT);
|
|
42
|
+
notebookService.onNotebookSerializer(async event => plugins.activateByEvent(event));
|
|
43
|
+
notebookService.markReady();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
dispose(): void {
|
|
47
|
+
this.disposables.dispose();
|
|
48
|
+
for (const disposable of this.notebookSerializer.values()) {
|
|
49
|
+
disposable.dispose();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
$registerNotebookSerializer(handle: number, extension: NotebookExtensionDescription, viewType: string, options: TransientOptions): void {
|
|
54
|
+
const disposables = new DisposableCollection();
|
|
55
|
+
|
|
56
|
+
disposables.push(this.notebookService.registerNotebookSerializer(viewType, extension, {
|
|
57
|
+
options,
|
|
58
|
+
dataToNotebook: async (data: BinaryBuffer): Promise<NotebookData> => {
|
|
59
|
+
const dto = await this.proxy.$dataToNotebook(handle, data, CancellationToken.None);
|
|
60
|
+
return NotebookDto.fromNotebookDataDto(dto);
|
|
61
|
+
},
|
|
62
|
+
notebookToData: (data: NotebookData): Promise<BinaryBuffer> =>
|
|
63
|
+
this.proxy.$notebookToData(handle, NotebookDto.toNotebookDataDto(data), CancellationToken.None)
|
|
64
|
+
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
this.notebookSerializer.set(handle, disposables);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
$unregisterNotebookSerializer(handle: number): void {
|
|
71
|
+
this.notebookSerializer.get(handle)?.dispose();
|
|
72
|
+
this.notebookSerializer.delete(handle);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
$emitCellStatusBarEvent(eventHandle: number): void {
|
|
76
|
+
const emitter = this.notebookCellStatusBarRegistrations.get(eventHandle);
|
|
77
|
+
if (emitter instanceof Emitter) {
|
|
78
|
+
emitter.fire(undefined);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async $registerNotebookCellStatusBarItemProvider(handle: number, eventHandle: number | undefined, viewType: string): Promise<void> {
|
|
83
|
+
const that = this;
|
|
84
|
+
const provider: NotebookCellStatusBarItemProvider = {
|
|
85
|
+
async provideCellStatusBarItems(uri: UriComponents, index: number, token: CancellationToken): Promise<NotebookCellStatusBarItemList | undefined> {
|
|
86
|
+
const result = await that.proxy.$provideNotebookCellStatusBarItems(handle, uri, index, token);
|
|
87
|
+
return {
|
|
88
|
+
items: result?.items ?? [],
|
|
89
|
+
dispose(): void {
|
|
90
|
+
if (result) {
|
|
91
|
+
that.proxy.$releaseNotebookCellStatusBarItems(result.cacheId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
viewType
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (typeof eventHandle === 'number') {
|
|
100
|
+
const emitter = new Emitter<void>();
|
|
101
|
+
this.notebookCellStatusBarRegistrations.set(eventHandle, emitter);
|
|
102
|
+
provider.onDidChangeStatusBarItems = emitter.event;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// const disposable = this._cellStatusBarService.registerCellStatusBarItemProvider(provider);
|
|
106
|
+
// this.notebookCellStatusBarRegistrations.set(handle, disposable);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async $unregisterNotebookCellStatusBarItemProvider(handle: number, eventHandle: number | undefined): Promise<void> {
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
111
|
+
const unregisterThing = (statusBarHandle: number) => {
|
|
112
|
+
const entry = this.notebookCellStatusBarRegistrations.get(statusBarHandle);
|
|
113
|
+
if (entry) {
|
|
114
|
+
this.notebookCellStatusBarRegistrations.get(statusBarHandle)?.dispose();
|
|
115
|
+
this.notebookCellStatusBarRegistrations.delete(statusBarHandle);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
unregisterThing(handle);
|
|
119
|
+
if (typeof eventHandle === 'number') {
|
|
120
|
+
unregisterThing(eventHandle);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
@@ -0,0 +1,198 @@
|
|
|
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 * as React from '@theia/core/shared/react';
|
|
22
|
+
import { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
|
|
23
|
+
import { NotebookRendererMessagingService, CellOutputWebview, NotebookRendererRegistry, NotebookEditorWidgetService } from '@theia/notebook/lib/browser';
|
|
24
|
+
import { v4 } from 'uuid';
|
|
25
|
+
import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-model';
|
|
26
|
+
import { WebviewWidget } from '../../webview/webview';
|
|
27
|
+
import { Message, WidgetManager } from '@theia/core/lib/browser';
|
|
28
|
+
import { outputWebviewPreload, PreloadContext } from './output-webview-internal';
|
|
29
|
+
import { WorkspaceTrustService } from '@theia/workspace/lib/browser';
|
|
30
|
+
import { ChangePreferredMimetypeMessage, FromWebviewMessage, OutputChangedMessage } from './webview-communication';
|
|
31
|
+
import { CellUri, NotebookCellOutputsSplice } from '@theia/notebook/lib/common';
|
|
32
|
+
import { Disposable, DisposableCollection, nls, QuickPickService } from '@theia/core';
|
|
33
|
+
import { NotebookCellOutputModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-output-model';
|
|
34
|
+
|
|
35
|
+
const CellModel = Symbol('CellModel');
|
|
36
|
+
|
|
37
|
+
export function createCellOutputWebviewContainer(ctx: interfaces.Container, cell: NotebookCellModel): interfaces.Container {
|
|
38
|
+
const child = ctx.createChild();
|
|
39
|
+
child.bind(CellModel).toConstantValue(cell);
|
|
40
|
+
child.bind(CellOutputWebviewImpl).toSelf().inSingletonScope();
|
|
41
|
+
return child;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@injectable()
|
|
45
|
+
export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
|
|
46
|
+
|
|
47
|
+
@inject(NotebookRendererMessagingService)
|
|
48
|
+
protected readonly messagingService: NotebookRendererMessagingService;
|
|
49
|
+
|
|
50
|
+
@inject(CellModel)
|
|
51
|
+
protected readonly cell: NotebookCellModel;
|
|
52
|
+
|
|
53
|
+
@inject(WidgetManager)
|
|
54
|
+
protected readonly widgetManager: WidgetManager;
|
|
55
|
+
|
|
56
|
+
@inject(WorkspaceTrustService)
|
|
57
|
+
protected readonly workspaceTrustService: WorkspaceTrustService;
|
|
58
|
+
|
|
59
|
+
@inject(NotebookRendererRegistry)
|
|
60
|
+
protected readonly notebookRendererRegistry: NotebookRendererRegistry;
|
|
61
|
+
|
|
62
|
+
@inject(NotebookEditorWidgetService)
|
|
63
|
+
protected readonly notebookEditorWidgetService: NotebookEditorWidgetService;
|
|
64
|
+
|
|
65
|
+
@inject(QuickPickService)
|
|
66
|
+
protected readonly quickPickService: QuickPickService;
|
|
67
|
+
|
|
68
|
+
readonly id = v4();
|
|
69
|
+
|
|
70
|
+
protected readonly elementRef = React.createRef<HTMLDivElement>();
|
|
71
|
+
protected outputPresentationListeners: DisposableCollection = new DisposableCollection();
|
|
72
|
+
|
|
73
|
+
protected webviewWidget: WebviewWidget;
|
|
74
|
+
|
|
75
|
+
@postConstruct()
|
|
76
|
+
protected async init(): Promise<void> {
|
|
77
|
+
this.cell.onDidChangeOutputs(outputChange => this.updateOutput(outputChange));
|
|
78
|
+
|
|
79
|
+
this.webviewWidget = await this.widgetManager.getOrCreateWidget(WebviewWidget.FACTORY_ID, { id: this.id });
|
|
80
|
+
this.webviewWidget.setContentOptions({ allowScripts: true });
|
|
81
|
+
this.webviewWidget.setHTML(await this.createWebviewContent());
|
|
82
|
+
|
|
83
|
+
this.webviewWidget.onMessage((message: FromWebviewMessage) => {
|
|
84
|
+
this.handleWebviewMessage(message);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
render(): React.JSX.Element {
|
|
89
|
+
return <div className='theia-notebook-cell-output-webview' ref={this.elementRef}></div>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
attachWebview(): void {
|
|
93
|
+
if (this.elementRef.current) {
|
|
94
|
+
this.webviewWidget.processMessage(new Message('before-attach'));
|
|
95
|
+
this.elementRef.current.appendChild(this.webviewWidget.node);
|
|
96
|
+
this.webviewWidget.processMessage(new Message('after-attach'));
|
|
97
|
+
this.webviewWidget.setIframeHeight(0);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
isAttached(): boolean {
|
|
102
|
+
return this.elementRef.current?.contains(this.webviewWidget.node) ?? false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
updateOutput(update: NotebookCellOutputsSplice): void {
|
|
106
|
+
if (this.cell.outputs.length > 0) {
|
|
107
|
+
if (this.webviewWidget.isHidden) {
|
|
108
|
+
this.webviewWidget.show();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.outputPresentationListeners.dispose();
|
|
112
|
+
this.outputPresentationListeners = new DisposableCollection();
|
|
113
|
+
for (const output of this.cell.outputs) {
|
|
114
|
+
this.outputPresentationListeners.push(output.onRequestOutputPresentationChange(() => this.requestOutputPresentationUpdate(output)));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const updateOutputMessage: OutputChangedMessage = {
|
|
118
|
+
type: 'outputChanged',
|
|
119
|
+
newOutputs: update.newOutputs.map(output => ({
|
|
120
|
+
id: output.outputId,
|
|
121
|
+
items: output.outputs.map(item => ({ mime: item.mime, data: item.data.buffer })),
|
|
122
|
+
metadata: output.metadata
|
|
123
|
+
})),
|
|
124
|
+
deletedOutputIds: this.cell.outputs.slice(update.start, update.start + update.deleteCount).map(output => output.outputId)
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
this.webviewWidget.sendMessage(updateOutputMessage);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private async requestOutputPresentationUpdate(output: NotebookCellOutputModel): Promise<void> {
|
|
132
|
+
const selectedMime = await this.quickPickService.show(
|
|
133
|
+
output.outputs.map(item => ({label: item.mime})),
|
|
134
|
+
{description: nls.localizeByDefault('Select mimetype to render for current output' )});
|
|
135
|
+
if (selectedMime) {
|
|
136
|
+
this.webviewWidget.sendMessage({
|
|
137
|
+
type: 'changePreferredMimetype',
|
|
138
|
+
outputId: output.outputId,
|
|
139
|
+
mimeType: selectedMime.label
|
|
140
|
+
} as ChangePreferredMimetypeMessage);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private handleWebviewMessage(message: FromWebviewMessage): void {
|
|
145
|
+
switch (message.type) {
|
|
146
|
+
case 'initialized':
|
|
147
|
+
this.updateOutput({newOutputs: this.cell.outputs, start: 0, deleteCount: 0});
|
|
148
|
+
break;
|
|
149
|
+
case 'customRendererMessage':
|
|
150
|
+
this.messagingService.getScoped('').postMessage(message.rendererId, message.message);
|
|
151
|
+
break;
|
|
152
|
+
case 'didRenderOutput':
|
|
153
|
+
this.webviewWidget.setIframeHeight(message.contentHeight + 5);
|
|
154
|
+
break;
|
|
155
|
+
case 'did-scroll-wheel':
|
|
156
|
+
this.notebookEditorWidgetService.getNotebookEditor(`notebook:${CellUri.parse(this.cell.uri)?.notebook}`)?.node.scrollBy(message.deltaX, message.deltaY);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private async createWebviewContent(): Promise<string> {
|
|
162
|
+
const isWorkspaceTrusted = await this.workspaceTrustService.getWorkspaceTrust();
|
|
163
|
+
const preloads = this.preloadsScriptString(isWorkspaceTrusted);
|
|
164
|
+
const content = `
|
|
165
|
+
<html>
|
|
166
|
+
<head>
|
|
167
|
+
<meta charset="UTF-8">
|
|
168
|
+
</head>
|
|
169
|
+
<body>
|
|
170
|
+
<script type="module">${preloads}</script>
|
|
171
|
+
</body>
|
|
172
|
+
</html>
|
|
173
|
+
`;
|
|
174
|
+
return content;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private preloadsScriptString(isWorkspaceTrusted: boolean): string {
|
|
178
|
+
const ctx: PreloadContext = {
|
|
179
|
+
isWorkspaceTrusted,
|
|
180
|
+
rendererData: this.notebookRendererRegistry.notebookRenderers,
|
|
181
|
+
renderOptions: { // TODO these should be changeable in the settings
|
|
182
|
+
lineLimit: 30,
|
|
183
|
+
outputScrolling: false,
|
|
184
|
+
outputWordWrap: false,
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
// TS will try compiling `import()` in webviewPreloads, so use a helper function instead
|
|
188
|
+
// of using `import(...)` directly
|
|
189
|
+
return `
|
|
190
|
+
const __import = (x) => import(x);
|
|
191
|
+
(${outputWebviewPreload})(JSON.parse(decodeURIComponent("${encodeURIComponent(JSON.stringify(ctx))}")))`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
dispose(): void {
|
|
195
|
+
this.outputPresentationListeners.dispose();
|
|
196
|
+
this.webviewWidget.dispose();
|
|
197
|
+
}
|
|
198
|
+
}
|