@@ -17,7 +17,6 @@ import { ISuggestMemoryService } from 'vs/editor/contrib/suggest/suggestMemory';
17
17
import { IMenuService , IMenu } from 'vs/platform/actions/common/actions' ;
18
18
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
19
19
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
20
- import sinon = require( 'sinon' ) ;
21
20
import { timeout } from 'vs/base/common/async' ;
22
21
import { DisposableStore } from 'vs/base/common/lifecycle' ;
23
22
import { CompletionItemKind , CompletionItemProvider , CompletionProviderRegistry } from 'vs/editor/common/modes' ;
@@ -27,9 +26,9 @@ import { Event } from 'vs/base/common/event';
27
26
import assert = require( 'assert' ) ;
28
27
import { GhostTextContext } from 'vs/editor/contrib/inlineCompletions/test/utils' ;
29
28
import { Range } from 'vs/editor/common/core/range' ;
29
+ import { runWithFakedTimers } from 'vs/editor/contrib/inlineCompletions/test/timeTravelScheduler' ;
30
30
31
31
suite ( 'Suggest Widget Model' , ( ) => {
32
-
33
32
test ( 'Active' , async ( ) => {
34
33
await withAsyncTestCodeEditorAndInlineCompletionsModel ( '' ,
35
34
{ fakeClock : true , provider, } ,
@@ -110,57 +109,49 @@ async function withAsyncTestCodeEditorAndInlineCompletionsModel(
110
109
options : TestCodeEditorCreationOptions & { provider ?: CompletionItemProvider , fakeClock ?: boolean , serviceCollection ?: never } ,
111
110
callback : ( args : { editor : ITestCodeEditor , editorViewModel : ViewModel , model : SuggestWidgetAdapterModel , context : GhostTextContext } ) => Promise < void >
112
111
) : Promise < void > {
113
- const serviceCollection = new ServiceCollection (
114
- [ ITelemetryService , NullTelemetryService ] ,
115
- [ ILogService , new NullLogService ( ) ] ,
116
- [ IStorageService , new InMemoryStorageService ( ) ] ,
117
- [ IKeybindingService , new MockKeybindingService ( ) ] ,
118
- [ IEditorWorkerService , new class extends mock < IEditorWorkerService > ( ) {
119
- override computeWordRanges ( ) {
120
- return Promise . resolve ( { } ) ;
121
- }
122
- } ] ,
123
- [ ISuggestMemoryService , new class extends mock < ISuggestMemoryService > ( ) {
124
- override memorize ( ) : void { }
125
- override select ( ) : number { return 0 ; }
126
- } ] ,
127
- [ IMenuService , new class extends mock < IMenuService > ( ) {
128
- override createMenu ( ) {
129
- return new class extends mock < IMenu > ( ) {
130
- override onDidChange = Event . None ;
131
- override dispose ( ) { }
132
- } ;
112
+ await runWithFakedTimers ( { useFakeTimers : options . fakeClock } , async ( ) => {
113
+ const disposableStore = new DisposableStore ( ) ;
114
+
115
+ try {
116
+ const serviceCollection = new ServiceCollection (
117
+ [ ITelemetryService , NullTelemetryService ] ,
118
+ [ ILogService , new NullLogService ( ) ] ,
119
+ [ IStorageService , new InMemoryStorageService ( ) ] ,
120
+ [ IKeybindingService , new MockKeybindingService ( ) ] ,
121
+ [ IEditorWorkerService , new class extends mock < IEditorWorkerService > ( ) {
122
+ override computeWordRanges ( ) {
123
+ return Promise . resolve ( { } ) ;
124
+ }
125
+ } ] ,
126
+ [ ISuggestMemoryService , new class extends mock < ISuggestMemoryService > ( ) {
127
+ override memorize ( ) : void { }
128
+ override select ( ) : number { return 0 ; }
129
+ } ] ,
130
+ [ IMenuService , new class extends mock < IMenuService > ( ) {
131
+ override createMenu ( ) {
132
+ return new class extends mock < IMenu > ( ) {
133
+ override onDidChange = Event . None ;
134
+ override dispose ( ) { }
135
+ } ;
136
+ }
137
+ } ]
138
+ ) ;
139
+
140
+ if ( options . provider ) {
141
+ const d = CompletionProviderRegistry . register ( { pattern : '**' } , options . provider ) ;
142
+ disposableStore . add ( d ) ;
133
143
}
134
- } ]
135
- ) ;
136
-
137
- const disposableStore = new DisposableStore ( ) ;
138
-
139
- if ( options . provider ) {
140
- const d = CompletionProviderRegistry . register ( { pattern : '**' } , options . provider ) ;
141
- disposableStore . add ( d ) ;
142
- }
143
-
144
- let clock : sinon . SinonFakeTimers | undefined ;
145
- if ( options . fakeClock ) {
146
- clock = sinon . useFakeTimers ( ) ;
147
- }
148
- try {
149
- const p = withAsyncTestCodeEditor ( text , { ...options , serviceCollection } , async ( editor , editorViewModel , instantiationService ) => {
150
- editor . registerAndInstantiateContribution ( SnippetController2 . ID , SnippetController2 ) ;
151
- editor . registerAndInstantiateContribution ( SuggestController . ID , SuggestController ) ;
152
- const model = instantiationService . createInstance ( SuggestWidgetAdapterModel , editor ) ;
153
- const context = new GhostTextContext ( model , editor ) ;
154
- await callback ( { editor, editorViewModel, model, context } ) ;
155
- model . dispose ( ) ;
156
- } ) ;
157
-
158
- const p2 = clock ?. runAllAsync ( ) ;
159
-
160
- await p ;
161
- await p2 ;
162
- } finally {
163
- clock ?. restore ( ) ;
164
- disposableStore . dispose ( ) ;
165
- }
144
+
145
+ await withAsyncTestCodeEditor ( text , { ...options , serviceCollection } , async ( editor , editorViewModel , instantiationService ) => {
146
+ editor . registerAndInstantiateContribution ( SnippetController2 . ID , SnippetController2 ) ;
147
+ editor . registerAndInstantiateContribution ( SuggestController . ID , SuggestController ) ;
148
+ const model = instantiationService . createInstance ( SuggestWidgetAdapterModel , editor ) ;
149
+ const context = new GhostTextContext ( model , editor ) ;
150
+ await callback ( { editor, editorViewModel, model, context } ) ;
151
+ model . dispose ( ) ;
152
+ } ) ;
153
+ } finally {
154
+ disposableStore . dispose ( ) ;
155
+ }
156
+ } ) ;
166
157
}
0 commit comments