@theia/plugin-ext 1.40.0 → 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,238 @@
|
|
|
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, DisposableCollection } from '@theia/core';
|
|
22
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
23
|
+
import { UriComponents } from '@theia/core/lib/common/uri';
|
|
24
|
+
import { NotebookEditorWidget, NotebookService, NotebookEditorWidgetService } from '@theia/notebook/lib/browser';
|
|
25
|
+
import { NotebookModel } from '@theia/notebook/lib/browser/view-model/notebook-model';
|
|
26
|
+
import { MAIN_RPC_CONTEXT, NotebookDocumentsAndEditorsDelta, NotebookDocumentsAndEditorsMain, NotebookModelAddedData, NotebooksExt } from '../../../common';
|
|
27
|
+
import { RPCProtocol } from '../../../common/rpc-protocol';
|
|
28
|
+
import { NotebookDto } from './notebook-dto';
|
|
29
|
+
import { WidgetManager } from '@theia/core/lib/browser';
|
|
30
|
+
import { NotebookEditorsMainImpl } from './notebook-editors-main';
|
|
31
|
+
import { NotebookDocumentsMainImpl } from './notebook-documents-main';
|
|
32
|
+
import { diffMaps, diffSets } from '../../../common/collections';
|
|
33
|
+
import { Mutex } from 'async-mutex';
|
|
34
|
+
|
|
35
|
+
interface NotebookAndEditorDelta {
|
|
36
|
+
removedDocuments: UriComponents[];
|
|
37
|
+
addedDocuments: NotebookModel[];
|
|
38
|
+
removedEditors: string[];
|
|
39
|
+
addedEditors: NotebookEditorWidget[];
|
|
40
|
+
newActiveEditor?: string | null;
|
|
41
|
+
visibleEditors?: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class NotebookAndEditorState {
|
|
45
|
+
static delta(before: NotebookAndEditorState | undefined, after: NotebookAndEditorState): NotebookAndEditorDelta {
|
|
46
|
+
if (!before) {
|
|
47
|
+
return {
|
|
48
|
+
addedDocuments: [...after.documents],
|
|
49
|
+
removedDocuments: [],
|
|
50
|
+
addedEditors: [...after.textEditors.values()],
|
|
51
|
+
removedEditors: [],
|
|
52
|
+
visibleEditors: [...after.visibleEditors].map(editor => editor[0])
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const documentDelta = diffSets(before.documents, after.documents);
|
|
56
|
+
const editorDelta = diffMaps(before.textEditors, after.textEditors);
|
|
57
|
+
|
|
58
|
+
const newActiveEditor = before.activeEditor !== after.activeEditor ? after.activeEditor : undefined;
|
|
59
|
+
const visibleEditorDelta = diffMaps(before.visibleEditors, after.visibleEditors);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
addedDocuments: documentDelta.added,
|
|
63
|
+
removedDocuments: documentDelta.removed.map(e => e.uri.toComponents()),
|
|
64
|
+
addedEditors: editorDelta.added,
|
|
65
|
+
removedEditors: editorDelta.removed.map(removed => removed.id),
|
|
66
|
+
newActiveEditor: newActiveEditor,
|
|
67
|
+
visibleEditors: visibleEditorDelta.added.length === 0 && visibleEditorDelta.removed.length === 0
|
|
68
|
+
? undefined
|
|
69
|
+
: [...after.visibleEditors].map(editor => editor[0])
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
constructor(
|
|
74
|
+
readonly documents: Set<NotebookModel>,
|
|
75
|
+
readonly textEditors: Map<string, NotebookEditorWidget>,
|
|
76
|
+
readonly activeEditor: string | null | undefined,
|
|
77
|
+
readonly visibleEditors: Map<string, NotebookEditorWidget>
|
|
78
|
+
) {
|
|
79
|
+
//
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class NotebooksAndEditorsMain implements NotebookDocumentsAndEditorsMain {
|
|
84
|
+
|
|
85
|
+
protected readonly proxy: NotebooksExt;
|
|
86
|
+
protected readonly disposables = new DisposableCollection();
|
|
87
|
+
|
|
88
|
+
protected readonly editorListeners = new Map<string, Disposable[]>();
|
|
89
|
+
|
|
90
|
+
protected currentState?: NotebookAndEditorState;
|
|
91
|
+
protected readonly updateMutex = new Mutex();
|
|
92
|
+
|
|
93
|
+
protected readonly notebookService: NotebookService;
|
|
94
|
+
protected readonly notebookEditorService: NotebookEditorWidgetService;
|
|
95
|
+
protected readonly WidgetManager: WidgetManager;
|
|
96
|
+
|
|
97
|
+
constructor(
|
|
98
|
+
rpc: RPCProtocol,
|
|
99
|
+
container: interfaces.Container,
|
|
100
|
+
protected readonly notebookDocumentsMain: NotebookDocumentsMainImpl,
|
|
101
|
+
protected readonly notebookEditorsMain: NotebookEditorsMainImpl
|
|
102
|
+
) {
|
|
103
|
+
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOKS_EXT);
|
|
104
|
+
|
|
105
|
+
this.notebookService = container.get(NotebookService);
|
|
106
|
+
this.notebookEditorService = container.get(NotebookEditorWidgetService);
|
|
107
|
+
this.WidgetManager = container.get(WidgetManager);
|
|
108
|
+
|
|
109
|
+
this.notebookService.onDidAddNotebookDocument(async () => this.updateState(), this, this.disposables);
|
|
110
|
+
this.notebookService.onDidRemoveNotebookDocument(async () => this.updateState(), this, this.disposables);
|
|
111
|
+
// this.WidgetManager.onActiveEditorChanged(() => this.updateState(), this, this.disposables);
|
|
112
|
+
this.notebookEditorService.onDidAddNotebookEditor(async editor => this.handleEditorAdd(editor), this, this.disposables);
|
|
113
|
+
this.notebookEditorService.onDidRemoveNotebookEditor(async editor => this.handleEditorRemove(editor), this, this.disposables);
|
|
114
|
+
this.notebookEditorService.onFocusedEditorChanged(async editor => this.updateState(editor), this, this.disposables);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
dispose(): void {
|
|
118
|
+
this.notebookDocumentsMain.dispose();
|
|
119
|
+
this.notebookEditorsMain.dispose();
|
|
120
|
+
this.disposables.dispose();
|
|
121
|
+
this.editorListeners.forEach(listeners => listeners.forEach(listener => listener.dispose()));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private async handleEditorAdd(editor: NotebookEditorWidget): Promise<void> {
|
|
125
|
+
const listeners = this.editorListeners.get(editor.id);
|
|
126
|
+
const disposable = editor.onDidChangeModel(() => this.updateState());
|
|
127
|
+
if (listeners) {
|
|
128
|
+
listeners.push(disposable);
|
|
129
|
+
} else {
|
|
130
|
+
this.editorListeners.set(editor.id, [disposable]);
|
|
131
|
+
}
|
|
132
|
+
await this.updateState();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private handleEditorRemove(editor: NotebookEditorWidget): void {
|
|
136
|
+
const listeners = this.editorListeners.get(editor.id);
|
|
137
|
+
listeners?.forEach(listener => listener.dispose());
|
|
138
|
+
this.editorListeners.delete(editor.id);
|
|
139
|
+
this.updateState();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async updateState(focusedEditor?: NotebookEditorWidget): Promise<void> {
|
|
143
|
+
await this.updateMutex.runExclusive(async () => this.doUpdateState(focusedEditor));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private async doUpdateState(focusedEditor?: NotebookEditorWidget): Promise<void> {
|
|
147
|
+
|
|
148
|
+
const editors = new Map<string, NotebookEditorWidget>();
|
|
149
|
+
const visibleEditorsMap = new Map<string, NotebookEditorWidget>();
|
|
150
|
+
|
|
151
|
+
for (const editor of this.notebookEditorService.listNotebookEditors()) {
|
|
152
|
+
if (editor.model) {
|
|
153
|
+
editors.set(editor.id, editor);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const activeNotebookEditor = this.notebookEditorService.currentFocusedEditor;
|
|
158
|
+
let activeEditor: string | null = null;
|
|
159
|
+
if (activeNotebookEditor) {
|
|
160
|
+
activeEditor = activeNotebookEditor.id;
|
|
161
|
+
} else if (focusedEditor?.model) {
|
|
162
|
+
activeEditor = focusedEditor.id;
|
|
163
|
+
}
|
|
164
|
+
if (activeEditor && !editors.has(activeEditor)) {
|
|
165
|
+
activeEditor = null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const notebookEditors = this.WidgetManager.getWidgets(NotebookEditorWidget.ID) as NotebookEditorWidget[];
|
|
169
|
+
for (const notebookEditor of notebookEditors) {
|
|
170
|
+
if (notebookEditor?.model && editors.has(notebookEditor.id) && notebookEditor.isVisible) {
|
|
171
|
+
visibleEditorsMap.set(notebookEditor.id, notebookEditor);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const newState = new NotebookAndEditorState(
|
|
176
|
+
new Set(this.notebookService.listNotebookDocuments()),
|
|
177
|
+
editors,
|
|
178
|
+
activeEditor, visibleEditorsMap);
|
|
179
|
+
await this.onDelta(NotebookAndEditorState.delta(this.currentState, newState));
|
|
180
|
+
this.currentState = newState;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private async onDelta(delta: NotebookAndEditorDelta): Promise<void> {
|
|
184
|
+
if (NotebooksAndEditorsMain._isDeltaEmpty(delta)) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const dto: NotebookDocumentsAndEditorsDelta = {
|
|
189
|
+
removedDocuments: delta.removedDocuments,
|
|
190
|
+
removedEditors: delta.removedEditors,
|
|
191
|
+
newActiveEditor: delta.newActiveEditor,
|
|
192
|
+
visibleEditors: delta.visibleEditors,
|
|
193
|
+
addedDocuments: delta.addedDocuments.map(NotebooksAndEditorsMain.asModelAddData),
|
|
194
|
+
// addedEditors: delta.addedEditors.map(this.asEditorAddData, this),
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// send to extension FIRST
|
|
198
|
+
await this.proxy.$acceptDocumentsAndEditorsDelta(dto);
|
|
199
|
+
|
|
200
|
+
// handle internally
|
|
201
|
+
this.notebookEditorsMain.handleEditorsRemoved(delta.removedEditors);
|
|
202
|
+
this.notebookDocumentsMain.handleNotebooksRemoved(delta.removedDocuments);
|
|
203
|
+
this.notebookDocumentsMain.handleNotebooksAdded(delta.addedDocuments);
|
|
204
|
+
this.notebookEditorsMain.handleEditorsAdded(delta.addedEditors);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private static _isDeltaEmpty(delta: NotebookAndEditorDelta): boolean {
|
|
208
|
+
if (delta.addedDocuments !== undefined && delta.addedDocuments.length > 0) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
if (delta.removedDocuments !== undefined && delta.removedDocuments.length > 0) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
if (delta.addedEditors !== undefined && delta.addedEditors.length > 0) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (delta.removedEditors !== undefined && delta.removedEditors.length > 0) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
if (delta.visibleEditors !== undefined && delta.visibleEditors.length > 0) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
if (delta.newActiveEditor !== undefined) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private static asModelAddData(e: NotebookModel): NotebookModelAddedData {
|
|
230
|
+
return {
|
|
231
|
+
viewType: e.viewType,
|
|
232
|
+
uri: e.uri.toComponents(),
|
|
233
|
+
metadata: e.metadata,
|
|
234
|
+
versionId: 1, // TODO implement versionID support
|
|
235
|
+
cells: e.cells.map(NotebookDto.toNotebookCellDto)
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
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 { URI, UriComponents } from '@theia/core/lib/common/uri';
|
|
19
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
20
|
+
import { NotebookModelResolverService } from '@theia/notebook/lib/browser';
|
|
21
|
+
import { NotebookModel } from '@theia/notebook/lib/browser/view-model/notebook-model';
|
|
22
|
+
import { NotebookCellsChangeType } from '@theia/notebook/lib/common';
|
|
23
|
+
import { MAIN_RPC_CONTEXT, NotebookCellDto, NotebookCellsChangedEventDto, NotebookDataDto, NotebookDocumentsExt, NotebookDocumentsMain } from '../../../common';
|
|
24
|
+
import { RPCProtocol } from '../../../common/rpc-protocol';
|
|
25
|
+
import { NotebookDto } from './notebook-dto';
|
|
26
|
+
|
|
27
|
+
export class NotebookDocumentsMainImpl implements NotebookDocumentsMain {
|
|
28
|
+
|
|
29
|
+
private readonly disposables = new DisposableCollection();
|
|
30
|
+
|
|
31
|
+
private readonly proxy: NotebookDocumentsExt;
|
|
32
|
+
private readonly documentEventListenersMapping = new Map<string, DisposableCollection>();
|
|
33
|
+
|
|
34
|
+
private readonly notebookModelResolverService: NotebookModelResolverService;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
rpc: RPCProtocol,
|
|
38
|
+
container: interfaces.Container
|
|
39
|
+
) {
|
|
40
|
+
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_EXT);
|
|
41
|
+
this.notebookModelResolverService = container.get(NotebookModelResolverService);
|
|
42
|
+
|
|
43
|
+
// forward dirty and save events
|
|
44
|
+
this.disposables.push(this.notebookModelResolverService.onDidChangeDirty(model => this.proxy.$acceptDirtyStateChanged(model.uri.toComponents(), model.isDirty())));
|
|
45
|
+
this.disposables.push(this.notebookModelResolverService.onDidSaveNotebook(e => this.proxy.$acceptModelSaved(e)));
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dispose(): void {
|
|
50
|
+
this.disposables.dispose();
|
|
51
|
+
// this.modelReferenceCollection.dispose();
|
|
52
|
+
this.documentEventListenersMapping.forEach(value => value.dispose());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
handleNotebooksAdded(notebooks: readonly NotebookModel[]): void {
|
|
56
|
+
|
|
57
|
+
for (const textModel of notebooks) {
|
|
58
|
+
const disposableStore = new DisposableCollection();
|
|
59
|
+
disposableStore.push(textModel.onDidChangeContent(event => {
|
|
60
|
+
|
|
61
|
+
const eventDto: NotebookCellsChangedEventDto = {
|
|
62
|
+
versionId: 1, // TODO implement version ID support
|
|
63
|
+
rawEvents: []
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
for (const e of event.rawEvents) {
|
|
67
|
+
|
|
68
|
+
switch (e.kind) {
|
|
69
|
+
case NotebookCellsChangeType.ModelChange:
|
|
70
|
+
eventDto.rawEvents.push({
|
|
71
|
+
kind: e.kind,
|
|
72
|
+
changes: e.changes.map(diff =>
|
|
73
|
+
[diff[0], diff[1], diff[2].map(NotebookDto.toNotebookCellDto)] as [number, number, NotebookCellDto[]])
|
|
74
|
+
});
|
|
75
|
+
break;
|
|
76
|
+
case NotebookCellsChangeType.Move:
|
|
77
|
+
eventDto.rawEvents.push({
|
|
78
|
+
kind: e.kind,
|
|
79
|
+
index: e.index,
|
|
80
|
+
length: e.length,
|
|
81
|
+
newIdx: e.newIdx,
|
|
82
|
+
});
|
|
83
|
+
break;
|
|
84
|
+
case NotebookCellsChangeType.Output:
|
|
85
|
+
eventDto.rawEvents.push({
|
|
86
|
+
kind: e.kind,
|
|
87
|
+
index: e.index,
|
|
88
|
+
outputs: e.outputs.map(NotebookDto.toNotebookOutputDto)
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
case NotebookCellsChangeType.OutputItem:
|
|
92
|
+
eventDto.rawEvents.push({
|
|
93
|
+
kind: e.kind,
|
|
94
|
+
index: e.index,
|
|
95
|
+
outputId: e.outputId,
|
|
96
|
+
outputItems: e.outputItems.map(NotebookDto.toNotebookOutputItemDto),
|
|
97
|
+
append: e.append
|
|
98
|
+
});
|
|
99
|
+
break;
|
|
100
|
+
case NotebookCellsChangeType.ChangeCellLanguage:
|
|
101
|
+
case NotebookCellsChangeType.ChangeCellContent:
|
|
102
|
+
case NotebookCellsChangeType.ChangeCellMetadata:
|
|
103
|
+
case NotebookCellsChangeType.ChangeCellInternalMetadata:
|
|
104
|
+
eventDto.rawEvents.push(e);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const hasDocumentMetadataChangeEvent = event.rawEvents.find(e => e.kind === NotebookCellsChangeType.ChangeDocumentMetadata);
|
|
110
|
+
|
|
111
|
+
// using the model resolver service to know if the model is dirty or not.
|
|
112
|
+
// assuming this is the first listener it can mean that at first the model
|
|
113
|
+
// is marked as dirty and that another event is fired
|
|
114
|
+
this.proxy.$acceptModelChanged(
|
|
115
|
+
textModel.uri.toComponents(),
|
|
116
|
+
eventDto,
|
|
117
|
+
textModel.isDirty(),
|
|
118
|
+
hasDocumentMetadataChangeEvent ? textModel.metadata : undefined
|
|
119
|
+
);
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
this.documentEventListenersMapping.set(textModel.uri.toString(), disposableStore);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
handleNotebooksRemoved(uris: UriComponents[]): void {
|
|
127
|
+
for (const uri of uris) {
|
|
128
|
+
this.documentEventListenersMapping.get(uri.toString())?.dispose();
|
|
129
|
+
this.documentEventListenersMapping.delete(uri.toString());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async $tryCreateNotebook(options: { viewType: string; content?: NotebookDataDto }): Promise<UriComponents> {
|
|
134
|
+
const ref = await this.notebookModelResolverService.resolve({ untitledResource: undefined }, options.viewType);
|
|
135
|
+
|
|
136
|
+
// untitled notebooks are disposed when they get saved. we should not hold a reference
|
|
137
|
+
// to such a disposed notebook and therefore dispose the reference as well
|
|
138
|
+
// ref.onWillDispose(() => {
|
|
139
|
+
// ref.dispose();
|
|
140
|
+
// });
|
|
141
|
+
|
|
142
|
+
// untitled notebooks are dirty by default
|
|
143
|
+
this.proxy.$acceptDirtyStateChanged(ref.uri.toComponents(), true);
|
|
144
|
+
|
|
145
|
+
// apply content changes... slightly HACKY -> this triggers a change event
|
|
146
|
+
// if (options.content) {
|
|
147
|
+
// const data = NotebookDto.fromNotebookDataDto(options.content);
|
|
148
|
+
// ref.notebook.reset(data.cells, data.metadata, ref.object.notebook.transientOptions);
|
|
149
|
+
// }
|
|
150
|
+
return ref.uri.toComponents();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async $tryOpenNotebook(uriComponents: UriComponents): Promise<UriComponents> {
|
|
154
|
+
const uri = URI.fromComponents(uriComponents);
|
|
155
|
+
return uri.toComponents();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async $trySaveNotebook(uriComponents: UriComponents): Promise<boolean> {
|
|
159
|
+
const uri = URI.fromComponents(uriComponents);
|
|
160
|
+
|
|
161
|
+
const ref = await this.notebookModelResolverService.resolve(uri);
|
|
162
|
+
await ref.save({});
|
|
163
|
+
ref.dispose();
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
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 { OS } from '@theia/core';
|
|
18
|
+
import * as notebookCommon from '@theia/notebook/lib/common';
|
|
19
|
+
import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-model';
|
|
20
|
+
import * as rpc from '../../../common';
|
|
21
|
+
|
|
22
|
+
export namespace NotebookDto {
|
|
23
|
+
|
|
24
|
+
export function toNotebookOutputItemDto(item: notebookCommon.CellOutputItem): rpc.NotebookOutputItemDto {
|
|
25
|
+
return {
|
|
26
|
+
mime: item.mime,
|
|
27
|
+
valueBytes: item.data
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function toNotebookOutputDto(output: notebookCommon.CellOutput): rpc.NotebookOutputDto {
|
|
32
|
+
return {
|
|
33
|
+
outputId: output.outputId,
|
|
34
|
+
metadata: output.metadata,
|
|
35
|
+
items: output.outputs.map(toNotebookOutputItemDto)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function toNotebookCellDataDto(cell: notebookCommon.CellData): rpc.NotebookCellDataDto {
|
|
40
|
+
return {
|
|
41
|
+
cellKind: cell.cellKind,
|
|
42
|
+
language: cell.language,
|
|
43
|
+
source: cell.source,
|
|
44
|
+
internalMetadata: cell.internalMetadata,
|
|
45
|
+
metadata: cell.metadata,
|
|
46
|
+
outputs: cell.outputs.map(toNotebookOutputDto)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function toNotebookDataDto(data: notebookCommon.NotebookData): rpc.NotebookDataDto {
|
|
51
|
+
return {
|
|
52
|
+
metadata: data.metadata,
|
|
53
|
+
cells: data.cells.map(toNotebookCellDataDto)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function fromNotebookOutputItemDto(item: rpc.NotebookOutputItemDto): notebookCommon.CellOutputItem {
|
|
58
|
+
return {
|
|
59
|
+
mime: item.mime,
|
|
60
|
+
data: item.valueBytes
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function fromNotebookOutputDto(output: rpc.NotebookOutputDto): notebookCommon.CellOutput {
|
|
65
|
+
return {
|
|
66
|
+
outputId: output.outputId,
|
|
67
|
+
metadata: output.metadata,
|
|
68
|
+
outputs: output.items.map(fromNotebookOutputItemDto)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function fromNotebookCellDataDto(cell: rpc.NotebookCellDataDto): notebookCommon.CellData {
|
|
73
|
+
return {
|
|
74
|
+
cellKind: cell.cellKind,
|
|
75
|
+
language: cell.language,
|
|
76
|
+
source: cell.source,
|
|
77
|
+
outputs: cell.outputs.map(fromNotebookOutputDto),
|
|
78
|
+
metadata: cell.metadata,
|
|
79
|
+
internalMetadata: cell.internalMetadata
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function fromNotebookDataDto(data: rpc.NotebookDataDto): notebookCommon.NotebookData {
|
|
84
|
+
return {
|
|
85
|
+
metadata: data.metadata,
|
|
86
|
+
cells: data.cells.map(fromNotebookCellDataDto)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function toNotebookCellDto(cell: NotebookCellModel): rpc.NotebookCellDto {
|
|
91
|
+
const eol = OS.backend.isWindows ? '\r\n' : '\n';
|
|
92
|
+
return {
|
|
93
|
+
handle: cell.handle,
|
|
94
|
+
uri: cell.uri.toComponents(),
|
|
95
|
+
source: cell.textBuffer.split(eol),
|
|
96
|
+
eol,
|
|
97
|
+
language: cell.language,
|
|
98
|
+
cellKind: cell.cellKind,
|
|
99
|
+
outputs: cell.outputs.map(toNotebookOutputDto),
|
|
100
|
+
metadata: cell.metadata,
|
|
101
|
+
internalMetadata: cell.internalMetadata,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// export function fromCellExecuteUpdateDto(data: extHostProtocol.ICellExecuteUpdateDto): ICellExecuteUpdate {
|
|
106
|
+
// if (data.editType === CellExecutionUpdateType.Output) {
|
|
107
|
+
// return {
|
|
108
|
+
// editType: data.editType,
|
|
109
|
+
// cellHandle: data.cellHandle,
|
|
110
|
+
// append: data.append,
|
|
111
|
+
// outputs: data.outputs.map(fromNotebookOutputDto)
|
|
112
|
+
// };
|
|
113
|
+
// } else if (data.editType === CellExecutionUpdateType.OutputItems) {
|
|
114
|
+
// return {
|
|
115
|
+
// editType: data.editType,
|
|
116
|
+
// append: data.append,
|
|
117
|
+
// outputId: data.outputId,
|
|
118
|
+
// items: data.items.map(fromNotebookOutputItemDto)
|
|
119
|
+
// };
|
|
120
|
+
// } else {
|
|
121
|
+
// return data;
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
|
|
125
|
+
// export function fromCellExecuteCompleteDto(data: extHostProtocol.ICellExecutionCompleteDto): ICellExecutionComplete {
|
|
126
|
+
// return data;
|
|
127
|
+
// }
|
|
128
|
+
|
|
129
|
+
// export function fromCellEditOperationDto(edit: extHostProtocol.ICellEditOperationDto): notebookCommon.ICellEditOperation {
|
|
130
|
+
// if (edit.editType === notebookCommon.CellEditType.Replace) {
|
|
131
|
+
// return {
|
|
132
|
+
// editType: edit.editType,
|
|
133
|
+
// index: edit.index,
|
|
134
|
+
// count: edit.count,
|
|
135
|
+
// cells: edit.cells.map(fromNotebookCellDataDto)
|
|
136
|
+
// };
|
|
137
|
+
// } else {
|
|
138
|
+
// return edit;
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
141
|
+
}
|
|
@@ -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
|
+
* 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 { UriComponents, URI } from '@theia/core/lib/common/uri';
|
|
22
|
+
import { CellRange } from '@theia/notebook/lib/common';
|
|
23
|
+
import { NotebookEditorWidget } from '@theia/notebook/lib/browser';
|
|
24
|
+
import { MAIN_RPC_CONTEXT, NotebookDocumentShowOptions, NotebookEditorRevealType, NotebookEditorsExt, NotebookEditorsMain } from '../../../common';
|
|
25
|
+
import { RPCProtocol } from '../../../common/rpc-protocol';
|
|
26
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
27
|
+
import { open, OpenerService } from '@theia/core/lib/browser';
|
|
28
|
+
|
|
29
|
+
export class NotebookEditorsMainImpl implements NotebookEditorsMain {
|
|
30
|
+
|
|
31
|
+
protected readonly proxy: NotebookEditorsExt;
|
|
32
|
+
protected readonly openerService: OpenerService;
|
|
33
|
+
|
|
34
|
+
protected readonly mainThreadEditors = new Map<string, NotebookEditorWidget>();
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
rpc: RPCProtocol,
|
|
38
|
+
container: interfaces.Container
|
|
39
|
+
) {
|
|
40
|
+
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOK_EDITORS_EXT);
|
|
41
|
+
this.openerService = container.get(OpenerService);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async $tryShowNotebookDocument(uriComponents: UriComponents, viewType: string, options: NotebookDocumentShowOptions): Promise<string> {
|
|
45
|
+
const editor = await open(this.openerService, URI.fromComponents(uriComponents), {});
|
|
46
|
+
return (editor as NotebookEditorWidget).id;
|
|
47
|
+
}
|
|
48
|
+
$tryRevealRange(id: string, range: CellRange, revealType: NotebookEditorRevealType): Promise<void> {
|
|
49
|
+
throw new Error('Method not implemented.');
|
|
50
|
+
}
|
|
51
|
+
$trySetSelections(id: string, range: CellRange[]): void {
|
|
52
|
+
throw new Error('Method not implemented.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
handleEditorsAdded(editors: readonly NotebookEditorWidget[]): void {
|
|
56
|
+
for (const editor of editors) {
|
|
57
|
+
this.mainThreadEditors.set(editor.id, editor);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
handleEditorsRemoved(editorIds: readonly string[]): void {
|
|
62
|
+
for (const id of editorIds) {
|
|
63
|
+
this.mainThreadEditors.get(id)?.dispose();
|
|
64
|
+
this.mainThreadEditors.delete(id);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
dispose(): void {
|
|
69
|
+
}
|
|
70
|
+
}
|