@@ -112,6 +112,7 @@ export class InlineCompletionManager implements Disposable {
112112 ) => {
113113 try {
114114 vsCodeState . isCodeWhispererEditing = true
115+ const startLine = position . line
115116 // TODO: also log the seen state for other suggestions in session
116117 // Calculate timing metrics before diagnostic delay
117118 const totalSessionDisplayTime = performance . now ( ) - requestStartTime
@@ -120,6 +121,11 @@ export class InlineCompletionManager implements Disposable {
120121 this . sessionManager . getActiveSession ( ) ?. diagnosticsBeforeAccept ,
121122 getDiagnosticsOfCurrentFile ( )
122123 )
124+ // try remove the extra } ) ' " if there is a new reported problem
125+ // the extra } will cause syntax error
126+ if ( diagnosticDiff . added . length > 0 ) {
127+ await handleExtraBrackets ( editor , editor . selection . active , position )
128+ }
123129 const params : LogInlineCompletionSessionResultsParams = {
124130 sessionId : sessionId ,
125131 completionSessionResult : {
@@ -164,10 +170,11 @@ export class InlineCompletionManager implements Disposable {
164170 const onInlineRejection = async ( ) => {
165171 try {
166172 vsCodeState . isCodeWhispererEditing = true
167- if ( this . sessionManager . getActiveSession ( ) === undefined ) {
173+ const session = this . sessionManager . getActiveSession ( )
174+ if ( session === undefined ) {
168175 return
169176 }
170- const requestStartTime = this . sessionManager . getActiveSession ( ) ! . requestStartTime
177+ const requestStartTime = session . requestStartTime
171178 const totalSessionDisplayTime = performance . now ( ) - requestStartTime
172179 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
173180 // TODO: also log the seen state for other suggestions in session
@@ -176,9 +183,9 @@ export class InlineCompletionManager implements Disposable {
176183 CodeWhispererConstants . platformLanguageIds ,
177184 this . inlineCompletionProvider
178185 )
179- const sessionId = this . sessionManager . getActiveSession ( ) ? .sessionId
186+ const sessionId = session . sessionId
180187 const itemId = this . sessionManager . getActiveRecommendation ( ) [ 0 ] ?. itemId
181- if ( ! sessionId || ! itemId ) {
188+ if ( ! itemId ) {
182189 return
183190 }
184191 const params : LogInlineCompletionSessionResultsParams = {
@@ -190,6 +197,7 @@ export class InlineCompletionManager implements Disposable {
190197 discarded : false ,
191198 } ,
192199 } ,
200+ firstCompletionDisplayLatency : session . firstCompletionDisplayLatency ,
193201 totalSessionDisplayTime : totalSessionDisplayTime ,
194202 }
195203 this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
@@ -229,53 +237,6 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
229237 await vscode . commands . executeCommand ( `aws.amazonq.checkInlineSuggestionVisibility` )
230238 }
231239
232- /**
233- * Check if a completion suggestion is currently active/displayed
234- */
235- public async isCompletionActive ( ) : Promise < boolean > {
236- const session = this . sessionManager . getActiveSession ( )
237- if ( session === undefined || ! session . displayed || session . suggestions . some ( ( item ) => item . isInlineEdit ) ) {
238- return false
239- }
240-
241- // Use VS Code command to check if inline suggestion is actually visible on screen
242- // This command only executes when inlineSuggestionVisible context is true
243- await vscode . commands . executeCommand ( 'aws.amazonq.checkInlineSuggestionVisibility' )
244- const isInlineSuggestionVisible = performance . now ( ) - session . lastVisibleTime < 50
245- return isInlineSuggestionVisible
246- }
247-
248- /**
249- * Batch discard telemetry for completion suggestions when edit suggestion is active
250- */
251- public batchDiscardTelemetryForEditSuggestion ( items : any [ ] , session : any ) : void {
252- // Emit DISCARD telemetry for completion suggestions that can't be shown due to active edit
253- const completionSessionResult : {
254- [ key : string ] : { seen : boolean ; accepted : boolean ; discarded : boolean }
255- } = { }
256-
257- for ( const item of items ) {
258- if ( ! item . isInlineEdit && item . itemId ) {
259- completionSessionResult [ item . itemId ] = {
260- seen : false ,
261- accepted : false ,
262- discarded : true ,
263- }
264- }
265- }
266-
267- // Send single telemetry event for all discarded items
268- if ( Object . keys ( completionSessionResult ) . length > 0 ) {
269- const params : LogInlineCompletionSessionResultsParams = {
270- sessionId : session . sessionId ,
271- completionSessionResult,
272- firstCompletionDisplayLatency : session . firstCompletionDisplayLatency ,
273- totalSessionDisplayTime : performance . now ( ) - session . requestStartTime ,
274- }
275- this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
276- }
277- }
278-
279240 // this method is automatically invoked by VS Code as user types
280241 async provideInlineCompletionItems (
281242 document : TextDocument ,
@@ -303,21 +264,16 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
303264 return [ ]
304265 }
305266
306- const isAutoTrigger = context . triggerKind === InlineCompletionTriggerKind . Automatic
267+ // there is a bug in VS Code, when hitting Enter, the context.triggerKind is Invoke (0)
268+ // when hitting other keystrokes, the context.triggerKind is Automatic (1)
269+ // we only mark option + C as manual trigger
270+ // this is a workaround since the inlineSuggest.trigger command take no params
271+ const isAutoTrigger = performance . now ( ) - vsCodeState . lastManualTriggerTime > 50
307272 if ( isAutoTrigger && ! CodeSuggestionsState . instance . isSuggestionsEnabled ( ) ) {
308273 // return early when suggestions are disabled with auto trigger
309274 return [ ]
310275 }
311276
312- // yield event loop to let the document listen catch updates
313- await sleep ( 1 )
314- // prevent user deletion invoking auto trigger
315- // this is a best effort estimate of deletion
316- if ( this . documentEventListener . isLastEventDeletion ( document . uri . fsPath ) ) {
317- getLogger ( ) . debug ( 'Skip auto trigger when deleting code' )
318- return [ ]
319- }
320-
321277 // yield event loop to let the document listen catch updates
322278 await sleep ( 1 )
323279
@@ -383,6 +339,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
383339 discarded : ! prevSession . displayed ,
384340 } ,
385341 } ,
342+ firstCompletionDisplayLatency : prevSession . firstCompletionDisplayLatency ,
386343 totalSessionDisplayTime : performance . now ( ) - prevSession . requestStartTime ,
387344 }
388345 this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
@@ -407,8 +364,8 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
407364 } ,
408365 token ,
409366 isAutoTrigger ,
410- getAllRecommendationsOptions ,
411- this . documentEventListener . getLastDocumentChangeEvent ( document . uri . fsPath ) ?. event
367+ this . documentEventListener ,
368+ getAllRecommendationsOptions
412369 )
413370 // get active item from session for displaying
414371 const items = this . sessionManager . getActiveRecommendation ( )
@@ -441,25 +398,24 @@ ${itemLog}
441398
442399 const cursorPosition = document . validatePosition ( position )
443400
444- if ( position . isAfter ( editor . selection . active ) ) {
445- const params : LogInlineCompletionSessionResultsParams = {
446- sessionId : session . sessionId ,
447- completionSessionResult : {
448- [ itemId ] : {
449- seen : false ,
450- accepted : false ,
451- discarded : true ,
401+ // Completion will not be rendered if users cursor moves to a position which is before the position when the service is invoked
402+ if ( items . length > 0 && ! items [ 0 ] . isInlineEdit ) {
403+ if ( position . isAfter ( editor . selection . active ) ) {
404+ const params : LogInlineCompletionSessionResultsParams = {
405+ sessionId : session . sessionId ,
406+ completionSessionResult : {
407+ [ itemId ] : {
408+ seen : false ,
409+ accepted : false ,
410+ discarded : true ,
411+ } ,
452412 } ,
453413 }
454414 this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
455415 this . sessionManager . clear ( )
456416 logstr += `- cursor moved behind trigger position. Discarding completion suggestion...`
457417 return [ ]
458418 }
459- this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
460- this . sessionManager . clear ( )
461- logstr += `- cursor moved behind trigger position. Discarding suggestion...`
462- return [ ]
463419 }
464420
465421 // delay the suggestion rendeing if user is actively typing
0 commit comments