@@ -11,7 +11,6 @@ import { assertType } from '../../../../../../base/common/types.js';
11
11
import { LineRange } from '../../../../../../editor/common/core/lineRange.js' ;
12
12
import { Range } from '../../../../../../editor/common/core/range.js' ;
13
13
import { nullDocumentDiff } from '../../../../../../editor/common/diff/documentDiffProvider.js' ;
14
- import { PrefixSumComputer } from '../../../../../../editor/common/model/prefixSumComputer.js' ;
15
14
import { localize } from '../../../../../../nls.js' ;
16
15
import { MenuId } from '../../../../../../platform/actions/common/actions.js' ;
17
16
import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js' ;
@@ -25,15 +24,16 @@ import { INotebookEditorService } from '../../../../notebook/browser/services/no
25
24
import { NotebookCellTextModel } from '../../../../notebook/common/model/notebookCellTextModel.js' ;
26
25
import { NotebookTextModel } from '../../../../notebook/common/model/notebookTextModel.js' ;
27
26
import { ChatAgentLocation , IChatAgentService } from '../../../common/chatAgents.js' ;
28
- import { IModifiedFileEntry , IModifiedFileEntryChangeHunk , IModifiedFileEntryEditorIntegration } from '../../../common/chatEditingService.js' ;
27
+ import { IModifiedFileEntryChangeHunk , IModifiedFileEntryEditorIntegration } from '../../../common/chatEditingService.js' ;
29
28
import { ChatEditingCodeEditorIntegration , IDocumentDiff2 } from '../chatEditingCodeEditorIntegration.js' ;
29
+ import { ChatEditingModifiedNotebookEntry } from '../chatEditingModifiedNotebookEntry.js' ;
30
30
import { countChanges , ICellDiffInfo , sortCellChanges } from './notebookCellChanges.js' ;
31
31
32
32
export class ChatEditingNotebookEditorIntegration extends Disposable implements IModifiedFileEntryEditorIntegration {
33
33
private integration : ChatEditingNotebookEditorWidgetIntegration ;
34
34
private notebookEditor : INotebookEditor ;
35
35
constructor (
36
- _entry : IModifiedFileEntry ,
36
+ _entry : ChatEditingModifiedNotebookEntry ,
37
37
editor : IEditorPane ,
38
38
notebookModel : NotebookTextModel ,
39
39
originalModel : NotebookTextModel ,
@@ -88,14 +88,12 @@ class ChatEditingNotebookEditorWidgetIntegration extends Disposable implements I
88
88
private readonly _currentChange = observableValue < { change : ICellDiffInfo ; index : number } | undefined > ( this , undefined ) ;
89
89
readonly currentChange : IObservable < { change : ICellDiffInfo ; index : number } | undefined > = this . _currentChange ;
90
90
91
- private diffIndexPrefixSum : PrefixSumComputer = new PrefixSumComputer ( new Uint32Array ( ) ) ;
92
-
93
91
private readonly cellEditorIntegrations = new Map < NotebookCellTextModel , { integration : ChatEditingCodeEditorIntegration ; diff : ISettableObservable < IDocumentDiff2 > } > ( ) ;
94
92
95
93
private readonly insertDeleteDecorators : IObservable < { insertedCellDecorator : NotebookInsertedCellDecorator ; deletedCellDecorator : NotebookDeletedCellDecorator } | undefined > ;
96
94
97
95
constructor (
98
- private readonly _entry : IModifiedFileEntry ,
96
+ private readonly _entry : ChatEditingModifiedNotebookEntry ,
99
97
private readonly notebookEditor : INotebookEditor ,
100
98
private readonly notebookModel : NotebookTextModel ,
101
99
originalModel : NotebookTextModel ,
@@ -130,28 +128,15 @@ class ChatEditingNotebookEditorWidgetIntegration extends Disposable implements I
130
128
}
131
129
} ) ) ;
132
130
133
- // INIT when not streaming anymore, once per request, and when having changes
131
+ // INIT when not streaming nor diffing the response anymore, once per request, and when having changes
134
132
let lastModifyingRequestId : string | undefined ;
135
133
this . _store . add ( autorun ( r => {
136
134
137
135
if ( ! _entry . isCurrentlyBeingModifiedBy . read ( r )
136
+ && ! _entry . isProcessingResponse . read ( r )
138
137
&& lastModifyingRequestId !== _entry . lastModifyingRequestId
139
138
&& cellChanges . read ( r ) . some ( c => c . type !== 'unchanged' && ! c . diff . read ( r ) . identical )
140
139
) {
141
- lastModifyingRequestId = _entry . lastModifyingRequestId ;
142
-
143
- const sortedCellChanges = sortCellChanges ( cellChanges . read ( r ) ) ;
144
- const values = new Uint32Array ( sortedCellChanges . length ) ;
145
- for ( let i = 0 ; i < sortedCellChanges . length ; i ++ ) {
146
- const change = sortedCellChanges [ i ] ;
147
- values [ i ] = change . type === 'insert' ? 1
148
- : change . type === 'delete' ? 1
149
- : change . type === 'modified' ? change . diff . read ( r ) . changes . length
150
- : 0 ;
151
- }
152
-
153
- this . diffIndexPrefixSum = new PrefixSumComputer ( values ) ;
154
-
155
140
this . reveal ( true ) ;
156
141
}
157
142
} ) ) ;
@@ -224,17 +209,28 @@ class ChatEditingNotebookEditorWidgetIntegration extends Disposable implements I
224
209
225
210
this . _register ( autorun ( r => {
226
211
const currentChange = this . currentChange . read ( r ) ;
227
- if ( currentChange ) {
228
- const indexInChange = currentChange . index ;
229
- const cellIndex = currentChange . change . modifiedCellIndex ?? currentChange . change . originalCellIndex ;
230
-
231
- const changesBeforeCell = cellIndex !== undefined && cellIndex > 0 ?
232
- this . diffIndexPrefixSum . getPrefixSum ( cellIndex - 1 ) : 0 ;
233
-
234
- this . _currentIndex . set ( changesBeforeCell + indexInChange , undefined ) ;
235
- } else {
212
+ if ( ! currentChange ) {
236
213
this . _currentIndex . set ( - 1 , undefined ) ;
214
+ return ;
237
215
}
216
+
217
+ let index = 0 ;
218
+ const sortedCellChanges = sortCellChanges ( cellChanges . read ( r ) ) ;
219
+ for ( const change of sortedCellChanges ) {
220
+ if ( currentChange && currentChange . change === change ) {
221
+ if ( change . type === 'modified' ) {
222
+ index += currentChange . index ;
223
+ }
224
+ break ;
225
+ }
226
+ if ( change . type === 'insert' || change . type === 'delete' ) {
227
+ index ++ ;
228
+ } else if ( change . type === 'modified' ) {
229
+ index += change . diff . read ( r ) . changes . length ;
230
+ }
231
+ }
232
+
233
+ this . _currentIndex . set ( index , undefined ) ;
238
234
} ) ) ;
239
235
240
236
this . insertDeleteDecorators = derivedWithStore ( ( r , store ) => {
0 commit comments