@@ -174,11 +174,15 @@ export class InlineCompletionService {
174
174
private hide : vscode . Disposable
175
175
private next : vscode . Disposable
176
176
private prev : vscode . Disposable
177
+ private _isPaginationRunning = false
177
178
178
179
constructor ( ) {
179
180
this . prev = prevCommand . register ( this )
180
181
this . next = nextCommand . register ( this )
181
182
this . hide = hideCommand . register ( this )
183
+ RecommendationHandler . instance . onDidReceiveRecommendation ( e => {
184
+ this . tryShowRecommendation ( )
185
+ } )
182
186
}
183
187
184
188
static #instance: InlineCompletionService
@@ -196,7 +200,7 @@ export class InlineCompletionService {
196
200
this . hide = hideCommand . register ( this )
197
201
}
198
202
199
- subscribeCommands ( ) {
203
+ subscribeSuggestionCommands ( ) {
200
204
this . disposeCommandOverrides ( )
201
205
this . registerCommandOverrides ( )
202
206
globals . context . subscriptions . push ( this . prev )
@@ -244,18 +248,38 @@ export class InlineCompletionService {
244
248
this . clearRejectionTimer ( )
245
249
}
246
250
251
+ async tryShowRecommendation ( ) {
252
+ const editor = vscode . window . activeTextEditor
253
+ if ( this . isSuggestionVisible ( ) || editor === undefined ) return
254
+ if (
255
+ editor . selection . active . isBefore ( RecommendationHandler . instance . startPos ) ||
256
+ editor . document . uri . fsPath !== this . documentUri ?. fsPath
257
+ ) {
258
+ RecommendationHandler . instance . cancelPaginatedRequest ( )
259
+ RecommendationHandler . instance . recommendations . forEach ( ( r , i ) => {
260
+ RecommendationHandler . instance . setSuggestionState ( i , 'Discard' )
261
+ } )
262
+ RecommendationHandler . instance . reportUserDecisionOfCurrentRecommendation ( editor , - 1 )
263
+ RecommendationHandler . instance . clearRecommendations ( )
264
+ } else if ( RecommendationHandler . instance . recommendations . length > 0 ) {
265
+ RecommendationHandler . instance . moveStartPositionToSkipSpaces ( editor )
266
+ await HoverConfigUtil . instance . overwriteHoverConfig ( )
267
+ this . subscribeSuggestionCommands ( )
268
+ this . startRejectionTimer ( editor )
269
+ await this . showRecommendation ( 0 , true )
270
+ }
271
+ }
272
+
247
273
async getPaginatedRecommendation (
248
274
client : DefaultCodeWhispererClient ,
249
275
editor : vscode . TextEditor ,
250
276
triggerType : CodewhispererTriggerType ,
251
277
config : ConfigurationEntry ,
252
278
autoTriggerType ?: CodewhispererAutomatedTriggerType
253
279
) {
254
- if ( vsCodeState . isCodeWhispererEditing || this . isPaginationRunning ( ) ) return
280
+ if ( vsCodeState . isCodeWhispererEditing || this . _isPaginationRunning ) return
255
281
await this . clearInlineCompletionStates ( editor )
256
282
this . setCodeWhispererStatusBarLoading ( )
257
- await HoverConfigUtil . instance . overwriteHoverConfig ( )
258
- this . subscribeCommands ( )
259
283
RecommendationHandler . instance . checkAndResetCancellationTokens ( )
260
284
this . documentUri = editor . document . uri
261
285
try {
@@ -270,32 +294,12 @@ export class InlineCompletionService {
270
294
true ,
271
295
page
272
296
)
273
-
274
297
if ( RecommendationHandler . instance . checkAndResetCancellationTokens ( ) ) {
275
298
RecommendationHandler . instance . reportUserDecisionOfCurrentRecommendation ( editor , - 1 )
276
299
RecommendationHandler . instance . clearRecommendations ( )
277
300
this . setCodeWhispererStatusBarOk ( )
278
301
return
279
302
}
280
-
281
- if ( ! this . isSuggestionVisible ( ) ) {
282
- if (
283
- editor . selection . active . isBefore ( RecommendationHandler . instance . startPos ) ||
284
- editor . document . uri . fsPath !== this . documentUri ?. fsPath
285
- ) {
286
- RecommendationHandler . instance . cancelPaginatedRequest ( )
287
- RecommendationHandler . instance . recommendations . forEach ( ( r , i ) => {
288
- RecommendationHandler . instance . setSuggestionState ( i , 'Discard' )
289
- } )
290
- RecommendationHandler . instance . reportUserDecisionOfCurrentRecommendation ( editor , - 1 )
291
- RecommendationHandler . instance . clearRecommendations ( )
292
- } else if ( RecommendationHandler . instance . recommendations . length > 0 ) {
293
- RecommendationHandler . instance . moveStartPositionToSkipSpaces ( editor )
294
- this . startRejectionTimer ( editor )
295
- await this . showRecommendation ( 0 , true )
296
- }
297
- }
298
-
299
303
if ( ! RecommendationHandler . instance . hasNextToken ( ) ) break
300
304
page ++
301
305
}
@@ -310,9 +314,6 @@ export class InlineCompletionService {
310
314
showTimedMessage ( CodeWhispererConstants . noSuggestions , 2000 )
311
315
}
312
316
}
313
- if ( RecommendationHandler . instance . recommendations . length === 0 ) {
314
- await HoverConfigUtil . instance . restoreHoverConfig ( )
315
- }
316
317
}
317
318
318
319
async showRecommendation ( indexShift : number , isFirstRecommendation : boolean = false ) {
@@ -349,11 +350,13 @@ export class InlineCompletionService {
349
350
}
350
351
351
352
setCodeWhispererStatusBarLoading ( ) {
353
+ this . _isPaginationRunning = true
352
354
this . statusBar . text = ` $(loading~spin)CodeWhisperer`
353
355
this . statusBar . show ( )
354
356
}
355
357
356
358
setCodeWhispererStatusBarOk ( ) {
359
+ this . _isPaginationRunning = false
357
360
this . statusBar . text = ` $(check)CodeWhisperer`
358
361
this . statusBar . show ( )
359
362
}
@@ -366,10 +369,6 @@ export class InlineCompletionService {
366
369
return this . inlineCompletionProvider ?. getActiveItemIndex !== undefined
367
370
}
368
371
369
- isPaginationRunning ( ) {
370
- return this . statusBar . text === ` $(loading~spin)CodeWhisperer`
371
- }
372
-
373
372
private clearRejectionTimer ( ) {
374
373
if ( this . _timer !== undefined ) {
375
374
clearTimeout ( this . _timer )
0 commit comments