@@ -12,9 +12,9 @@ import { mock } from 'vs/base/test/common/mock';
12
12
import { assertThrowsAsync } from 'vs/base/test/common/utils' ;
13
13
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry' ;
14
14
import { IMenu , IMenuService } from 'vs/platform/actions/common/actions' ;
15
+ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
15
16
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
16
17
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock' ;
17
- import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService' ;
18
18
import { insertCellAtIndex } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations' ;
19
19
import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl' ;
20
20
import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl' ;
@@ -29,6 +29,7 @@ import { setupInstantiationService, withTestNotebook as _withTestNotebook } from
29
29
suite ( 'NotebookExecutionService' , ( ) => {
30
30
31
31
let instantiationService : TestInstantiationService ;
32
+ let contextKeyService : IContextKeyService ;
32
33
let kernelService : INotebookKernelService ;
33
34
let disposables : DisposableStore ;
34
35
@@ -56,6 +57,7 @@ suite('NotebookExecutionService', () => {
56
57
57
58
kernelService = instantiationService . createInstance ( NotebookKernelService ) ;
58
59
instantiationService . set ( INotebookKernelService , kernelService ) ;
60
+ contextKeyService = instantiationService . get ( IContextKeyService ) ;
59
61
60
62
} ) ;
61
63
@@ -77,48 +79,48 @@ suite('NotebookExecutionService', () => {
77
79
test ( 'cell is not runnable when no kernel is selected' , async ( ) => {
78
80
await withTestNotebook (
79
81
[ ] ,
80
- async ( viewModel ) => {
82
+ async ( viewModel , textModel ) => {
81
83
const executionService = instantiationService . createInstance ( NotebookExecutionService ) ;
82
84
83
85
const cell = insertCellAtIndex ( viewModel , 1 , 'var c = 3' , 'javascript' , CellKind . Code , { } , [ ] , true , true ) ;
84
- await assertThrowsAsync ( async ( ) => await executionService . executeNotebookCell ( cell ) ) ;
86
+ await assertThrowsAsync ( async ( ) => await executionService . executeNotebookCells ( textModel , [ cell . model ] , contextKeyService ) ) ;
85
87
} ) ;
86
88
} ) ;
87
89
88
90
test ( 'cell is not runnable when kernel does not support the language' , async ( ) => {
89
91
await withTestNotebook (
90
92
[ ] ,
91
- async ( viewModel ) => {
93
+ async ( viewModel , textModel ) => {
92
94
93
95
kernelService . registerKernel ( new TestNotebookKernel ( { languages : [ 'testlang' ] } ) ) ;
94
96
const executionService = instantiationService . createInstance ( NotebookExecutionService ) ;
95
97
const cell = insertCellAtIndex ( viewModel , 1 , 'var c = 3' , 'javascript' , CellKind . Code , { } , [ ] , true , true ) ;
96
- await assertThrowsAsync ( async ( ) => await executionService . executeNotebookCell ( cell ) ) ;
98
+ await assertThrowsAsync ( async ( ) => await executionService . executeNotebookCells ( textModel , [ cell . model ] , contextKeyService ) ) ;
97
99
98
100
} ) ;
99
101
} ) ;
100
102
101
103
test ( 'cell is runnable when kernel does support the language' , async ( ) => {
102
104
await withTestNotebook (
103
105
[ ] ,
104
- async ( viewModel ) => {
106
+ async ( viewModel , textModel ) => {
105
107
const kernel = new TestNotebookKernel ( { languages : [ 'javascript' ] } ) ;
106
108
kernelService . registerKernel ( kernel ) ;
107
109
const executionService = instantiationService . createInstance ( NotebookExecutionService ) ;
108
110
const executeSpy = sinon . spy ( ) ;
109
111
kernel . executeNotebookCellsRequest = executeSpy ;
110
112
111
113
const cell = insertCellAtIndex ( viewModel , 0 , 'var c = 3' , 'javascript' , CellKind . Code , { } , [ ] , true , true ) ;
112
- await executionService . executeNotebookCells ( viewModel . notebookDocument , [ cell ] , new MockContextKeyService ( ) ) ;
114
+ await executionService . executeNotebookCells ( viewModel . notebookDocument , [ cell . model ] , contextKeyService ) ;
113
115
assert . strictEqual ( executeSpy . calledOnce , true ) ;
114
116
} ) ;
115
117
} ) ;
116
118
117
119
test ( 'select kernel when running cell' , async function ( ) {
118
120
// https://github.com/microsoft/vscode/issues/121904
119
121
120
- return withTestNotebook ( [ ] , async viewModel => {
121
- assert . strictEqual ( kernelService . getMatchingKernel ( viewModel . notebookDocument ) . all . length , 0 ) ;
122
+ return withTestNotebook ( [ ] , async ( viewModel , textModel ) => {
123
+ assert . strictEqual ( kernelService . getMatchingKernel ( textModel ) . all . length , 0 ) ;
122
124
123
125
let didExecute = false ;
124
126
const kernel = new class extends TestNotebookKernel {
@@ -140,7 +142,7 @@ suite('NotebookExecutionService', () => {
140
142
kernelService . onDidChangeSelectedNotebooks ( e => event = e ) ;
141
143
142
144
const cell = insertCellAtIndex ( viewModel , 0 , 'var c = 3' , 'javascript' , CellKind . Code , { } , [ ] , true , true ) ;
143
- await executionService . executeNotebookCells ( viewModel . notebookDocument , [ cell ] , new MockContextKeyService ( ) ) ;
145
+ await executionService . executeNotebookCells ( textModel , [ cell . model ] , contextKeyService ) ;
144
146
145
147
assert . strictEqual ( didExecute , true ) ;
146
148
assert . ok ( event !== undefined ) ;
@@ -151,7 +153,7 @@ suite('NotebookExecutionService', () => {
151
153
152
154
test ( 'Completes unconfirmed executions' , async function ( ) {
153
155
154
- return withTestNotebook ( [ ] , async viewModel => {
156
+ return withTestNotebook ( [ ] , async ( viewModel , textModel ) => {
155
157
let didExecute = false ;
156
158
const kernel = new class extends TestNotebookKernel {
157
159
constructor ( ) {
@@ -170,7 +172,7 @@ suite('NotebookExecutionService', () => {
170
172
const exeStateService = instantiationService . get ( INotebookExecutionStateService ) ;
171
173
172
174
const cell = insertCellAtIndex ( viewModel , 0 , 'var c = 3' , 'javascript' , CellKind . Code , { } , [ ] , true , true ) ;
173
- await executionService . executeNotebookCells ( viewModel . notebookDocument , [ cell ] , new MockContextKeyService ( ) ) ;
175
+ await executionService . executeNotebookCells ( textModel , [ cell . model ] , contextKeyService ) ;
174
176
175
177
assert . strictEqual ( didExecute , true ) ;
176
178
assert . strictEqual ( exeStateService . getCellExecution ( cell . uri ) , undefined ) ;
0 commit comments