@@ -16,7 +16,6 @@ import {
1616 GenerateSuggestionsRequest ,
1717 GenerateSuggestionsResponse ,
1818 getFileContext ,
19- SuggestionType ,
2019} from '../../shared/codeWhispererService'
2120import { CodeWhispererSession , SessionManager } from './session/sessionManager'
2221import { CursorTracker } from './tracker/cursorTracker'
@@ -36,7 +35,7 @@ import { RejectedEditTracker } from './tracker/rejectedEditTracker'
3635import { getErrorMessage , hasConnectionExpired } from '../../shared/utils'
3736import { AmazonQError , AmazonQServiceConnectionExpiredError } from '../../shared/amazonQServiceManager/errors'
3837import { DocumentChangedListener } from './documentChangedListener'
39- import { EMPTY_RESULT , EDIT_DEBOUNCE_INTERVAL_MS , EDIT_STALE_RETRY_COUNT } from './constants'
38+ import { EMPTY_RESULT , EDIT_DEBOUNCE_INTERVAL_MS } from './constants'
4039
4140export class EditCompletionHandler {
4241 private readonly editsEnabled : boolean
@@ -74,22 +73,19 @@ export class EditCompletionHandler {
7473 */
7574 documentChanged ( ) {
7675 if ( this . debounceTimeout ) {
77- this . logging . info ( '[NEP] refresh timeout' )
78- this . debounceTimeout . refresh ( )
79- }
80-
81- if ( this . isWaiting ) {
82- this . hasDocumentChangedSinceInvocation = true
76+ if ( this . isWaiting ) {
77+ this . hasDocumentChangedSinceInvocation = true
78+ } else {
79+ this . logging . info ( `refresh and debounce edits suggestion for another ${ EDIT_DEBOUNCE_INTERVAL_MS } ` )
80+ this . debounceTimeout . refresh ( )
81+ }
8382 }
8483 }
8584
8685 async onEditCompletion (
8786 params : InlineCompletionWithReferencesParams ,
8887 token : CancellationToken
8988 ) : Promise < InlineCompletionListWithReferences > {
90- this . hasDocumentChangedSinceInvocation = false
91- this . debounceTimeout = undefined
92-
9389 // On every new completion request close current inflight session.
9490 const currentSession = this . sessionManager . getCurrentSession ( )
9591 if ( currentSession && currentSession . state == 'REQUESTING' && ! params . partialResultToken ) {
@@ -156,46 +152,37 @@ export class EditCompletionHandler {
156152 }
157153 }
158154
159- // TODO: telemetry, discarded suggestions
160- // The other easy way to do this is simply not return any suggestion (which is used when retry > 3)
161- const invokeWithRetry = async ( attempt : number = 0 ) : Promise < InlineCompletionListWithReferences > => {
162- return new Promise ( async resolve => {
163- this . debounceTimeout = setTimeout ( async ( ) => {
164- try {
165- this . isWaiting = true
166- const result = await this . _invoke (
167- params ,
168- token ,
169- textDocument ,
170- inferredLanguageId ,
171- currentSession
172- ) . finally ( ( ) => {
173- this . isWaiting = false
155+ return new Promise ( async resolve => {
156+ this . debounceTimeout = setTimeout ( async ( ) => {
157+ try {
158+ this . isWaiting = true
159+ const result = await this . _invoke (
160+ params ,
161+ token ,
162+ textDocument ,
163+ inferredLanguageId ,
164+ currentSession
165+ ) . finally ( ( ) => {
166+ this . isWaiting = false
167+ } )
168+ if ( this . hasDocumentChangedSinceInvocation ) {
169+ this . logging . info (
170+ 'EditCompletionHandler - Document changed during execution, resolving empty result'
171+ )
172+ resolve ( {
173+ sessionId : SessionManager . getInstance ( 'EDITS' ) . getActiveSession ( ) ?. id ?? '' ,
174+ items : [ ] ,
174175 } )
175- if ( this . hasDocumentChangedSinceInvocation ) {
176- if ( attempt < EDIT_STALE_RETRY_COUNT ) {
177- this . logging . info (
178- `EditCompletionHandler - Document changed during execution, retrying (attempt ${ attempt + 1 } )`
179- )
180- this . hasDocumentChangedSinceInvocation = false
181- const retryResult = await invokeWithRetry ( attempt + 1 )
182- resolve ( retryResult )
183- } else {
184- this . logging . info ( 'EditCompletionHandler - Max retries reached, returning empty result' )
185- resolve ( EMPTY_RESULT )
186- }
187- } else {
188- this . logging . info ( 'EditCompletionHandler - No document changes, resolving result' )
189- resolve ( result )
190- }
191- } finally {
192- this . debounceTimeout = undefined
176+ } else {
177+ this . logging . info ( 'EditCompletionHandler - No document changes, resolving result' )
178+ resolve ( result )
193179 }
194- } , EDIT_DEBOUNCE_INTERVAL_MS )
195- } )
196- }
197-
198- return invokeWithRetry ( )
180+ } finally {
181+ this . debounceTimeout = undefined
182+ this . hasDocumentChangedSinceInvocation = false
183+ }
184+ } , EDIT_DEBOUNCE_INTERVAL_MS )
185+ } )
199186 }
200187
201188 async _invoke (
0 commit comments