3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import 'vs/css!./notebookKernelActionViewItem ' ;
6
+ import { IAction } from 'vs/base/common/actions ' ;
7
7
import { groupBy } from 'vs/base/common/arrays' ;
8
8
import { createCancelablePromise } from 'vs/base/common/async' ;
9
9
import { CancellationToken } from 'vs/base/common/cancellation' ;
10
10
import { Codicon } from 'vs/base/common/codicons' ;
11
11
import { Event } from 'vs/base/common/event' ;
12
+ import { DisposableStore } from 'vs/base/common/lifecycle' ;
13
+ import { MarshalledId } from 'vs/base/common/marshallingIds' ;
12
14
import { compareIgnoreCase , uppercaseFirstLetter } from 'vs/base/common/strings' ;
15
+ import 'vs/css!./notebookKernelActionViewItem' ;
16
+ import { Command } from 'vs/editor/common/languages' ;
13
17
import { localize } from 'vs/nls' ;
18
+ import { MenuItemAction } from 'vs/platform/actions/common/actions' ;
19
+ import { ICommandService } from 'vs/platform/commands/common/commands' ;
14
20
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
15
- import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
16
21
import { ILabelService } from 'vs/platform/label/common/label' ;
17
22
import { ILogService } from 'vs/platform/log/common/log' ;
18
23
import { IProductService } from 'vs/platform/product/common/productService' ;
19
24
import { ProgressLocation } from 'vs/platform/progress/common/progress' ;
20
25
import { IQuickInputService , IQuickPick , IQuickPickItem , QuickPickInput } from 'vs/platform/quickinput/common/quickInput' ;
26
+ import { ThemeIcon } from 'vs/platform/theme/common/themeService' ;
21
27
import { ViewContainerLocation } from 'vs/workbench/common/views' ;
22
28
import { IExtensionsViewPaneContainer , IExtensionsWorkbenchService , VIEWLET_ID as EXTENSION_VIEWLET_ID } from 'vs/workbench/contrib/extensions/common/extensions' ;
23
- import { getNotebookEditorFromEditorPane , INotebookEditor , INotebookExtensionRecommendation , JUPYTER_EXTENSION_ID , KERNEL_RECOMMENDATIONS } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
29
+ import { IActiveNotebookEditor , INotebookExtensionRecommendation , JUPYTER_EXTENSION_ID , KERNEL_RECOMMENDATIONS } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
24
30
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget' ;
31
+ import { executingStateIcon , selectKernelIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons' ;
25
32
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel' ;
26
33
import { INotebookKernel , INotebookKernelHistoryService , INotebookKernelMatchResult , INotebookKernelService , ISourceAction } from 'vs/workbench/contrib/notebook/common/notebookKernelService' ;
27
- import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
28
34
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
29
35
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite' ;
30
- import { Command } from 'vs/editor/common/languages' ;
31
- import { ICommandService } from 'vs/platform/commands/common/commands' ;
32
- import { DisposableStore } from 'vs/base/common/lifecycle' ;
33
- import { MarshalledId } from 'vs/base/common/marshallingIds' ;
34
- import { IAction } from 'vs/base/common/actions' ;
35
- import { ThemeIcon } from 'vs/platform/theme/common/themeService' ;
36
- import { executingStateIcon , selectKernelIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons' ;
37
- import { MenuItemAction } from 'vs/platform/actions/common/actions' ;
38
36
39
37
type KernelPick = IQuickPickItem & { kernel : INotebookKernel } ;
40
38
function isKernelPick ( item : QuickPickInput < IQuickPickItem > ) : item is KernelPick {
@@ -49,6 +47,9 @@ function isInstallExtensionPick(item: QuickPickInput<IQuickPickItem>): item is I
49
47
return item . id === 'installSuggested' && 'extensionId' in item ;
50
48
}
51
49
type KernelSourceQuickPickItem = IQuickPickItem & { command : Command } ;
50
+ function isKernelSourceQuickPickItem ( item : IQuickPickItem ) : item is KernelSourceQuickPickItem {
51
+ return 'command' in item ;
52
+ }
52
53
type KernelQuickPickItem = IQuickPickItem | InstallExtensionPick | KernelPick | SourcePick | KernelSourceQuickPickItem ;
53
54
const KERNEL_PICKER_UPDATE_DEBOUNCE = 200 ;
54
55
@@ -59,25 +60,7 @@ export type KernelQuickPickContext =
59
60
{ ui ?: boolean ; notebookEditor ?: NotebookEditorWidget } ;
60
61
61
62
export interface IKernelPickerStrategy {
62
- showQuickPick ( context ?: KernelQuickPickContext ) : Promise < boolean > ;
63
- }
64
-
65
- function getEditorFromContext ( editorService : IEditorService , context ?: KernelQuickPickContext ) : INotebookEditor | undefined {
66
- let editor : INotebookEditor | undefined ;
67
- if ( context !== undefined && 'notebookEditorId' in context ) {
68
- const editorId = context . notebookEditorId ;
69
- const matchingEditor = editorService . visibleEditorPanes . find ( ( editorPane ) => {
70
- const notebookEditor = getNotebookEditorFromEditorPane ( editorPane ) ;
71
- return notebookEditor ?. getId ( ) === editorId ;
72
- } ) ;
73
- editor = getNotebookEditorFromEditorPane ( matchingEditor ) ;
74
- } else if ( context !== undefined && 'notebookEditor' in context ) {
75
- editor = context ?. notebookEditor ;
76
- } else {
77
- editor = getNotebookEditorFromEditorPane ( editorService . activeEditorPane ) ;
78
- }
79
-
80
- return editor ;
63
+ showQuickPick ( editor : IActiveNotebookEditor , wantedKernelId ?: string ) : Promise < boolean > ;
81
64
}
82
65
83
66
function toQuickPick ( kernel : INotebookKernel , selected : INotebookKernel | undefined ) {
@@ -102,7 +85,6 @@ function toQuickPick(kernel: INotebookKernel, selected: INotebookKernel | undefi
102
85
abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
103
86
constructor (
104
87
protected readonly _notebookKernelService : INotebookKernelService ,
105
- protected readonly _editorService : IEditorService ,
106
88
protected readonly _productService : IProductService ,
107
89
protected readonly _quickInputService : IQuickInputService ,
108
90
protected readonly _labelService : ILabelService ,
@@ -113,34 +95,14 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
113
95
protected readonly _commandService : ICommandService
114
96
) { }
115
97
116
- async showQuickPick ( context ?: KernelQuickPickContext ) : Promise < boolean > {
117
- const editor = getEditorFromContext ( this . _editorService , context ) ;
118
-
119
- if ( ! editor || ! editor . hasModel ( ) ) {
120
- return false ;
121
- }
122
- let controllerId = context && 'id' in context ? context . id : undefined ;
123
- let extensionId = context && 'extension' in context ? context . extension : undefined ;
124
-
125
- if ( controllerId && ( typeof controllerId !== 'string' || typeof extensionId !== 'string' ) ) {
126
- // validate context: id & extension MUST be strings
127
- controllerId = undefined ;
128
- extensionId = undefined ;
129
- }
130
-
98
+ async showQuickPick ( editor : IActiveNotebookEditor , wantedId ?: string ) : Promise < boolean > {
131
99
const notebook = editor . textModel ;
132
100
const scopedContextKeyService = editor . scopedContextKeyService ;
133
101
const matchResult = this . _getMatchingResult ( notebook ) ;
134
102
const { selected, all } = matchResult ;
135
103
136
- if ( selected && controllerId && selected . id === controllerId && ExtensionIdentifier . equals ( selected . extension , extensionId ) ) {
137
- // current kernel is wanted kernel -> done
138
- return true ;
139
- }
140
-
141
104
let newKernel : INotebookKernel | undefined ;
142
- if ( controllerId ) {
143
- const wantedId = `${ extensionId } /${ controllerId } ` ;
105
+ if ( wantedId ) {
144
106
for ( const candidate of all ) {
145
107
if ( candidate . id === wantedId ) {
146
108
newKernel = candidate ;
@@ -239,7 +201,7 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
239
201
} ) ;
240
202
241
203
if ( pick ) {
242
- return await this . _handleQuickPick ( notebook , pick , context , editor . scopedContextKeyService ) ;
204
+ return await this . _handleQuickPick ( editor , pick ) ;
243
205
}
244
206
245
207
return false ;
@@ -256,10 +218,10 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
256
218
scopedContextKeyService : IContextKeyService
257
219
) : QuickPickInput < KernelQuickPickItem > [ ] ;
258
220
259
- protected async _handleQuickPick ( notebook : NotebookTextModel , pick : KernelQuickPickItem , context ?: KernelQuickPickContext , contextKeyService ?: IContextKeyService ) {
221
+ protected async _handleQuickPick ( editor : IActiveNotebookEditor , pick : KernelQuickPickItem ) {
260
222
if ( isKernelPick ( pick ) ) {
261
223
const newKernel = pick . kernel ;
262
- this . _selecteKernel ( notebook , newKernel ) ;
224
+ this . _selecteKernel ( editor . textModel , newKernel ) ;
263
225
return true ;
264
226
}
265
227
@@ -269,15 +231,15 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
269
231
this . _paneCompositePartService ,
270
232
this . _extensionWorkbenchService ,
271
233
this . _extensionService ,
272
- notebook . viewType
234
+ editor . textModel . viewType
273
235
) ;
274
236
// suggestedExtension must be defined for this option to be shown, but still check to make TS happy
275
237
} else if ( isInstallExtensionPick ( pick ) ) {
276
238
await this . _showKernelExtension (
277
239
this . _paneCompositePartService ,
278
240
this . _extensionWorkbenchService ,
279
241
this . _extensionService ,
280
- notebook . viewType ,
242
+ editor . textModel . viewType ,
281
243
pick . extensionId ,
282
244
this . _productService . quality !== 'stable'
283
245
) ;
@@ -417,7 +379,6 @@ export class KernelPickerFlatStrategy extends KernelPickerStrategyBase {
417
379
418
380
constructor (
419
381
@INotebookKernelService _notebookKernelService : INotebookKernelService ,
420
- @IEditorService _editorService : IEditorService ,
421
382
@IProductService _productService : IProductService ,
422
383
@IQuickInputService _quickInputService : IQuickInputService ,
423
384
@ILabelService _labelService : ILabelService ,
@@ -430,7 +391,6 @@ export class KernelPickerFlatStrategy extends KernelPickerStrategyBase {
430
391
) {
431
392
super (
432
393
_notebookKernelService ,
433
- _editorService ,
434
394
_productService ,
435
395
_quickInputService ,
436
396
_labelService ,
@@ -475,15 +435,15 @@ export class KernelPickerFlatStrategy extends KernelPickerStrategyBase {
475
435
// label: localize('sourceActions', "")
476
436
} ) ;
477
437
478
- sourceActions . forEach ( sourceAction => {
479
- const res = < SourcePick > {
438
+ for ( const sourceAction of sourceActions ) {
439
+ const res : SourcePick = {
480
440
action : sourceAction ,
481
441
picked : false ,
482
442
label : sourceAction . action . label ,
483
443
} ;
484
444
485
445
quickPickItems . push ( res ) ;
486
- } ) ;
446
+ }
487
447
}
488
448
489
449
return quickPickItems ;
@@ -575,7 +535,6 @@ export class KernelPickerFlatStrategy extends KernelPickerStrategyBase {
575
535
export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
576
536
constructor (
577
537
@INotebookKernelService _notebookKernelService : INotebookKernelService ,
578
- @IEditorService _editorService : IEditorService ,
579
538
@IProductService _productService : IProductService ,
580
539
@IQuickInputService _quickInputService : IQuickInputService ,
581
540
@ILabelService _labelService : ILabelService ,
@@ -589,7 +548,6 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
589
548
) {
590
549
super (
591
550
_notebookKernelService ,
592
- _editorService ,
593
551
_productService ,
594
552
_quickInputService ,
595
553
_labelService ,
@@ -659,15 +617,16 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
659
617
} ;
660
618
}
661
619
662
- protected override async _handleQuickPick ( notebook : NotebookTextModel , pick : KernelQuickPickItem , context ?: KernelQuickPickContext , contextKeyService ?: IContextKeyService ) : Promise < boolean > {
620
+ protected override async _handleQuickPick ( editor : IActiveNotebookEditor , pick : KernelQuickPickItem ) : Promise < boolean > {
663
621
if ( pick . id === 'selectAnother' ) {
664
- return this . displaySelectAnotherQuickPick ( notebook , context ) ;
622
+ return this . displaySelectAnotherQuickPick ( editor ) ;
665
623
}
666
624
667
- return super . _handleQuickPick ( notebook , pick , context ) ;
625
+ return super . _handleQuickPick ( editor , pick ) ;
668
626
}
669
627
670
- private async displaySelectAnotherQuickPick ( notebook : NotebookTextModel , context ?: KernelQuickPickContext , contextKeyService ?: IContextKeyService ) {
628
+ private async displaySelectAnotherQuickPick ( editor : IActiveNotebookEditor ) {
629
+ const notebook : NotebookTextModel = editor . textModel ;
671
630
const disposables = new DisposableStore ( ) ;
672
631
return new Promise < boolean > ( resolve => {
673
632
// select from kernel sources
@@ -681,14 +640,14 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
681
640
disposables . add ( quickPick . onDidTriggerButton ( button => {
682
641
if ( button === this . _quickInputService . backButton ) {
683
642
quickPick . hide ( ) ;
684
- resolve ( this . showQuickPick ( context ) ) ;
643
+ resolve ( this . showQuickPick ( editor ) ) ;
685
644
}
686
645
} ) ) ;
687
646
disposables . add ( quickPick . onDidAccept ( async ( ) => {
688
647
quickPick . hide ( ) ;
689
648
quickPick . dispose ( ) ;
690
649
if ( quickPick . selectedItems ) {
691
- if ( 'command' in quickPick . selectedItems [ 0 ] ) {
650
+ if ( isKernelSourceQuickPickItem ( quickPick . selectedItems [ 0 ] ) ) {
692
651
const selectedKernelId = await this . _executeCommand < string > ( notebook , quickPick . selectedItems [ 0 ] . command ) ;
693
652
if ( selectedKernelId ) {
694
653
const { all } = await this . _getMatchingResult ( notebook ) ;
@@ -699,7 +658,7 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
699
658
}
700
659
resolve ( true ) ;
701
660
} else {
702
- return resolve ( this . displaySelectAnotherQuickPick ( notebook , context , contextKeyService ) ) ;
661
+ return resolve ( this . displaySelectAnotherQuickPick ( editor ) ) ;
703
662
}
704
663
} else if ( isKernelPick ( quickPick . selectedItems [ 0 ] ) ) {
705
664
await this . _selecteKernel ( notebook , quickPick . selectedItems [ 0 ] . kernel ) ;
@@ -732,17 +691,17 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
732
691
} ;
733
692
} ) ) ;
734
693
735
- const sourceActionCommands = this . _notebookKernelService . getSourceActions ( notebook , contextKeyService ) ;
736
- sourceActionCommands . forEach ( sourceAction => {
737
- const res = < SourcePick > {
694
+ const sourceActionCommands = this . _notebookKernelService . getSourceActions ( notebook , editor . scopedContextKeyService ) ;
695
+ for ( const sourceAction of sourceActionCommands ) {
696
+ const res : SourcePick = {
738
697
action : sourceAction ,
739
698
picked : false ,
740
699
label : sourceAction . action . label ,
741
700
detail : ( sourceAction . action as MenuItemAction ) ?. item ?. source
742
701
} ;
743
702
744
703
quickPickItems . push ( res ) ;
745
- } ) ;
704
+ }
746
705
747
706
quickPick . items = quickPickItems ;
748
707
} ) ;
0 commit comments