forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplController.ts
More file actions
40 lines (32 loc) · 1.29 KB
/
Copy pathreplController.ts
File metadata and controls
40 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as vscode from 'vscode';
import { createPythonServer } from './pythonServer';
export function createReplController(
interpreterPath: string,
disposables: vscode.Disposable[],
cwd?: string,
): vscode.NotebookController {
const server = createPythonServer([interpreterPath], cwd);
disposables.push(server);
const controller = vscode.notebooks.createNotebookController('pythonREPL', 'jupyter-notebook', 'Python REPL');
controller.supportedLanguages = ['python'];
controller.description = 'Python REPL';
controller.interruptHandler = async () => {
server.interrupt();
};
controller.executeHandler = async (cells) => {
for (const cell of cells) {
const exec = controller.createNotebookCellExecution(cell);
exec.start(Date.now());
const result = await server.execute(cell.document.getText());
if (result?.output) {
exec.replaceOutput([
new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.text(result.output, 'text/plain')]),
]);
// TODO: Properly update via NotebookCellOutputItem.error later.
}
exec.end(result?.status);
}
};
disposables.push(controller);
return controller;
}