@@ -17,6 +17,7 @@ import { getLogger } from '../../shared/logger'
17
17
import { isCloud9 } from '../../shared/extensionUtilities'
18
18
import { asyncCallWithTimeout , isAwsError } from '../util/commonUtil'
19
19
import * as codewhispererClient from '../client/codewhisperer'
20
+ import { showTimedMessage } from '../../shared/utilities/messages'
20
21
21
22
/**
22
23
* This class is for getRecommendation/listRecommendation API calls and its states
@@ -36,6 +37,7 @@ export class RecommendationHandler {
36
37
public startPos : vscode . Position
37
38
private cancellationToken : vscode . CancellationTokenSource
38
39
public errorMessagePrompt : string
40
+ public isGenerateRecommendationInProgress : boolean
39
41
40
42
constructor ( ) {
41
43
this . requestId = ''
@@ -48,6 +50,7 @@ export class RecommendationHandler {
48
50
this . cancellationToken = new vscode . CancellationTokenSource ( )
49
51
this . errorMessagePrompt = ''
50
52
this . recommendationSuggestionState = new Map < number , string > ( )
53
+ this . isGenerateRecommendationInProgress = false
51
54
}
52
55
53
56
static #instance: RecommendationHandler
@@ -245,7 +248,9 @@ export class RecommendationHandler {
245
248
}
246
249
}
247
250
}
248
- if ( recommendation . length > 0 ) this . recommendations = this . recommendations . concat ( recommendation )
251
+ if ( recommendation . length > 0 ) {
252
+ this . recommendations = isCloud9 ( ) ? recommendation : this . recommendations . concat ( recommendation )
253
+ }
249
254
this . requestId = requestId
250
255
this . sessionId = sessionId
251
256
this . nextToken = nextToken
@@ -299,4 +304,41 @@ export class RecommendationHandler {
299
304
hasNextToken ( ) : boolean {
300
305
return this . nextToken !== ''
301
306
}
307
+
308
+ canShowRecommendationInIntelliSense ( editor : vscode . TextEditor , showPrompt : boolean = false ) : boolean {
309
+ const reject = ( ) => {
310
+ this . reportUserDecisionOfCurrentRecommendation ( editor , - 1 )
311
+ this . clearRecommendations ( )
312
+ }
313
+ if ( ! this . isValidResponse ( ) ) {
314
+ if ( showPrompt ) {
315
+ showTimedMessage (
316
+ this . errorMessagePrompt === '' ? CodeWhispererConstants . noSuggestions : this . errorMessagePrompt ,
317
+ 3000
318
+ )
319
+ }
320
+ reject ( )
321
+ return false
322
+ }
323
+ // do not show recommendation if cursor is before invocation position
324
+ if ( editor . selection . active . isBefore ( this . startPos ) ) {
325
+ reject ( )
326
+ return false
327
+ }
328
+
329
+ // do not show recommendation if typeahead does not match
330
+ const typedPrefix = editor . document . getText (
331
+ new vscode . Range (
332
+ this . startPos . line ,
333
+ this . startPos . character ,
334
+ editor . selection . active . line ,
335
+ editor . selection . active . character
336
+ )
337
+ )
338
+ if ( ! this . recommendations [ 0 ] . content . startsWith ( typedPrefix . trimStart ( ) ) ) {
339
+ reject ( )
340
+ return false
341
+ }
342
+ return true
343
+ }
302
344
}
0 commit comments