@@ -12,26 +12,53 @@ import * as telemetryHelper from '../common/telemetry';
1212import * as telemetryContracts from '../common/telemetryContracts' ;
1313import * as main from './jupyter_client/main' ;
1414import { KernelRestartedError , KernelShutdownError } from './common/errors' ;
15+ import { PythonSettings } from '../common/configSettings' ;
1516
16- // Todo: Refactor the error handling and displaying of messages
17+ const pythonSettings = PythonSettings . getInstance ( ) ;
1718
19+ // Todo: Refactor the error handling and displaying of messages
1820export class Jupyter extends vscode . Disposable {
1921 public kernelManager : KernelManagerImpl ;
2022 public kernel : Kernel = null ;
2123 private status : KernelStatus ;
2224 private disposables : vscode . Disposable [ ] ;
2325 private display : JupyterDisplay ;
2426 private codeLensProvider : JupyterCodeLensProvider ;
25- constructor ( private outputChannel : vscode . OutputChannel ) {
27+ private lastUsedPythonPath : string ;
28+ constructor ( private outputChannel : vscode . OutputChannel , private rootPath : string ) {
2629 super ( ( ) => { } ) ;
2730 this . disposables = [ ] ;
2831 this . registerCommands ( ) ;
2932 this . registerKernelCommands ( ) ;
33+
34+ pythonSettings . on ( 'change' , this . onConfigurationChanged . bind ( this ) ) ;
35+ this . lastUsedPythonPath = pythonSettings . pythonPath ;
36+ }
37+ private onConfigurationChanged ( ) {
38+ if ( this . lastUsedPythonPath === pythonSettings . pythonPath ) {
39+ return ;
40+ }
41+ this . kernelManager . dispose ( ) ;
42+ this . createKernelManager ( ) ;
43+ }
44+ public dispose ( ) {
45+ this . kernelManager . dispose ( ) ;
46+ this . disposables . forEach ( d => d . dispose ( ) ) ;
3047 }
31- activate ( rootPath : string ) {
32- const jupyterClient = new main . JupyterClientAdapter ( this . outputChannel , rootPath ) ;
48+ private createKernelManager ( ) {
49+ const jupyterClient = new main . JupyterClientAdapter ( this . outputChannel , this . rootPath ) ;
3350 this . kernelManager = new KernelManagerImpl ( this . outputChannel , jupyterClient ) ;
34- this . disposables . push ( this . kernelManager ) ;
51+
52+ // This happend when user changes it from status bar
53+ this . kernelManager . on ( 'kernelChanged' , ( kernel : Kernel , language : string ) => {
54+ if ( this . kernel !== kernel && ( this . kernel && this . kernel . kernelSpec . language === kernel . kernelSpec . language ) ) {
55+ this . onKernelChanged ( kernel ) ;
56+ }
57+ } ) ;
58+ }
59+ activate ( ) {
60+ this . createKernelManager ( ) ;
61+
3562 this . disposables . push ( vscode . window . onDidChangeActiveTextEditor ( this . onEditorChanged . bind ( this ) ) ) ;
3663 this . codeLensProvider = new JupyterCodeLensProvider ( ) ;
3764 this . disposables . push ( vscode . languages . registerCodeLensProvider ( PythonLanguage , this . codeLensProvider ) ) ;
@@ -40,13 +67,6 @@ export class Jupyter extends vscode.Disposable {
4067 this . disposables . push ( this . status ) ;
4168 this . display = new JupyterDisplay ( this . codeLensProvider ) ;
4269 this . disposables . push ( this . display ) ;
43-
44- // This happend when user changes it from status bar
45- this . kernelManager . on ( 'kernelChanged' , ( kernel : Kernel , language : string ) => {
46- if ( this . kernel !== kernel && ( this . kernel && this . kernel . kernelSpec . language === kernel . kernelSpec . language ) ) {
47- this . onKernelChanged ( kernel ) ;
48- }
49- } ) ;
5070 }
5171 public hasCodeCells ( document : vscode . TextDocument , token : vscode . CancellationToken ) : Promise < boolean > {
5272 return new Promise < boolean > ( resolve => {
@@ -59,9 +79,6 @@ export class Jupyter extends vscode.Disposable {
5979 } ) ;
6080 } ) ;
6181 }
62- public dispose ( ) {
63- this . disposables . forEach ( d => d . dispose ( ) ) ;
64- }
6582 private onEditorChanged ( editor : vscode . TextEditor ) {
6683 if ( ! editor || ! editor . document ) {
6784 return ;
0 commit comments