@@ -14,49 +14,48 @@ import { IJupyterCommand, IJupyterKernelSpec, IJupyterSessionManager } from '../
14
14
import { JupyterCommandFinder , ModuleExistsStatus } from '../jupyterCommandFinder' ;
15
15
import { KernelSelectionProvider } from './kernelSelections' ;
16
16
import { KernelService } from './kernelService' ;
17
+ import { IKernelSelector } from './types' ;
17
18
18
19
@injectable ( )
19
- export class KernelSelector {
20
+ export class KernelSelector implements IKernelSelector {
20
21
constructor (
21
22
@inject ( KernelSelectionProvider ) private readonly selectionProvider : KernelSelectionProvider ,
22
23
@inject ( IApplicationShell ) private readonly applicationShell : IApplicationShell ,
23
24
@inject ( JupyterCommandFinder ) private readonly cmdFinder : JupyterCommandFinder ,
24
25
@inject ( KernelService ) private readonly kernelService : KernelService ,
25
26
@inject ( IInstaller ) private readonly installer : IInstaller
26
27
) { }
27
- public async selectKernel (
28
- options : { session ?: IJupyterSessionManager } | { session : IJupyterSessionManager ; isRemoteConnection : true } ,
29
- cancelToken ?: CancellationToken
30
- ) : Promise < IJupyterKernelSpec | undefined > {
31
- const suggestions =
32
- 'isRemoteConnection' in options
33
- ? this . selectionProvider . getKernelSelectionsForRemoteSession ( options . session )
34
- : this . selectionProvider . getLocalKernelSelectionProvider ( options . session ) ;
35
-
36
- const selection = await this . applicationShell . showQuickPick ( suggestions ) ;
28
+ public async selectRemoteKernel ( session : IJupyterSessionManager , cancelToken ?: CancellationToken ) : Promise < IJupyterKernelSpec | undefined > {
29
+ const suggestions = this . selectionProvider . getKernelSelectionsForRemoteSession ( session , cancelToken ) ;
30
+ const selection = await this . applicationShell . showQuickPick ( suggestions , undefined , cancelToken ) ;
37
31
if ( ! selection ) {
38
32
return ;
39
33
}
40
34
41
35
// Nothing to validate if this is a remote connection.
42
- if ( 'isRemoteConnection' in options ) {
43
- if ( 'kernelSpec' in selection . selection ) {
44
- return selection . selection . kernelSpec ;
45
- }
46
- // This is not possible.
47
- throw new Error ( 'Invalid Selection in kernel spec' ) ;
36
+ if ( ! selection . selection . kernelSpec ) {
37
+ return selection . selection . kernelSpec ;
38
+ }
39
+ // This is not possible (remote kernels selector can only display remote kernels).
40
+ throw new Error ( 'Invalid Selection in kernel spec (somehow a local kernel/interpreter has been selected for a remote session!' ) ;
41
+ }
42
+
43
+ public async selectLocalKernel ( session ?: IJupyterSessionManager , cancelToken ?: CancellationToken ) : Promise < IJupyterKernelSpec | undefined > {
44
+ const suggestions = this . selectionProvider . getLocalKernelSelectionProvider ( session , cancelToken ) ;
45
+ const selection = await this . applicationShell . showQuickPick ( suggestions , undefined , cancelToken ) ;
46
+ if ( ! selection ) {
47
+ return ;
48
48
}
49
49
50
50
// Check if ipykernel is installed in this kernel.
51
- if ( 'interpreter' in selection . selection ) {
52
- const interpreter = selection . selection . interpreter ;
53
- const isValid = await this . isSelectionValid ( interpreter , cancelToken ) ;
51
+ if ( selection . selection . interpreter ) {
52
+ const isValid = await this . isSelectionValid ( selection . selection . interpreter , cancelToken ) ;
54
53
if ( ! isValid ) {
55
54
return ;
56
55
}
57
56
58
57
// Try an install this interpreter as a kernel.
59
- return this . kernelService . registerKernel ( interpreter , cancelToken ) ;
58
+ return this . kernelService . registerKernel ( selection . selection . interpreter , cancelToken ) ;
60
59
} else {
61
60
return selection . selection . kernelSpec ;
62
61
}
0 commit comments