33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import { getLogger , setContext } from 'aws-core-vscode/shared'
6+ import { getLogger , setContext , waitUntil } from 'aws-core-vscode/shared'
77import * as vscode from 'vscode'
88import { diffLines } from 'diff'
99import { LanguageClient } from 'vscode-languageclient'
@@ -292,22 +292,42 @@ export async function displaySvgDecoration(
292292 startLine ,
293293 async ( ) => {
294294 // Handle accept
295+ session . isAccepted = true
295296 getLogger ( ) . info ( 'Edit suggestion accepted' )
296297
297- // Replace content
298+ const endPosition = getEndOfEditPosition ( originalCode , newCode )
299+
300+ let isEditDone : boolean | undefined
298301 try {
299302 vsCodeState . isCodeWhispererEditing = true
303+ getLogger ( ) . info ( 'set isEditing to TRUE' )
304+ // Replace content
300305 await replaceEditorContent ( editor , newCode )
306+
307+ // Move cursor to end of the actual changed content
308+ editor . selection = new vscode . Selection ( endPosition , endPosition )
309+
310+ // Move cursor to end of the actual changed content
311+ // editor.selection = new vscode.Selection(endPosition, endPosition)
312+
313+ isEditDone = await waitUntil (
314+ async ( ) => {
315+ return editor . document . getText ( ) === newCode
316+ } ,
317+ {
318+ timeout : 1000 ,
319+ interval : 50 ,
320+ truthy : true ,
321+ }
322+ )
301323 } finally {
324+ getLogger ( ) . info ( 'set isEditing to FALSE' )
302325 vsCodeState . isCodeWhispererEditing = false
303326 }
304327
305- // Move cursor to end of the actual changed content
306- const endPosition = getEndOfEditPosition ( originalCode , newCode )
307- editor . selection = new vscode . Selection ( endPosition , endPosition )
308-
309- // Move cursor to end of the actual changed content
310- editor . selection = new vscode . Selection ( endPosition , endPosition )
328+ if ( ! isEditDone ) {
329+ console . log ( )
330+ }
311331
312332 await decorationManager . clearDecorations ( editor )
313333 const params : LogInlineCompletionSessionResultsParams = {
@@ -326,19 +346,19 @@ export async function displaySvgDecoration(
326346 languageClient . sendNotification ( 'aws/logInlineCompletionSessionResults' , params )
327347 // Only auto trigger on acceptance if there is a nextToken
328348 if ( inlineCompletionProvider && session . editsStreakPartialResultToken ) {
329- getLogger ( 'nextEditPrediction' ) . info (
330- `on acceptance trigger with nextToken ${ session . editsStreakPartialResultToken } `
331- )
332- await inlineCompletionProvider . provideInlineCompletionItems (
333- editor . document ,
334- endPosition ,
335- {
336- triggerKind : vscode . InlineCompletionTriggerKind . Automatic ,
337- selectedCompletionInfo : undefined ,
338- } ,
339- new vscode . CancellationTokenSource ( ) . token ,
340- { emitTelemetry : false , showUi : false , editsStreakToken : session . editsStreakPartialResultToken }
341- )
349+ // getLogger('nextEditPrediction').info(
350+ // `on acceptance trigger with nextToken ${session.editsStreakPartialResultToken}`
351+ // )
352+ // await inlineCompletionProvider._provideInlineCompletionItems (
353+ // editor.document,
354+ // endPosition,
355+ // {
356+ // triggerKind: vscode.InlineCompletionTriggerKind.Automatic,
357+ // selectedCompletionInfo: undefined,
358+ // },
359+ // new vscode.CancellationTokenSource().token,
360+ // { emitTelemetry: false, showUi: false, editsStreakToken: session.editsStreakPartialResultToken }
361+ // )
342362 }
343363 } ,
344364 async ( ) => {
0 commit comments