update notebook api to using serializer

This commit is contained in:
tanhakabir 2021-05-03 10:40:27 -07:00
Родитель 6cac857181
Коммит 8ab3b9e2a7
5 изменённых файлов: 9343 добавлений и 263 удалений

6212
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -7,6 +7,7 @@
"author": {
"name": "Microsoft Corporation"
},
"enableProposedApi": true,
"repository": {
"type": "git",
"url": "https://github.com/microsoft/codetour"
@ -32,7 +33,8 @@
"workspace"
],
"activationEvents": [
"*"
"*",
"onNotebookEditor:codetour"
],
"main": "./dist/extension-node.js",
"browser": "./dist/extension-web.js",
@ -366,6 +368,11 @@
"command": "codetour.previewTour",
"group": "inline@4",
"when": "commentController == codetour && codetour:isEditing && !commentThreadIsEmpty"
},
{
"command": "codetour.viewNotebook",
"when": "viewItem == codetour.tour",
"group": "basic@2"
}
],
"comments/commentThread/context": [
@ -580,7 +587,7 @@
"jsonValidation": [
{
"fileMatch": "*.tour",
"url": "./schema.json"
"url": "./schema.json"
}
],
"keybindings": [
@ -616,6 +623,17 @@
".tour"
]
}
],
"notebookProvider": [
{
"viewType": "codetour",
"displayName": "CodeTour Notebook",
"selector": [
{
"filenamePattern": "*.tour"
}
]
}
]
},
"dependencies": {
@ -627,7 +645,7 @@
"vsls": "^1.0.2532"
},
"devDependencies": {
"@types/node": "^8.10.25",
"@types/node": "^8.10.66",
"@types/throttle-debounce": "^2.1.0",
"ts-loader": "^7.0.4",
"tslint": "^5.8.0",
@ -649,4 +667,4 @@
"arrowParens": "avoid",
"trailingComma": "none"
}
}
}

Просмотреть файл

@ -5,6 +5,7 @@ import * as vscode from "vscode";
import { initializeApi } from "./api";
import { initializeGitApi } from "./git";
import { registerLiveShareModule } from "./liveShare";
import { registerNotebookProvider } from "./notebook";
import { registerPlayerModule } from "./player";
import { registerRecorderModule } from "./recorder";
import { promptForTour } from "./store/actions";
@ -14,6 +15,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerPlayerModule(context);
registerRecorderModule();
registerLiveShareModule();
registerNotebookProvider();
if (vscode.workspace.workspaceFolders) {
await discoverTours();

Просмотреть файл

@ -1,26 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { TextDecoder, TextEncoder } from "util";
import * as vscode from "vscode";
import { EXTENSION_NAME, SMALL_ICON_URL } from "../constants";
import { CodeTour } from "../store";
import { getStepFileUri, getWorkspaceUri, readUriContents } from "../utils";
import { getStepFileUri, getWorkspaceUri } from "../utils";
class CodeTourNotebookProvider implements vscode.NotebookProvider {
async resolveNotebook(editor: vscode.NotebookEditor): Promise<void> {
editor.document.metadata = {
editable: false,
cellRunnable: false,
cellEditable: false
};
let contents = await readUriContents(editor.document.uri);
class CodeTourNotebookProvider implements vscode.NotebookSerializer {
async deserializeNotebook(content: Uint8Array, token: any): Promise<vscode.NotebookData> {
let contents = new TextDecoder().decode(content);
let tour = <CodeTour>JSON.parse(contents);
tour.id = editor.document.uri.toString();
let steps: any[] = [];
const workspaceRoot = getWorkspaceUri(tour);
let steps: any[] = [];
for (let item of tour.steps) {
const uri = await getStepFileUri(item, workspaceRoot, tour.ref);
@ -39,56 +32,34 @@ class CodeTourNotebookProvider implements vscode.NotebookProvider {
});
}
await editor.edit(editBuilder => {
editBuilder.insert(
0,
`## ![Icon](${SMALL_ICON_URL})&nbsp;&nbsp; CodeTour (${tour.title}) - ${steps.length} steps\n\n${tour.description}`,
"markdown",
vscode.CellKind.Markdown,
[],
{ editable: false, runnable: false, executionOrder: 1 }
);
let cells: vscode.NotebookCellData[] = [];
steps.forEach((step, index) => {
editBuilder.insert(
0,
step.contents,
step.language,
vscode.CellKind.Code,
[
{
outputKind: vscode.CellOutputKind.Rich,
data: {
"text/markdown": `_Step #${index + 1} of ${steps.length}:_ ${
step.description
} ([View File](${step.uri}))`
}
}
],
{
editable: false,
runnable: false,
executionOrder: index + 1
}
);
});
});
// Title cell
cells.push(new vscode.NotebookCellData(0,
`## ![Icon](${SMALL_ICON_URL})&nbsp;&nbsp; CodeTour (${tour.title}) - ${steps.length} steps\n\n${tour.description}`,
'markdown'))
steps.forEach((step, index) => {
cells.push(new vscode.NotebookCellData(1,
step.contents,
step.language,
[new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/markdown', `_Step #${index + 1} of ${steps.length}:_ ${step.description} ([View File](${step.uri}))`)
])]
))
})
return new vscode.NotebookData(cells, new vscode.NotebookDocumentMetadata(true))
}
async executeCell(
document: vscode.NotebookDocument,
cell: vscode.NotebookCell | undefined,
token: vscode.CancellationToken
): Promise<void> {}
async save(document: vscode.NotebookDocument): Promise<boolean> {
return true;
async serializeNotebook(data: vscode.NotebookData, token: any): Promise<Uint8Array> {
return new TextEncoder().encode('');
}
}
export function registerNotebookProvider() {
vscode.notebook.registerNotebookProvider(
vscode.notebook.registerNotebookSerializer(
EXTENSION_NAME,
new CodeTourNotebookProvider()
);
}
}

3283
src/notebook/vscode.proposed.d.ts поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу