@@ -4,6 +4,8 @@ import * as vscode from 'vscode';
44import { JupyterDisplay } from './display/main' ;
55import { KernelStatus } from './display/kernelStatus' ;
66import { Commands } from '../common/constants' ;
7+ import { JupyterCodeLensProvider } from './editorIntegration/codeLensProvider' ;
8+ import { JupyterSymbolProvider } from './editorIntegration/symbolProvider' ;
79
810export class Jupyter extends vscode . Disposable {
911 public kernelManager : KernelManagerImpl ;
@@ -15,11 +17,15 @@ export class Jupyter extends vscode.Disposable {
1517 constructor ( private outputChannel : vscode . OutputChannel ) {
1618 super ( ( ) => { } ) ;
1719 this . disposables = [ ] ;
20+ this . registerCommands ( ) ;
21+ this . registerKernelCommands ( ) ;
1822 }
1923 activate ( state ) {
2024 this . kernelManager = new KernelManagerImpl ( this . outputChannel ) ;
2125 this . disposables . push ( this . kernelManager ) ;
2226 this . disposables . push ( vscode . window . onDidChangeActiveTextEditor ( this . onEditorChanged . bind ( this ) ) ) ;
27+ this . disposables . push ( vscode . languages . registerCodeLensProvider ( 'python' , new JupyterCodeLensProvider ( ) ) ) ;
28+ this . disposables . push ( vscode . languages . registerDocumentSymbolProvider ( 'python' , new JupyterSymbolProvider ( ) ) ) ;
2329 this . status = new KernelStatus ( ) ;
2430 this . disposables . push ( this . status ) ;
2531 this . display = new JupyterDisplay ( ) ;
@@ -74,27 +80,17 @@ export class Jupyter extends vscode.Disposable {
7480 let htmlResponse = '' ;
7581 let responses = [ ] ;
7682 return kernel . execute ( code , ( result : { type : string , stream : string , data : { [ key : string ] : string } | string } ) => {
77- if ( ( result . type === 'text' && result . stream === 'stdout' && typeof result . data [ 'text/plain' ] === 'string' ) ||
78- ( result . type === 'text' && result . stream === 'pyout' && typeof result . data [ 'text/plain' ] === 'string' ) ||
79- ( result . type === 'text' && result . stream === 'error' && typeof result . data [ 'text/plain' ] === 'string' ) ) {
80- responses . push ( result . data ) ;
81- if ( result . stream === 'error' ) {
82- return resolve ( [ htmlResponse , responses ] ) ;
83- }
84- }
85- if ( result . type === 'text/html' && result . stream === 'pyout' && typeof result . data [ 'text/html' ] === 'string' ) {
86- result . data [ 'text/html' ] = result . data [ 'text/html' ] . replace ( / < \/ s c r i p t > / g, '</scripts>' ) ;
87- responses . push ( result . data ) ;
88- }
89- if ( result . type === 'application/javascript' && result . stream === 'pyout' && typeof result . data [ 'application/javascript' ] === 'string' ) {
90- responses . push ( result . data ) ;
83+ if ( result . data === 'ok' && result . stream === 'status' && result . type === 'text' ) {
84+ return resolve ( [ htmlResponse , responses ] ) ;
9185 }
92- if ( result . type . startsWith ( 'image/' ) && result . stream === 'pyout ' && typeof result . data [ result . type ] === 'string ' ) {
86+ if ( result . stream === 'error ' && result . type === 'text ' ) {
9387 responses . push ( result . data ) ;
88+ return resolve ( [ htmlResponse , responses ] ) ;
9489 }
95- if ( result . data === 'ok' && result . stream === 'status' && result . type === 'text ') {
96- resolve ( [ htmlResponse , responses ] ) ;
90+ if ( typeof result . data [ 'text/html' ] === 'string ' ) {
91+ result . data [ 'text/html' ] = result . data [ 'text/html' ] . replace ( / < \/ s c r i p t > / g , '</scripts>' ) ;
9792 }
93+ responses . push ( result . data ) ;
9894 } ) ;
9995 } ) ;
10096 }
@@ -106,6 +102,16 @@ export class Jupyter extends vscode.Disposable {
106102 const code = activeEditor . document . getText ( vscode . window . activeTextEditor . selection ) ;
107103 this . executeCode ( code , activeEditor . document . languageId ) ;
108104 }
105+ private registerCommands ( ) {
106+ this . disposables . push ( vscode . commands . registerCommand ( Commands . Jupyter . ExecuteRangeInKernel , ( range : vscode . Range ) => {
107+ const activeEditor = vscode . window . activeTextEditor ;
108+ if ( ! activeEditor || ! activeEditor . document || ! range || range . isEmpty ) {
109+ return ;
110+ }
111+ const code = activeEditor . document . getText ( range ) ;
112+ this . executeCode ( code , activeEditor . document . languageId ) ;
113+ } ) ) ;
114+ }
109115 private registerKernelCommands ( ) {
110116 this . disposables . push ( vscode . commands . registerCommand ( Commands . Jupyter . Kernel . Kernel_Interrupt , ( ) => {
111117 this . kernel . interrupt ( ) ;
@@ -115,7 +121,7 @@ export class Jupyter extends vscode.Disposable {
115121 this . onKernelChanged ( kernel ) ;
116122 } ) ;
117123 } ) ) ;
118- this . disposables . push ( vscode . commands . registerCommand ( Commands . Jupyter . Kernel . Kernel_Interrupt , ( ) => {
124+ this . disposables . push ( vscode . commands . registerCommand ( Commands . Jupyter . Kernel . Kernel_Shut_Down , ( ) => {
119125 this . kernel . shutdown ( ) ;
120126 this . onKernelChanged ( ) ;
121127 } ) ) ;
0 commit comments