Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
update for latest notebook API
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed Sep 16, 2020
1 parent e8a4e0a commit 23ef7f5
Show file tree
Hide file tree
Showing 6 changed files with 961 additions and 369 deletions.
16 changes: 1 addition & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,15 @@
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--enable-proposed-api", "undefined_publisher.vscode-nodebook",
"${workspaceFolder}/samplenotebooks"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"activationEvents": [
"onNotebookEditor:nodebook",
"onNotebook:nodebook",
"onDebugDynamicConfigurations:node"
],
"main": "./out/extension.js",
Expand Down
6 changes: 4 additions & 2 deletions src/nodeKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class NodeKernel {
private debugPort?: number;

constructor(private document: vscode.NotebookDocument) {
this.tmpDirectory = fs.mkdtempSync(PATH.join(os.tmpdir(), 'vscode-nodebook-'));
}

public async start() {
Expand Down Expand Up @@ -51,7 +50,7 @@ export class NodeKernel {
__notebookID: this.document.uri.toString(),
name: 'nodebook',
request: 'attach',
type: 'node',
type: 'node2', // doesn't work with 'pwa-node'
port: this.debugPort,
timeout: 100000,
outputCapture: 'std',
Expand Down Expand Up @@ -143,6 +142,9 @@ export class NodeKernel {
// find cell in document by matching its URI
const cell = this.document.cells.find(c => c.uri.toString() === uri);
if (cell) {
if (!this.tmpDirectory) {
this.tmpDirectory = fs.mkdtempSync(PATH.join(os.tmpdir(), 'vscode-nodebook-'));
}
const cellPath = `${this.tmpDirectory}/nodebook_cell_${cellUri.fragment}.js`;
this.pathToCell.set(cellPath, cell);

Expand Down
43 changes: 21 additions & 22 deletions src/nodebookProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ const debugTypes = ['node', 'node2', 'pwa-node', 'pwa-chrome'];

export class NodebookContentProvider implements vscode.NotebookContentProvider, vscode.NotebookKernel {

readonly id = 'nodebookKernel';
public label = 'Node.js Kernel';

private _localDisposables: vscode.Disposable[] = [];
private readonly _associations = new Map<string, [ProjectAssociation, Nodebook]>();

public label = 'Node.js Kernel';
public kernel = this;

onDidChangeNotebook: vscode.Event<NotebookDocumentEditEvent> = new vscode.EventEmitter<NotebookDocumentEditEvent>().event;

Expand Down Expand Up @@ -84,6 +85,14 @@ export class NodebookContentProvider implements vscode.NotebookContentProvider,
}
}))
);

vscode.notebook.registerNotebookKernelProvider({
viewType: 'nodebook',
}, {
provideKernels: () => {
return [this];
}
});
}

public lookupNodebook(keyOrUri: string | vscode.Uri | undefined): Nodebook | undefined {
Expand Down Expand Up @@ -157,23 +166,9 @@ export class NodebookContentProvider implements vscode.NotebookContentProvider,
};
}

public async executeCell(document: vscode.NotebookDocument, cell: vscode.NotebookCell, token: vscode.CancellationToken): Promise<void> {

if (!cell) {

const project = this.lookupNodebook(document.uri);
if (project) {
project.restartKernel();
}

// run them all
for (let cell of document.cells) {
if (cell.cellKind === vscode.CellKind.Code && cell.metadata.runnable) {
await this.executeCell(document, cell, token);
}
}
return;
}
public async executeCell(_document: vscode.NotebookDocument, cell: vscode.NotebookCell): Promise<void> {

let output = '';
let error: Error | undefined;
Expand All @@ -200,16 +195,20 @@ export class NodebookContentProvider implements vscode.NotebookContentProvider,
}
}

public async executeAllCells(document: vscode.NotebookDocument, token: vscode.CancellationToken): Promise<void> {
public cancelCellExecution(_document: vscode.NotebookDocument, _cell: vscode.NotebookCell): void {
// not yet supported
}

public async executeAllCells(document: vscode.NotebookDocument): Promise<void> {
for (const cell of document.cells) {
if (token.isCancellationRequested) {
break;
}
await this.executeCell(document, cell, token);
await this.executeCell(document, cell);
}
}

cancelAllCellsExecution(_document: vscode.NotebookDocument): void {
// not yet supported
}

public dispose() {
this._localDisposables.forEach(d => d.dispose());
}
Expand Down
Loading

0 comments on commit 23ef7f5

Please sign in to comment.