|
1 | 1 | import {KernelManagerImpl} from './kernel-manager'; |
2 | 2 | import {Kernel} from './kernel'; |
3 | 3 | import * as vscode from 'vscode'; |
4 | | -import {TextDocumentContentProvider} from './resultView'; |
5 | 4 | import {JupyterDisplay} from './display/main'; |
6 | 5 | import {KernelStatus} from './display/kernelStatus'; |
7 | 6 | import {Commands} from '../common/constants'; |
8 | 7 |
|
9 | | -const anser = require('anser'); |
| 8 | +// const anser = require('anser'); |
10 | 9 |
|
11 | | -const jupyterSchema = 'jupyter-result-viewer'; |
12 | | -const previewUri = vscode.Uri.parse(jupyterSchema + '://authority/jupyter'); |
13 | | - |
14 | | -let previewWindow: TextDocumentContentProvider; |
15 | | -let display: JupyterDisplay; |
16 | | -export function activate(): vscode.Disposable[] { |
17 | | - previewWindow = new TextDocumentContentProvider(); |
18 | | - let disposables: vscode.Disposable[] = []; |
19 | | - disposables.push(vscode.workspace.registerTextDocumentContentProvider(jupyterSchema, previewWindow)); |
20 | | - display = new JupyterDisplay(); |
21 | | - disposables.push(display); |
22 | | - return disposables; |
23 | | -} |
24 | | - |
25 | | -let displayed = false; |
26 | | -function showResults(result: string, data: any): any { |
27 | | - previewWindow.setText(result, data); |
28 | | - // Dirty hack to support instances when document has been closed |
29 | | - if (displayed) { |
30 | | - previewWindow.update(); |
31 | | - } |
32 | | - displayed = true; |
33 | | - return vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two, 'Results') |
34 | | - .then(() => { |
35 | | - if (displayed) { |
36 | | - previewWindow.update(); |
37 | | - } |
38 | | - }, reason => { |
39 | | - vscode.window.showErrorMessage(reason); |
40 | | - }); |
41 | | -} |
42 | 10 | export class Jupyter extends vscode.Disposable { |
43 | 11 | public kernelManager: KernelManagerImpl; |
44 | 12 | public kernel: Kernel = null; |
45 | 13 | private status: KernelStatus; |
46 | 14 | private disposables: vscode.Disposable[]; |
| 15 | + private display: JupyterDisplay; |
47 | 16 |
|
48 | 17 | constructor() { |
49 | 18 | super(() => { }); |
50 | 19 | this.disposables = []; |
51 | 20 | } |
52 | 21 | activate(state) { |
53 | | - this.disposables.push(...activate()); |
54 | 22 | this.kernelManager = new KernelManagerImpl(); |
55 | 23 | this.disposables.push(this.kernelManager); |
56 | 24 | this.disposables.push(vscode.window.onDidChangeActiveTextEditor(this.onEditorChanged.bind(this))); |
57 | 25 | this.status = new KernelStatus(); |
58 | 26 | this.disposables.push(this.status); |
| 27 | + this.display = new JupyterDisplay(); |
| 28 | + this.disposables.push(this.display); |
59 | 29 | } |
60 | 30 | public dispose() { |
61 | 31 | this.disposables.forEach(d => d.dispose()); |
@@ -95,39 +65,39 @@ export class Jupyter extends vscode.Disposable { |
95 | 65 | } |
96 | 66 | private executeAndDisplay(kernel: Kernel, code: string) { |
97 | 67 | return this.executeCodeInKernel(kernel, code).then(result => { |
98 | | - if (result[0].length === 0) { |
| 68 | + if (result[1].length === 0) { |
99 | 69 | return; |
100 | 70 | } |
101 | | - return showResults(result[0], result[1]); |
| 71 | + return this.display.showResults(result[0], result[1]); |
102 | 72 | }); |
103 | 73 | } |
104 | | - private executeCodeInKernel(kernel: Kernel, code: string): Promise<string> { |
105 | | - return new Promise<any>((resolve, reject) => { |
| 74 | + private executeCodeInKernel(kernel: Kernel, code: string): Promise<[string, any[]]> { |
| 75 | + return new Promise<[string, any[]]>((resolve, reject) => { |
106 | 76 | let htmlResponse = ''; |
107 | 77 | let responses = []; |
108 | 78 | return kernel.execute(code, (result: { type: string, stream: string, data: { [key: string]: string } | string }) => { |
109 | 79 | if ((result.type === 'text' && result.stream === 'stdout' && typeof result.data['text/plain'] === 'string') || |
110 | 80 | (result.type === 'text' && result.stream === 'pyout' && typeof result.data['text/plain'] === 'string') || |
111 | 81 | (result.type === 'text' && result.stream === 'error' && typeof result.data['text/plain'] === 'string')) { |
112 | | - const htmlText = anser.ansiToHtml(anser.escapeForHtml(result.data['text/plain'])); |
113 | | - htmlResponse = htmlResponse + `<p><pre>${htmlText}</pre></p>`; |
| 82 | + // const htmlText = anser.ansiToHtml(anser.escapeForHtml(result.data['text/plain'])); |
| 83 | + // htmlResponse = htmlResponse + `<p><pre>${htmlText}</pre></p>`; |
114 | 84 | responses.push(result.data); |
115 | 85 | if (result.stream === 'error') { |
116 | 86 | return resolve([htmlResponse, responses]); |
117 | 87 | } |
118 | 88 | } |
119 | 89 | if (result.type === 'text/html' && result.stream === 'pyout' && typeof result.data['text/html'] === 'string') { |
120 | | - htmlResponse = htmlResponse + result.data['text/html']; |
| 90 | + // htmlResponse = htmlResponse + result.data['text/html']; |
121 | 91 | result.data['text/html'] = result.data['text/html'].replace(/<\/script>/g, '</scripts>'); |
122 | 92 | responses.push(result.data); |
123 | 93 | } |
124 | 94 | if (result.type === 'application/javascript' && result.stream === 'pyout' && typeof result.data['application/javascript'] === 'string') { |
125 | 95 | responses.push(result.data); |
126 | | - htmlResponse = htmlResponse + `<script type="text/javascript">${result.data['application/javascript']}</script>`; |
| 96 | + // htmlResponse = htmlResponse + `<script type="text/javascript">${result.data['application/javascript']}</script>`; |
127 | 97 | } |
128 | 98 | if (result.type.startsWith('image/') && result.stream === 'pyout' && typeof result.data[result.type] === 'string') { |
129 | 99 | responses.push(result.data); |
130 | | - htmlResponse = htmlResponse + `<div style="background-color:white;display:inline-block;"><img src="data:${result.type};base64,${result.data[result.type]}" /></div><div></div>`; |
| 100 | + // htmlResponse = htmlResponse + `<div style="background-color:white;display:inline-block;"><img src="data:${result.type};base64,${result.data[result.type]}" /></div><div></div>`; |
131 | 101 | } |
132 | 102 | if (result.data === 'ok' && result.stream === 'status' && result.type === 'text') { |
133 | 103 | resolve([htmlResponse, responses]); |
|
0 commit comments