@@ -39,6 +39,11 @@ import { CTX_INLINE_CHAT_CHANGE_HAS_DIFF, CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF, CTX
39
39
import { HunkState } from './inlineChatSession' ;
40
40
import { assertType } from 'vs/base/common/types' ;
41
41
42
+ export interface IEditObserver {
43
+ start ( ) : void ;
44
+ stop ( ) : void ;
45
+ }
46
+
42
47
export abstract class EditModeStrategy {
43
48
44
49
protected static _decoBlock = ModelDecorationOptions . register ( {
@@ -80,9 +85,9 @@ export abstract class EditModeStrategy {
80
85
this . _onDidDiscard . fire ( ) ;
81
86
}
82
87
83
- abstract makeProgressiveChanges ( edits : ISingleEditOperation [ ] , timings : ProgressingEditsOptions ) : Promise < void > ;
88
+ abstract makeProgressiveChanges ( edits : ISingleEditOperation [ ] , obs : IEditObserver , timings : ProgressingEditsOptions ) : Promise < void > ;
84
89
85
- abstract makeChanges ( edits : ISingleEditOperation [ ] ) : Promise < void > ;
90
+ abstract makeChanges ( edits : ISingleEditOperation [ ] , obs : IEditObserver ) : Promise < void > ;
86
91
87
92
abstract undoChanges ( altVersionId : number ) : Promise < void > ;
88
93
@@ -239,7 +244,7 @@ export class LivePreviewStrategy extends EditModeStrategy {
239
244
await undoModelUntil ( modelN , targetAltVersion ) ;
240
245
}
241
246
242
- override async makeChanges ( edits : ISingleEditOperation [ ] ) : Promise < void > {
247
+ override async makeChanges ( edits : ISingleEditOperation [ ] , obs : IEditObserver ) : Promise < void > {
243
248
const cursorStateComputerAndInlineDiffCollection : ICursorStateComputer = ( undoEdits ) => {
244
249
let last : Position | null = null ;
245
250
for ( const edit of undoEdits ) {
@@ -252,7 +257,9 @@ export class LivePreviewStrategy extends EditModeStrategy {
252
257
if ( ++ this . _editCount === 1 ) {
253
258
this . _editor . pushUndoStop ( ) ;
254
259
}
260
+ obs . start ( ) ;
255
261
this . _editor . executeEdits ( 'inline-chat-live' , edits , cursorStateComputerAndInlineDiffCollection ) ;
262
+ obs . stop ( ) ;
256
263
}
257
264
258
265
override async undoChanges ( altVersionId : number ) : Promise < void > {
@@ -261,7 +268,7 @@ export class LivePreviewStrategy extends EditModeStrategy {
261
268
await this . _updateDiffZones ( ) ;
262
269
}
263
270
264
- override async makeProgressiveChanges ( edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions ) : Promise < void > {
271
+ override async makeProgressiveChanges ( edits : ISingleEditOperation [ ] , obs : IEditObserver , opts : ProgressingEditsOptions ) : Promise < void > {
265
272
266
273
// push undo stop before first edit
267
274
if ( ++ this . _editCount === 1 ) {
@@ -280,7 +287,7 @@ export class LivePreviewStrategy extends EditModeStrategy {
280
287
const wordCount = countWords ( edit . text ?? '' ) ;
281
288
const speed = wordCount / durationInSec ;
282
289
// console.log({ durationInSec, wordCount, speed: wordCount / durationInSec });
283
- await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( new WindowIntervalTimer ( this . _zone . domNode ) , edit , speed , opts . token ) ) ;
290
+ await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( new WindowIntervalTimer ( this . _zone . domNode ) , edit , speed , opts . token ) , undefined , obs ) ;
284
291
}
285
292
286
293
await renderTask ;
@@ -398,7 +405,7 @@ export interface AsyncTextEdit {
398
405
readonly newText : AsyncIterable < string > ;
399
406
}
400
407
401
- export async function performAsyncTextEdit ( model : ITextModel , edit : AsyncTextEdit , progress ?: IProgress < IValidEditOperation [ ] > ) {
408
+ export async function performAsyncTextEdit ( model : ITextModel , edit : AsyncTextEdit , progress ?: IProgress < IValidEditOperation [ ] > , obs ?: IEditObserver ) {
402
409
403
410
const [ id ] = model . deltaDecorations ( [ ] , [ {
404
411
range : edit . range ,
@@ -423,11 +430,12 @@ export async function performAsyncTextEdit(model: ITextModel, edit: AsyncTextEdi
423
430
const edit = first
424
431
? EditOperation . replace ( range , part ) // first edit needs to override the "anchor"
425
432
: EditOperation . insert ( range . getEndPosition ( ) , part ) ;
426
-
433
+ obs ?. start ( ) ;
427
434
model . pushEditOperations ( null , [ edit ] , ( undoEdits ) => {
428
435
progress ?. report ( undoEdits ) ;
429
436
return null ;
430
437
} ) ;
438
+ obs ?. stop ( ) ;
431
439
first = false ;
432
440
}
433
441
}
@@ -578,15 +586,15 @@ export class LiveStrategy extends EditModeStrategy {
578
586
await undoModelUntil ( textModelN , altVersionId ) ;
579
587
}
580
588
581
- override async makeChanges ( edits : ISingleEditOperation [ ] ) : Promise < void > {
582
- return this . _makeChanges ( edits , undefined ) ;
589
+ override async makeChanges ( edits : ISingleEditOperation [ ] , obs : IEditObserver ) : Promise < void > {
590
+ return this . _makeChanges ( edits , obs , undefined ) ;
583
591
}
584
592
585
- override async makeProgressiveChanges ( edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions ) : Promise < void > {
586
- return this . _makeChanges ( edits , opts ) ;
593
+ override async makeProgressiveChanges ( edits : ISingleEditOperation [ ] , obs : IEditObserver , opts : ProgressingEditsOptions ) : Promise < void > {
594
+ return this . _makeChanges ( edits , obs , opts ) ;
587
595
}
588
596
589
- private async _makeChanges ( edits : ISingleEditOperation [ ] , opts : ProgressingEditsOptions | undefined ) : Promise < void > {
597
+ private async _makeChanges ( edits : ISingleEditOperation [ ] , obs : IEditObserver , opts : ProgressingEditsOptions | undefined ) : Promise < void > {
590
598
591
599
// push undo stop before first edit
592
600
if ( ++ this . _editCount === 1 ) {
@@ -619,15 +627,17 @@ export class LiveStrategy extends EditModeStrategy {
619
627
const wordCount = countWords ( edit . text ?? '' ) ;
620
628
const speed = wordCount / durationInSec ;
621
629
// console.log({ durationInSec, wordCount, speed: wordCount / durationInSec });
622
- await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( new WindowIntervalTimer ( this . _zone . domNode ) , edit , speed , opts . token ) , progress ) ;
630
+ await performAsyncTextEdit ( this . _session . textModelN , asProgressiveEdit ( new WindowIntervalTimer ( this . _zone . domNode ) , edit , speed , opts . token ) , progress , obs ) ;
623
631
}
624
632
625
633
} else {
626
634
// SYNC
635
+ obs . start ( ) ;
627
636
this . _editor . executeEdits ( 'inline-chat-live' , edits , undoEdits => {
628
637
progress . report ( undoEdits ) ;
629
638
return null ;
630
639
} ) ;
640
+ obs . stop ( ) ;
631
641
}
632
642
}
633
643
0 commit comments