Skip to content

Commit c9d395a

Browse files
committed
Add support for REPL
1 parent ba5bfa3 commit c9d395a

File tree

8 files changed

+228
-21
lines changed

8 files changed

+228
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 2.0.4 (26 Sept 2021)
4+
* Support for a REPL (Interactive Window) experience (https://github.com/DonJayamanne/typescript-notebook/issues/37)
5+
36
## 2.0.3 (12 Sept 2021)
47
* Support for user input in notebooks using [readline](https://nodejs.org/api/readline.html#readline_readline_createinterface_options)
58
* Update samples to use `isomorphic-fetch` instead of `node-fetch` (and pre-requisite `npm` packages).

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ wowever, this extension leverages the power of Notebooks to provide the same ric
1818
Use the command `Open a sample node.js notebook` to open a sample notebook to get started with plotly.js, danfo.js, tensorflow.js, etc.
1919

2020
## Getting started
21-
* Create a file with the extension `*.nnb`, e.g. `sample.nnb`
22-
* Or use the menu item `New File...` to create a Node.js notebook
21+
* For a REPL experience use the command `Open Node.js REPL`
22+
* Consider installing the [Jupyter](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) extension for an enhance user interface (toolbars).
23+
* For a notebook experience, create a file with the extension `*.nnb`, e.g. `sample.nnb`
24+
* Or use the menu item `New File...` to create a Node.js notebook
2325

2426

2527
![Demo](https://raw.githubusercontent.com/DonJayamanne/typescript-notebook/main/images/demo.gif)
@@ -34,7 +36,6 @@ Use the command `Open a sample node.js notebook` to open a sample notebook to ge
3436
* node.js needs to be in the current path
3537

3638
## Roadmap
37-
* Interactive Window experience
3839
* Open a plain js/ts file as a notebook & vice versa.
3940
* Better renderers for tabular data (arquero, danfo.js, etc)
4041
* [Vega](https://vega.github.io/vega/) plots without having to install vega

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "typescript-notebook",
3-
"displayName": "Node.js Notebooks",
4-
"description": "Iterative & iteractive programming for Node.js in JavaScript/TypeScript, with great support for Tensorflow.js, debugging, & more..",
5-
"version": "2.0.3",
3+
"displayName": "Node.js Notebooks (REPL)",
4+
"description": "Iterative & iteractive programming for Node.js in JavaScript/TypeScript (REPL), with great support for Tensorflow.js, debugging, & more..",
5+
"version": "2.0.4",
66
"engines": {
77
"vscode": "^1.60.0"
88
},
@@ -71,6 +71,7 @@
7171
"onCommand:node.notebook.sample.basics.debug",
7272
"onCommand:node.notebook.sample.arquero.htmlOutput",
7373
"onCommand:node.notebook.new",
74+
"onCommand:node.notebook.newREPL",
7475
"onRenderer:node-notebook-plot-renderer",
7576
"onRenderer:tensorflow-vis-renderer"
7677
],
@@ -87,6 +88,11 @@
8788
"command": "node.notebook.sample",
8889
"title": "Open a sample node.js notebook"
8990
},
91+
{
92+
"category": "Notebook",
93+
"command": "node.notebook.newREPL",
94+
"title": "Open node.js REPL"
95+
},
9096
{
9197
"category": "Notebook",
9298
"icon": "$(bug)",

src/extension/const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const notebookType = 'node-notebook';
2+
export const iwnotebookType = 'interactive';
23

34
const writingToConsoleOutputCompletdMarker = 'd1786f7c-d2ed-4a27-bd8a-ce19f704d111';
45

src/extension/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ShellKernel } from './kernel/shellKernel';
1111
import { JavaScriptKernel } from './kernel/jsKernel';
1212
import { Compiler } from './kernel/compiler';
1313
import { Samples } from './content/walkThrough';
14+
import { NodeRepl } from './kernel/repl';
1415

1516
export async function activate(context: ExtensionContext) {
1617
registerDisposableRegistry(context);
@@ -25,4 +26,5 @@ export async function activate(context: ExtensionContext) {
2526
PlotlyDownloadRenderer.register(context);
2627
ShellKernel.register(context);
2728
JavaScriptKernel.register(context);
29+
NodeRepl.register(context);
2830
}

src/extension/kernel/controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Uri,
99
workspace
1010
} from 'vscode';
11-
import { notebookType } from '../const';
11+
import { iwnotebookType, notebookType } from '../const';
1212
import { IDisposable } from '../types';
1313
import { disposeAllDisposables, registerDisposable } from '../utils';
1414
import { CellExecutionQueue } from './cellExecutionQueue';
@@ -21,15 +21,20 @@ export function isBrowserController(controller: NotebookController) {
2121
}
2222
export class Controller implements IDisposable {
2323
private static _tsNbController: NotebookController;
24+
private static _iwController: NotebookController;
2425
public static get nodeNotebookController(): NotebookController {
2526
return Controller._tsNbController;
2627
}
28+
public static get interactiveController(): NotebookController {
29+
return Controller._iwController;
30+
}
2731
private readonly disposables: IDisposable[] = [];
2832
public static regsiter() {
2933
registerDisposable(new Controller());
3034
}
3135
constructor() {
3236
Controller._tsNbController = this.createController(notebookType, 'node');
37+
Controller._iwController = this.createController(iwnotebookType, 'node');
3338
workspace.onDidOpenNotebookDocument(
3439
(e) => {
3540
if (e.notebookType === notebookType) {
@@ -45,6 +50,7 @@ export class Controller implements IDisposable {
4550
public dispose() {
4651
disposeAllDisposables(this.disposables);
4752
Controller._tsNbController.dispose();
53+
Controller._iwController.dispose();
4854
}
4955
private createController(nbType: string, type: 'node' | 'browser') {
5056
const controller = notebooks.createNotebookController(

src/extension/kernel/repl.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { commands, ExtensionContext, ViewColumn } from 'vscode';
2+
import { Controller } from '.';
3+
4+
export class NodeRepl {
5+
public static register(context: ExtensionContext) {
6+
context.subscriptions.push(
7+
commands.registerCommand('node.notebook.newREPL', async () => {
8+
await commands.executeCommand(
9+
'interactive.open',
10+
{ viewColumn: ViewColumn.Active, preserveFocus: false },
11+
undefined,
12+
Controller.interactiveController.id,
13+
'Node.js REPL'
14+
);
15+
await commands.executeCommand('notebook.selectKernel', {
16+
id: Controller.interactiveController.id,
17+
extension: 'donjayamanne.typescript-notebook'
18+
});
19+
})
20+
);
21+
}
22+
constructor() {}
23+
}

0 commit comments

Comments
 (0)