Skip to content

Commit

Permalink
Add support for REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Sep 25, 2021
1 parent ba5bfa3 commit c9d395a
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.0.4 (26 Sept 2021)
* Support for a REPL (Interactive Window) experience (https://github.com/DonJayamanne/typescript-notebook/issues/37)

## 2.0.3 (12 Sept 2021)
* Support for user input in notebooks using [readline](https://nodejs.org/api/readline.html#readline_readline_createinterface_options)
* Update samples to use `isomorphic-fetch` instead of `node-fetch` (and pre-requisite `npm` packages).
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ wowever, this extension leverages the power of Notebooks to provide the same ric
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.

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


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

## Roadmap
* Interactive Window experience
* Open a plain js/ts file as a notebook & vice versa.
* Better renderers for tabular data (arquero, danfo.js, etc)
* [Vega](https://vega.github.io/vega/) plots without having to install vega
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "typescript-notebook",
"displayName": "Node.js Notebooks",
"description": "Iterative & iteractive programming for Node.js in JavaScript/TypeScript, with great support for Tensorflow.js, debugging, & more..",
"version": "2.0.3",
"displayName": "Node.js Notebooks (REPL)",
"description": "Iterative & iteractive programming for Node.js in JavaScript/TypeScript (REPL), with great support for Tensorflow.js, debugging, & more..",
"version": "2.0.4",
"engines": {
"vscode": "^1.60.0"
},
Expand Down Expand Up @@ -71,6 +71,7 @@
"onCommand:node.notebook.sample.basics.debug",
"onCommand:node.notebook.sample.arquero.htmlOutput",
"onCommand:node.notebook.new",
"onCommand:node.notebook.newREPL",
"onRenderer:node-notebook-plot-renderer",
"onRenderer:tensorflow-vis-renderer"
],
Expand All @@ -87,6 +88,11 @@
"command": "node.notebook.sample",
"title": "Open a sample node.js notebook"
},
{
"category": "Notebook",
"command": "node.notebook.newREPL",
"title": "Open node.js REPL"
},
{
"category": "Notebook",
"icon": "$(bug)",
Expand Down
1 change: 1 addition & 0 deletions src/extension/const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const notebookType = 'node-notebook';
export const iwnotebookType = 'interactive';

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

Expand Down
2 changes: 2 additions & 0 deletions src/extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ShellKernel } from './kernel/shellKernel';
import { JavaScriptKernel } from './kernel/jsKernel';
import { Compiler } from './kernel/compiler';
import { Samples } from './content/walkThrough';
import { NodeRepl } from './kernel/repl';

export async function activate(context: ExtensionContext) {
registerDisposableRegistry(context);
Expand All @@ -25,4 +26,5 @@ export async function activate(context: ExtensionContext) {
PlotlyDownloadRenderer.register(context);
ShellKernel.register(context);
JavaScriptKernel.register(context);
NodeRepl.register(context);
}
8 changes: 7 additions & 1 deletion src/extension/kernel/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Uri,
workspace
} from 'vscode';
import { notebookType } from '../const';
import { iwnotebookType, notebookType } from '../const';
import { IDisposable } from '../types';
import { disposeAllDisposables, registerDisposable } from '../utils';
import { CellExecutionQueue } from './cellExecutionQueue';
Expand All @@ -21,15 +21,20 @@ export function isBrowserController(controller: NotebookController) {
}
export class Controller implements IDisposable {
private static _tsNbController: NotebookController;
private static _iwController: NotebookController;
public static get nodeNotebookController(): NotebookController {
return Controller._tsNbController;
}
public static get interactiveController(): NotebookController {
return Controller._iwController;
}
private readonly disposables: IDisposable[] = [];
public static regsiter() {
registerDisposable(new Controller());
}
constructor() {
Controller._tsNbController = this.createController(notebookType, 'node');
Controller._iwController = this.createController(iwnotebookType, 'node');
workspace.onDidOpenNotebookDocument(
(e) => {
if (e.notebookType === notebookType) {
Expand All @@ -45,6 +50,7 @@ export class Controller implements IDisposable {
public dispose() {
disposeAllDisposables(this.disposables);
Controller._tsNbController.dispose();
Controller._iwController.dispose();
}
private createController(nbType: string, type: 'node' | 'browser') {
const controller = notebooks.createNotebookController(
Expand Down
23 changes: 23 additions & 0 deletions src/extension/kernel/repl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { commands, ExtensionContext, ViewColumn } from 'vscode';
import { Controller } from '.';

export class NodeRepl {
public static register(context: ExtensionContext) {
context.subscriptions.push(
commands.registerCommand('node.notebook.newREPL', async () => {
await commands.executeCommand(
'interactive.open',
{ viewColumn: ViewColumn.Active, preserveFocus: false },
undefined,
Controller.interactiveController.id,
'Node.js REPL'
);
await commands.executeCommand('notebook.selectKernel', {
id: Controller.interactiveController.id,
extension: 'donjayamanne.typescript-notebook'
});
})
);
}
constructor() {}
}
Loading

0 comments on commit c9d395a

Please sign in to comment.