@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
|
@@ -15,13 +15,22 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
import * as os from 'os';
|
|
17
17
|
import * as path from 'path';
|
|
18
|
-
import
|
|
18
|
+
import { realpathSync, promises as fs } from 'fs';
|
|
19
19
|
|
|
20
20
|
export function getTempDir(name: string): string {
|
|
21
21
|
let tempDir = os.tmpdir();
|
|
22
22
|
// for mac os 'os.tmpdir()' return symlink, but we need real path
|
|
23
23
|
if (process.platform === 'darwin') {
|
|
24
|
-
tempDir =
|
|
24
|
+
tempDir = realpathSync(tempDir);
|
|
25
|
+
}
|
|
26
|
+
return path.resolve(tempDir, name);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function getTempDirPathAsync(name: string): Promise<string> {
|
|
30
|
+
let tempDir = os.tmpdir();
|
|
31
|
+
// for mac os 'os.tmpdir()' return symlink, but we need real path
|
|
32
|
+
if (process.platform === 'darwin') {
|
|
33
|
+
tempDir = await fs.realpath(tempDir);
|
|
25
34
|
}
|
|
26
35
|
return path.resolve(tempDir, name);
|
|
27
36
|
}
|
|
@@ -43,7 +43,7 @@ export class EditorsAndDocumentsExtImpl implements EditorsAndDocumentsExt {
|
|
|
43
43
|
constructor(private readonly rpc: RPCProtocol) {
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
$acceptEditorsAndDocumentsDelta(delta: EditorsAndDocumentsDelta): void {
|
|
46
|
+
async $acceptEditorsAndDocumentsDelta(delta: EditorsAndDocumentsDelta): Promise<void> {
|
|
47
47
|
const removedDocuments = new Array<DocumentDataExt>();
|
|
48
48
|
const addedDocuments = new Array<DocumentDataExt>();
|
|
49
49
|
const removedEditors = new Array<TextEditorExt>();
|
|
@@ -0,0 +1,438 @@
|
|
|
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 theia from '@theia/plugin';
|
|
22
|
+
import * as rpc from '../../common';
|
|
23
|
+
import { EditorsAndDocumentsExtImpl } from '../editors-and-documents';
|
|
24
|
+
import * as notebookCommon from '@theia/notebook/lib/common';
|
|
25
|
+
import { Disposable, URI } from '@theia/core';
|
|
26
|
+
import * as typeConverters from '../type-converters';
|
|
27
|
+
import { ModelAddedData, NotebookCellDto, NotebookCellsChangedEventDto, NotebookModelAddedData, NotebookOutputDto } from '../../common';
|
|
28
|
+
import { NotebookRange } from '../types-impl';
|
|
29
|
+
import { UriComponents } from '../../common/uri-components';
|
|
30
|
+
import { DocumentsExtImpl } from '../documents';
|
|
31
|
+
|
|
32
|
+
class RawContentChangeEvent {
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
readonly start: number,
|
|
36
|
+
readonly deletedCount: number,
|
|
37
|
+
readonly deletedItems: theia.NotebookCell[],
|
|
38
|
+
readonly items: Cell[]
|
|
39
|
+
) { }
|
|
40
|
+
|
|
41
|
+
asApiEvent(): theia.NotebookDocumentContentChange {
|
|
42
|
+
return {
|
|
43
|
+
range: new NotebookRange(this.start, this.start + this.deletedCount),
|
|
44
|
+
addedCells: this.items.map(cell => cell.apiCell),
|
|
45
|
+
removedCells: this.deletedItems,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class Cell {
|
|
51
|
+
|
|
52
|
+
static asModelAddData(notebook: theia.NotebookDocument, cell: NotebookCellDto): ModelAddedData & { notebook: theia.NotebookDocument } {
|
|
53
|
+
return {
|
|
54
|
+
EOL: cell.eol,
|
|
55
|
+
lines: cell.source,
|
|
56
|
+
languageId: cell.language,
|
|
57
|
+
uri: cell.uri,
|
|
58
|
+
isDirty: false,
|
|
59
|
+
versionId: 1,
|
|
60
|
+
notebook,
|
|
61
|
+
modeId: ''
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private cell: theia.NotebookCell | undefined;
|
|
66
|
+
|
|
67
|
+
readonly handle: number;
|
|
68
|
+
readonly uri: URI;
|
|
69
|
+
readonly cellKind: notebookCommon.CellKind;
|
|
70
|
+
|
|
71
|
+
private outputs: theia.NotebookCellOutput[];
|
|
72
|
+
private metadata: Readonly<notebookCommon.NotebookCellMetadata>;
|
|
73
|
+
private previousResult: Readonly<theia.NotebookCellExecutionSummary | undefined>;
|
|
74
|
+
|
|
75
|
+
internalMetadata: notebookCommon.NotebookCellInternalMetadata;
|
|
76
|
+
|
|
77
|
+
get language(): string {
|
|
78
|
+
return this.apiCell.document.languageId;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
constructor(
|
|
82
|
+
public readonly notebookDocument: NotebookDocument,
|
|
83
|
+
private readonly editorsAndDocuments: EditorsAndDocumentsExtImpl,
|
|
84
|
+
private readonly cellData: rpc.NotebookCellDto,
|
|
85
|
+
) {
|
|
86
|
+
this.handle = cellData.handle;
|
|
87
|
+
this.uri = URI.fromComponents(cellData.uri);
|
|
88
|
+
this.cellKind = cellData.cellKind;
|
|
89
|
+
this.outputs = cellData.outputs.map(typeConverters.NotebookCellOutputConverter.to);
|
|
90
|
+
this.internalMetadata = cellData.internalMetadata ?? {};
|
|
91
|
+
this.metadata = Object.freeze(cellData.metadata ?? {});
|
|
92
|
+
this.previousResult = Object.freeze(typeConverters.NotebookCellExecutionSummary.to(cellData.internalMetadata ?? {}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get apiCell(): theia.NotebookCell {
|
|
96
|
+
if (!this.cell) {
|
|
97
|
+
const that = this;
|
|
98
|
+
const data = this.editorsAndDocuments.getDocument(this.uri.toString());
|
|
99
|
+
if (!data) {
|
|
100
|
+
throw new Error(`MISSING extHostDocument for notebook cell: ${this.uri}`);
|
|
101
|
+
}
|
|
102
|
+
const apiCell: theia.NotebookCell = {
|
|
103
|
+
get index(): number { return that.notebookDocument.getCellIndex(that); },
|
|
104
|
+
notebook: that.notebookDocument.apiNotebook,
|
|
105
|
+
kind: typeConverters.NotebookCellKind.to(this.cellData.cellKind),
|
|
106
|
+
document: data.document,
|
|
107
|
+
get outputs(): theia.NotebookCellOutput[] { return that.outputs.slice(0); },
|
|
108
|
+
get metadata(): notebookCommon.NotebookCellMetadata { return that.metadata; },
|
|
109
|
+
get executionSummary(): theia.NotebookCellExecutionSummary | undefined { return that.previousResult; }
|
|
110
|
+
};
|
|
111
|
+
this.cell = Object.freeze(apiCell);
|
|
112
|
+
}
|
|
113
|
+
return this.cell;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setOutputs(newOutputs: NotebookOutputDto[]): void {
|
|
117
|
+
this.outputs = newOutputs.map(typeConverters.NotebookCellOutputConverter.to);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// setOutputItems(outputId: string, append: boolean, newOutputItems: NotebookOutputItemDto[]): void {
|
|
121
|
+
// const newItems = newOutputItems.map(typeConverters.NotebookCellOutputItem.to);
|
|
122
|
+
// const output = this.outputs.find(op => op.id === outputId);
|
|
123
|
+
// if (output) {
|
|
124
|
+
// if (!append) {
|
|
125
|
+
// output.items.length = 0;
|
|
126
|
+
// }
|
|
127
|
+
// output.items.push(...newItems);
|
|
128
|
+
|
|
129
|
+
// // if (output.items.length > 1 && output.items.every(item => notebookCommon.isTextStreamMime(item.mime))) {
|
|
130
|
+
// // // Look for the mimes in the items, and keep track of their order.
|
|
131
|
+
// // // Merge the streams into one output item, per mime type.
|
|
132
|
+
// // const mimeOutputs = new Map<string, Uint8Array[]>();
|
|
133
|
+
// // const mimeTypes: string[] = [];
|
|
134
|
+
// // output.items.forEach(item => {
|
|
135
|
+
// // let items: Uint8Array[];
|
|
136
|
+
// // if (mimeOutputs.has(item.mime)) {
|
|
137
|
+
// // items = mimeOutputs.get(item.mime)!;
|
|
138
|
+
// // } else {
|
|
139
|
+
// // items = [];
|
|
140
|
+
// // mimeOutputs.set(item.mime, items);
|
|
141
|
+
// // mimeTypes.push(item.mime);
|
|
142
|
+
// // }
|
|
143
|
+
// // items.push(item.data);
|
|
144
|
+
// // });
|
|
145
|
+
// // output.items.length = 0;
|
|
146
|
+
// // mimeTypes.forEach(mime => {
|
|
147
|
+
// // const compressed = notebookCommon.compressOutputItemStreams(mimeOutputs.get(mime)!);
|
|
148
|
+
// // output.items.push({
|
|
149
|
+
// // mime,
|
|
150
|
+
// // data: compressed.buffer
|
|
151
|
+
// // });
|
|
152
|
+
// // });
|
|
153
|
+
// // }
|
|
154
|
+
// }
|
|
155
|
+
// }
|
|
156
|
+
|
|
157
|
+
setMetadata(newMetadata: notebookCommon.NotebookCellMetadata): void {
|
|
158
|
+
this.metadata = Object.freeze(newMetadata);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setInternalMetadata(newInternalMetadata: notebookCommon.NotebookCellInternalMetadata): void {
|
|
162
|
+
this.internalMetadata = newInternalMetadata;
|
|
163
|
+
this.previousResult = Object.freeze(typeConverters.NotebookCellExecutionSummary.to(newInternalMetadata));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export class NotebookDocument implements Disposable {
|
|
169
|
+
|
|
170
|
+
private readonly cells: Cell[];
|
|
171
|
+
|
|
172
|
+
private readonly notebookType: string;
|
|
173
|
+
|
|
174
|
+
private notebook?: theia.NotebookDocument;
|
|
175
|
+
private metadata: Record<string, unknown>;
|
|
176
|
+
private versionId: number = 0;
|
|
177
|
+
private isDirty: boolean = false;
|
|
178
|
+
private disposed: boolean = false;
|
|
179
|
+
|
|
180
|
+
constructor(
|
|
181
|
+
private readonly proxy: rpc.NotebookDocumentsMain,
|
|
182
|
+
private readonly editorsAndDocuments: EditorsAndDocumentsExtImpl,
|
|
183
|
+
private readonly textDocuments: DocumentsExtImpl,
|
|
184
|
+
public readonly uri: theia.Uri,
|
|
185
|
+
notebookData: NotebookModelAddedData
|
|
186
|
+
) {
|
|
187
|
+
this.notebookType = notebookData.viewType;
|
|
188
|
+
this.metadata = notebookData.metadata ?? {};
|
|
189
|
+
this.versionId = notebookData.versionId;
|
|
190
|
+
this.cells = notebookData.cells.map(cell => new Cell(this, editorsAndDocuments, cell));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
get apiNotebook(): theia.NotebookDocument {
|
|
194
|
+
if (!this.notebook) {
|
|
195
|
+
const that = this;
|
|
196
|
+
const apiObject: theia.NotebookDocument = {
|
|
197
|
+
get uri(): theia.Uri { return that.uri; },
|
|
198
|
+
get version(): number { return that.versionId; },
|
|
199
|
+
get notebookType(): string { return that.notebookType; },
|
|
200
|
+
get isDirty(): boolean { return that.isDirty; },
|
|
201
|
+
get isUntitled(): boolean { return that.uri.scheme === 'untitled'; },
|
|
202
|
+
get isClosed(): boolean { return that.disposed; },
|
|
203
|
+
get metadata(): Record<string, unknown> { return that.metadata; },
|
|
204
|
+
get cellCount(): number { return that.cells.length; },
|
|
205
|
+
cellAt(index): theia.NotebookCell {
|
|
206
|
+
index = that.validateIndex(index);
|
|
207
|
+
return that.cells[index].apiCell;
|
|
208
|
+
},
|
|
209
|
+
getCells(range): theia.NotebookCell[] {
|
|
210
|
+
const cells = range ? that.getCells(range) : that.cells;
|
|
211
|
+
return cells.map(cell => cell.apiCell);
|
|
212
|
+
},
|
|
213
|
+
save(): Promise<boolean> {
|
|
214
|
+
return that.save();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
this.notebook = Object.freeze(apiObject);
|
|
218
|
+
}
|
|
219
|
+
return this.notebook;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private validateIndex(index: number): number {
|
|
223
|
+
index = index | 0;
|
|
224
|
+
if (index < 0) {
|
|
225
|
+
return 0;
|
|
226
|
+
} else if (index >= this.cells.length) {
|
|
227
|
+
return this.cells.length - 1;
|
|
228
|
+
} else {
|
|
229
|
+
return index;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private validateRange(range: theia.NotebookRange): theia.NotebookRange {
|
|
234
|
+
let start = range.start | 0;
|
|
235
|
+
let end = range.end | 0;
|
|
236
|
+
if (start < 0) {
|
|
237
|
+
start = 0;
|
|
238
|
+
}
|
|
239
|
+
if (end > this.cells.length) {
|
|
240
|
+
end = this.cells.length;
|
|
241
|
+
}
|
|
242
|
+
return range.with({ start, end });
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private getCells(range: theia.NotebookRange): Cell[] {
|
|
246
|
+
range = this.validateRange(range);
|
|
247
|
+
const result: Cell[] = [];
|
|
248
|
+
for (let i = range.start; i < range.end; i++) {
|
|
249
|
+
result.push(this.cells[i]);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private async save(): Promise<boolean> {
|
|
255
|
+
if (this.disposed) {
|
|
256
|
+
return Promise.reject(new Error('Notebook has been closed'));
|
|
257
|
+
}
|
|
258
|
+
return this.proxy.$trySaveNotebook(this.uri);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
acceptDirty(isDirty: boolean): void {
|
|
262
|
+
this.isDirty = isDirty;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
acceptModelChanged(event: NotebookCellsChangedEventDto, isDirty: boolean, newMetadata: notebookCommon.NotebookDocumentMetadata | undefined): theia.NotebookDocumentChangeEvent {
|
|
266
|
+
this.versionId = event.versionId;
|
|
267
|
+
this.isDirty = isDirty;
|
|
268
|
+
// this.acceptDocumentPropertiesChanged({ metadata: newMetadata });
|
|
269
|
+
|
|
270
|
+
const result = {
|
|
271
|
+
notebook: this.apiNotebook,
|
|
272
|
+
metadata: newMetadata,
|
|
273
|
+
cellChanges: <theia.NotebookDocumentCellChange[]>[],
|
|
274
|
+
contentChanges: <theia.NotebookDocumentContentChange[]>[],
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
type RelaxedCellChange = Partial<theia.NotebookDocumentCellChange> & { cell: theia.NotebookCell };
|
|
278
|
+
const relaxedCellChanges: RelaxedCellChange[] = [];
|
|
279
|
+
|
|
280
|
+
// -- apply change and populate content changes
|
|
281
|
+
|
|
282
|
+
for (const rawEvent of event.rawEvents) {
|
|
283
|
+
if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ModelChange) {
|
|
284
|
+
this.spliceNotebookCells(rawEvent.changes, false, result.contentChanges);
|
|
285
|
+
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.Move) {
|
|
286
|
+
this.moveCells(rawEvent.index, rawEvent.length, rawEvent.newIdx, result.contentChanges);
|
|
287
|
+
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.Output) {
|
|
288
|
+
this.setCellOutputs(rawEvent.index, rawEvent.outputs);
|
|
289
|
+
relaxedCellChanges.push({ cell: this.cells[rawEvent.index].apiCell, outputs: this.cells[rawEvent.index].apiCell.outputs });
|
|
290
|
+
|
|
291
|
+
// } else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.OutputItem) {
|
|
292
|
+
// this._setCellOutputItems(rawEvent.index, rawEvent.outputId, rawEvent.append, rawEvent.outputItems);
|
|
293
|
+
// relaxedCellChanges.push({ cell: this.cells[rawEvent.index].apiCell, outputs: this.cells[rawEvent.index].apiCell.outputs });
|
|
294
|
+
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeCellLanguage) {
|
|
295
|
+
this.changeCellLanguage(rawEvent.index, rawEvent.language);
|
|
296
|
+
relaxedCellChanges.push({ cell: this.cells[rawEvent.index].apiCell, document: this.cells[rawEvent.index].apiCell.document });
|
|
297
|
+
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeCellContent) {
|
|
298
|
+
relaxedCellChanges.push({ cell: this.cells[rawEvent.index].apiCell, document: this.cells[rawEvent.index].apiCell.document });
|
|
299
|
+
|
|
300
|
+
// } else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeCellMime) {
|
|
301
|
+
// this._changeCellMime(rawEvent.index, rawEvent.mime);
|
|
302
|
+
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeCellMetadata) {
|
|
303
|
+
this.changeCellMetadata(rawEvent.index, rawEvent.metadata);
|
|
304
|
+
relaxedCellChanges.push({ cell: this.cells[rawEvent.index].apiCell, metadata: this.cells[rawEvent.index].apiCell.metadata });
|
|
305
|
+
|
|
306
|
+
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeCellInternalMetadata) {
|
|
307
|
+
this.changeCellInternalMetadata(rawEvent.index, rawEvent.internalMetadata);
|
|
308
|
+
relaxedCellChanges.push({ cell: this.cells[rawEvent.index].apiCell, executionSummary: this.cells[rawEvent.index].apiCell.executionSummary });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// -- compact cellChanges
|
|
313
|
+
|
|
314
|
+
const map = new Map<theia.NotebookCell, number>();
|
|
315
|
+
for (let i = 0; i < relaxedCellChanges.length; i++) {
|
|
316
|
+
const relaxedCellChange = relaxedCellChanges[i];
|
|
317
|
+
const existing = map.get(relaxedCellChange.cell);
|
|
318
|
+
if (existing === undefined) {
|
|
319
|
+
const newLen = result.cellChanges.push({
|
|
320
|
+
document: undefined,
|
|
321
|
+
executionSummary: undefined,
|
|
322
|
+
metadata: undefined,
|
|
323
|
+
outputs: undefined,
|
|
324
|
+
...relaxedCellChange,
|
|
325
|
+
});
|
|
326
|
+
map.set(relaxedCellChange.cell, newLen - 1);
|
|
327
|
+
} else {
|
|
328
|
+
result.cellChanges[existing] = {
|
|
329
|
+
...result.cellChanges[existing],
|
|
330
|
+
...relaxedCellChange
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Freeze event properties so handlers cannot accidentally modify them
|
|
336
|
+
Object.freeze(result);
|
|
337
|
+
Object.freeze(result.cellChanges);
|
|
338
|
+
Object.freeze(result.contentChanges);
|
|
339
|
+
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private spliceNotebookCells(splices: notebookCommon.NotebookCellTextModelSplice<NotebookCellDto>[], initialization: boolean,
|
|
344
|
+
bucket: theia.NotebookDocumentContentChange[] | undefined): void {
|
|
345
|
+
if (this.disposed) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const contentChangeEvents: RawContentChangeEvent[] = [];
|
|
350
|
+
const addedCellDocuments: ModelAddedData[] = [];
|
|
351
|
+
const removedCellDocuments: UriComponents[] = [];
|
|
352
|
+
|
|
353
|
+
splices.reverse().forEach(splice => {
|
|
354
|
+
const cellDtos = splice[2];
|
|
355
|
+
const newCells = cellDtos.map((cell: NotebookCellDto) => {
|
|
356
|
+
|
|
357
|
+
const extCell = new Cell(this, this.editorsAndDocuments, cell);
|
|
358
|
+
if (!initialization) {
|
|
359
|
+
addedCellDocuments.push(Cell.asModelAddData(this.apiNotebook, cell));
|
|
360
|
+
}
|
|
361
|
+
return extCell;
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
const changeEvent = new RawContentChangeEvent(splice[0], splice[1], [], newCells);
|
|
365
|
+
const deletedItems = this.cells.splice(splice[0], splice[1], ...newCells);
|
|
366
|
+
for (const cell of deletedItems) {
|
|
367
|
+
removedCellDocuments.push(cell.uri.toComponents());
|
|
368
|
+
changeEvent.deletedItems.push(cell.apiCell);
|
|
369
|
+
}
|
|
370
|
+
contentChangeEvents.push(changeEvent);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
if (bucket) {
|
|
374
|
+
for (const changeEvent of contentChangeEvents) {
|
|
375
|
+
bucket.push(changeEvent.asApiEvent());
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
private moveCells(index: number, length: number, newIdx: number, bucket: theia.NotebookDocumentContentChange[]): void {
|
|
381
|
+
const cells = this.cells.splice(index, length);
|
|
382
|
+
this.cells.splice(newIdx, 0, ...cells);
|
|
383
|
+
const changes = [
|
|
384
|
+
new RawContentChangeEvent(index, length, cells.map(c => c.apiCell), []),
|
|
385
|
+
new RawContentChangeEvent(newIdx, 0, [], cells)
|
|
386
|
+
];
|
|
387
|
+
for (const change of changes) {
|
|
388
|
+
bucket.push(change.asApiEvent());
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
private setCellOutputs(index: number, outputs: NotebookOutputDto[]): void {
|
|
393
|
+
const cell = this.cells[index];
|
|
394
|
+
cell.setOutputs(outputs);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// private _setCellOutputItems(index: number, outputId: string, append: boolean, outputItems: NotebookOutputItemDto[]): void {
|
|
398
|
+
// const cell = this.cells[index];
|
|
399
|
+
// cell.setOutputItems(outputId, append, outputItems);
|
|
400
|
+
// }
|
|
401
|
+
|
|
402
|
+
private changeCellLanguage(index: number, newLanguageId: string): void {
|
|
403
|
+
const cell = this.cells[index];
|
|
404
|
+
if (cell.apiCell.document.languageId !== newLanguageId) {
|
|
405
|
+
this.textDocuments.$acceptModelModeChanged(cell.uri.toComponents(), cell.language, newLanguageId);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private changeCellMetadata(index: number, newMetadata: notebookCommon.NotebookCellMetadata): void {
|
|
410
|
+
const cell = this.cells[index];
|
|
411
|
+
cell.setMetadata(newMetadata);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
private changeCellInternalMetadata(index: number, newInternalMetadata: notebookCommon.NotebookCellInternalMetadata): void {
|
|
415
|
+
const cell = this.cells[index];
|
|
416
|
+
cell.setInternalMetadata(newInternalMetadata);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
getCellFromApiCell(apiCell: theia.NotebookCell): Cell | undefined {
|
|
420
|
+
return this.cells.find(cell => cell.apiCell === apiCell);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
getCell(cellHandle: number): Cell | undefined {
|
|
424
|
+
return this.cells.find(cell => cell.handle === cellHandle);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
getCellFromIndex(index: number): Cell | undefined {
|
|
428
|
+
return this.cells[index];
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
getCellIndex(cell: Cell): number {
|
|
432
|
+
return this.cells.indexOf(cell);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
dispose(): void {
|
|
436
|
+
this.disposed = true;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 theia from '@theia/plugin';
|
|
22
|
+
import { Emitter } from '@theia/core';
|
|
23
|
+
import { UriComponents } from '../../common/uri-components';
|
|
24
|
+
import { NotebookCellsChangedEventDto, NotebookDocumentsExt } from '../../common';
|
|
25
|
+
import { NotebooksExtImpl } from './notebooks';
|
|
26
|
+
import { URI } from '../types-impl';
|
|
27
|
+
|
|
28
|
+
export type NotebookDocumentMetadata = Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
export class NotebookDocumentsExtImpl implements NotebookDocumentsExt {
|
|
31
|
+
|
|
32
|
+
private readonly didSaveNotebookDocumentEmitter = new Emitter<theia.NotebookDocument>();
|
|
33
|
+
readonly onDidSaveNotebookDocument = this.didSaveNotebookDocumentEmitter.event;
|
|
34
|
+
|
|
35
|
+
private readonly didChangeNotebookDocumentEmitter = new Emitter<theia.NotebookDocumentChangeEvent>();
|
|
36
|
+
readonly onDidChangeNotebookDocument = this.didChangeNotebookDocumentEmitter.event;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
private readonly notebooksAndEditors: NotebooksExtImpl,
|
|
40
|
+
) { }
|
|
41
|
+
|
|
42
|
+
$acceptModelChanged(uri: UriComponents, event: NotebookCellsChangedEventDto,
|
|
43
|
+
isDirty: boolean, newMetadata?: NotebookDocumentMetadata): void {
|
|
44
|
+
const document = this.notebooksAndEditors.getNotebookDocument(URI.from(uri));
|
|
45
|
+
const e = document.acceptModelChanged(event, isDirty, newMetadata);
|
|
46
|
+
this.didChangeNotebookDocumentEmitter.fire(e);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
$acceptDirtyStateChanged(uri: UriComponents, isDirty: boolean): void {
|
|
50
|
+
const document = this.notebooksAndEditors.getNotebookDocument(URI.from(uri));
|
|
51
|
+
document.acceptDirty(isDirty);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
$acceptModelSaved(uri: UriComponents): void {
|
|
55
|
+
const document = this.notebooksAndEditors.getNotebookDocument(URI.from(uri));
|
|
56
|
+
this.didSaveNotebookDocumentEmitter.fire(document.apiNotebook);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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 theia from '@theia/plugin';
|
|
22
|
+
import { NotebookDocument } from './notebook-document';
|
|
23
|
+
|
|
24
|
+
export class NotebookEditor {
|
|
25
|
+
|
|
26
|
+
public static readonly apiEditorsToExtHost = new WeakMap<theia.NotebookEditor, NotebookEditor>();
|
|
27
|
+
|
|
28
|
+
private selections: theia.NotebookRange[] = [];
|
|
29
|
+
private visibleRanges: theia.NotebookRange[] = [];
|
|
30
|
+
private viewColumn?: theia.ViewColumn;
|
|
31
|
+
|
|
32
|
+
private internalVisible: boolean = false;
|
|
33
|
+
|
|
34
|
+
private editor?: theia.NotebookEditor;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
readonly id: string,
|
|
38
|
+
// private readonly _proxy: MainThreadNotebookEditorsShape,
|
|
39
|
+
readonly notebookData: NotebookDocument,
|
|
40
|
+
visibleRanges: theia.NotebookRange[],
|
|
41
|
+
selections: theia.NotebookRange[],
|
|
42
|
+
viewColumn: theia.ViewColumn | undefined
|
|
43
|
+
) {
|
|
44
|
+
this.selections = selections;
|
|
45
|
+
this.visibleRanges = visibleRanges;
|
|
46
|
+
this.viewColumn = viewColumn;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get apiEditor(): theia.NotebookEditor {
|
|
50
|
+
if (!this.editor) {
|
|
51
|
+
const that = this;
|
|
52
|
+
this.editor = {
|
|
53
|
+
get notebook(): theia.NotebookDocument {
|
|
54
|
+
return that.notebookData.apiNotebook;
|
|
55
|
+
},
|
|
56
|
+
get selection(): theia.NotebookRange {
|
|
57
|
+
return that.selections[0];
|
|
58
|
+
},
|
|
59
|
+
set selection(selection: theia.NotebookRange) {
|
|
60
|
+
this.selections = [selection];
|
|
61
|
+
},
|
|
62
|
+
get selections(): theia.NotebookRange[] {
|
|
63
|
+
return that.selections;
|
|
64
|
+
},
|
|
65
|
+
set selections(value: theia.NotebookRange[]) {
|
|
66
|
+
// if (!Array.isArray(value) || !value.every(extHostTypes.NotebookRange.isNotebookRange)) {
|
|
67
|
+
// throw illegalArgument('selections');
|
|
68
|
+
// }
|
|
69
|
+
that.selections = value;
|
|
70
|
+
that.trySetSelections(value);
|
|
71
|
+
},
|
|
72
|
+
get visibleRanges(): theia.NotebookRange[] {
|
|
73
|
+
return that.visibleRanges;
|
|
74
|
+
},
|
|
75
|
+
revealRange(range, revealType): void {
|
|
76
|
+
// that._proxy.$tryRevealRange(
|
|
77
|
+
// that.id,
|
|
78
|
+
// extHostConverter.NotebookRange.from(range),
|
|
79
|
+
// revealType ?? extHostTypes.NotebookEditorRevealType.Default
|
|
80
|
+
// );
|
|
81
|
+
},
|
|
82
|
+
get viewColumn(): theia.ViewColumn | undefined {
|
|
83
|
+
return that.viewColumn;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
NotebookEditor.apiEditorsToExtHost.set(this.editor, this);
|
|
88
|
+
}
|
|
89
|
+
return this.editor;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get visible(): boolean {
|
|
93
|
+
return this.internalVisible;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
acceptVisibility(value: boolean): void {
|
|
97
|
+
this.internalVisible = value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
acceptVisibleRanges(value: theia.NotebookRange[]): void {
|
|
101
|
+
this.visibleRanges = value;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
acceptSelections(selections: theia.NotebookRange[]): void {
|
|
105
|
+
this.selections = selections;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private trySetSelections(value: theia.NotebookRange[]): void {
|
|
109
|
+
// NB Unimplemented: implement "selections"
|
|
110
|
+
// this._proxy.$trySetSelections(this.id, value.map(extHostConverter.NotebookRange.from));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
acceptViewColumn(value: theia.ViewColumn | undefined): void {
|
|
114
|
+
this.viewColumn = value;
|
|
115
|
+
}
|
|
116
|
+
}
|