@@ -22,14 +22,14 @@ import * as localize from '../common/utils/localize';
22
22
import { IInterpreterService } from '../interpreter/contracts' ;
23
23
import { captureTelemetry , sendTelemetryEvent } from '../telemetry' ;
24
24
import { HistoryMessages , Telemetry } from './constants' ;
25
- import { CellState , ICell , ICodeCssGenerator , IHistory , INotebookServer , IStatusProvider } from './types' ;
25
+ import { JupyterInstallError } from './jupyterInstallError' ;
26
+ import { CellState , ICell , ICodeCssGenerator , IHistory , IJupyterExecution , INotebookServer , IStatusProvider } from './types' ;
26
27
27
28
@injectable ( )
28
29
export class History implements IWebPanelMessageListener , IHistory {
29
30
private disposed : boolean = false ;
30
31
private webPanel : IWebPanel | undefined ;
31
- // tslint:disable-next-line: no-any
32
- private loadPromise : Promise < any > ;
32
+ private loadPromise : Promise < void > ;
33
33
private settingsChangedDisposable : Disposable ;
34
34
private closedEvent : EventEmitter < IHistory > ;
35
35
private unfinishedCells : ICell [ ] = [ ] ;
@@ -44,7 +44,8 @@ export class History implements IWebPanelMessageListener, IHistory {
44
44
@inject ( IWebPanelProvider ) private provider : IWebPanelProvider ,
45
45
@inject ( IDisposableRegistry ) private disposables : IDisposableRegistry ,
46
46
@inject ( ICodeCssGenerator ) private cssGenerator : ICodeCssGenerator ,
47
- @inject ( IStatusProvider ) private statusProvider : IStatusProvider ) {
47
+ @inject ( IStatusProvider ) private statusProvider : IStatusProvider ,
48
+ @inject ( IJupyterExecution ) private jupyterExecution : IJupyterExecution ) {
48
49
49
50
// Sign up for configuration changes
50
51
this . settingsChangedDisposable = this . interpreterService . onDidChangeInterpreter ( this . onSettingsChanged ) ;
@@ -63,7 +64,7 @@ export class History implements IWebPanelMessageListener, IHistory {
63
64
await this . loadPromise ;
64
65
65
66
// Then show our web panel.
66
- if ( this . webPanel ) {
67
+ if ( this . webPanel && this . jupyterServer ) {
67
68
await this . webPanel . show ( ) ;
68
69
}
69
70
}
@@ -77,29 +78,38 @@ export class History implements IWebPanelMessageListener, IHistory {
77
78
// Start a status item
78
79
const status = this . setStatus ( localize . DataScience . executingCode ( ) ) ;
79
80
80
- // Make sure we're loaded first.
81
- await this . loadPromise ;
81
+ try {
82
+ // Make sure we're loaded first.
83
+ await this . loadPromise ;
82
84
83
- // Then show our webpanel
84
- await this . show ( ) ;
85
+ // Then show our webpanel
86
+ await this . show ( ) ;
85
87
86
- if ( this . jupyterServer ) {
87
- // Attempt to evaluate this cell in the jupyter notebook
88
- const observable = this . jupyterServer . executeObservable ( code , file , line ) ;
89
-
90
- // Sign up for cell changes
91
- observable . subscribe (
92
- ( cells : ICell [ ] ) => {
93
- this . onAddCodeEvent ( cells , editor ) ;
94
- } ,
95
- ( error ) => {
96
- status . dispose ( ) ;
97
- this . applicationShell . showErrorMessage ( error ) ;
98
- } ,
99
- ( ) => {
100
- // Indicate executing until this cell is done.
101
- status . dispose ( ) ;
102
- } ) ;
88
+ if ( this . jupyterServer ) {
89
+ // Attempt to evaluate this cell in the jupyter notebook
90
+ const observable = this . jupyterServer . executeObservable ( code , file , line ) ;
91
+
92
+ // Sign up for cell changes
93
+ observable . subscribe (
94
+ ( cells : ICell [ ] ) => {
95
+ this . onAddCodeEvent ( cells , editor ) ;
96
+ } ,
97
+ ( error ) => {
98
+ status . dispose ( ) ;
99
+ this . applicationShell . showErrorMessage ( error ) ;
100
+ } ,
101
+ ( ) => {
102
+ // Indicate executing until this cell is done.
103
+ status . dispose ( ) ;
104
+ } ) ;
105
+ }
106
+ } catch ( err ) {
107
+ status . dispose ( ) ;
108
+
109
+ // We failed, dispose of ourselves too so that nobody uses us again
110
+ this . dispose ( ) ;
111
+
112
+ throw err ;
103
113
}
104
114
}
105
115
@@ -366,10 +376,14 @@ export class History implements IWebPanelMessageListener, IHistory {
366
376
this . webPanel = this . provider . create ( this , localize . DataScience . historyTitle ( ) , mainScriptPath , css ) ;
367
377
}
368
378
369
- private load = ( ) : Promise < [ void , void ] > => {
370
- return Promise . all ( [
371
- this . loadWebPanel ( ) ,
372
- this . loadJupyterServer ( )
373
- ] ) ;
379
+ private load = async ( ) : Promise < void > => {
380
+
381
+ // Check to see if we support jupyter or not. If not quick fail
382
+ if ( ! ( await this . jupyterExecution . isImportSupported ( ) ) ) {
383
+ throw new JupyterInstallError ( localize . DataScience . jupyterNotSupported ( ) , localize . DataScience . pythonInteractiveHelpLink ( ) ) ;
384
+ }
385
+
386
+ // Otherwise wait for both
387
+ await Promise . all ( [ this . loadJupyterServer ( ) , this . loadWebPanel ( ) ] ) ;
374
388
}
375
389
}
0 commit comments