@@ -31,6 +31,7 @@ import { ModelDecorationOptions, createTextBufferFactoryFromSnapshot } from 'vs/
31
31
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker' ;
32
32
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures' ;
33
33
import { IModelService } from 'vs/editor/common/services/model' ;
34
+ import { ITextModelService } from 'vs/editor/common/services/resolverService' ;
34
35
import { InlineCompletionsController } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController' ;
35
36
import { localize } from 'vs/nls' ;
36
37
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
@@ -310,6 +311,7 @@ export class InteractiveEditorController implements IEditorContribution {
310
311
@IStorageService private readonly _storageService : IStorageService ,
311
312
@IConfigurationService private readonly _configurationService : IConfigurationService ,
312
313
@IModelService private readonly _modelService : IModelService ,
314
+ @ITextModelService private readonly _textModelService : ITextModelService ,
313
315
@INotebookEditorService private readonly _notebookEditorService : INotebookEditorService ,
314
316
@IContextKeyService contextKeyService : IContextKeyService ,
315
317
@@ -375,15 +377,16 @@ export class InteractiveEditorController implements IEditorContribution {
375
377
376
378
const store = new DisposableStore ( ) ;
377
379
380
+ // keep a snapshot of the "actual" model
381
+ const textModel0 = this . _modelService . createModel ( createTextBufferFactoryFromSnapshot ( textModel . createSnapshot ( ) ) , { languageId : textModel . getLanguageId ( ) , onDidChange : Event . None } , undefined , true ) ;
382
+ store . add ( textModel0 ) ;
383
+
384
+ // keep a reference to prevent disposal of the "actual" model
385
+ const refTextModelN = await this . _textModelService . createModelReference ( textModel . uri ) ;
386
+ store . add ( refTextModelN ) ;
378
387
379
388
let textModel0Changes : LineRangeMapping [ ] | undefined ;
380
- const textModel0 = this . _modelService . createModel (
381
- createTextBufferFactoryFromSnapshot ( textModel . createSnapshot ( ) ) ,
382
- { languageId : textModel . getLanguageId ( ) , onDidChange : Event . None } ,
383
- undefined , true
384
- ) ;
385
389
386
- store . add ( textModel0 ) ;
387
390
this . _currentSession = new Session ( editMode , textModel0 , textModel , provider , session ) ;
388
391
this . _strategy = this . _instaService . createInstance ( EditModeStrategy . ctor ( editMode ) , this . _currentSession ) ;
389
392
@@ -459,9 +462,6 @@ export class InteractiveEditorController implements IEditorContribution {
459
462
460
463
} , undefined , store ) ;
461
464
462
- const roundStore = new DisposableStore ( ) ;
463
- store . add ( roundStore ) ;
464
-
465
465
const diffZone = this . _instaService . createInstance ( InteractiveEditorDiffWidget , this . _editor , textModel0 ) ;
466
466
467
467
do {
@@ -507,7 +507,6 @@ export class InteractiveEditorController implements IEditorContribution {
507
507
this . accept ( ) ;
508
508
}
509
509
const input = await inputPromise ;
510
- roundStore . clear ( ) ;
511
510
512
511
if ( ! input ) {
513
512
continue ;
@@ -805,16 +804,20 @@ export class InteractiveEditorController implements IEditorContribution {
805
804
}
806
805
807
806
async applyChanges ( ) : Promise < EditResponse | void > {
808
- if ( this . _currentSession ?. lastResponse instanceof EditResponse ) {
807
+ if ( this . _currentSession ?. lastResponse instanceof EditResponse && this . _strategy ) {
809
808
const { lastResponse } = this . _currentSession ;
810
- await this . _strategy ?. apply ( ) ;
809
+ const strategy = this . _strategy ;
810
+ this . _strategy = undefined ;
811
+ await strategy ?. apply ( ) ;
811
812
this . _ctsSession . cancel ( ) ;
812
813
return lastResponse ;
813
814
}
814
815
}
815
816
816
817
async cancelSession ( ) {
817
- await this . _strategy ?. cancel ( ) ;
818
+ const strategy = this . _strategy ;
819
+ this . _strategy = undefined ;
820
+ await strategy ?. cancel ( ) ;
818
821
this . _ctsSession . cancel ( ) ;
819
822
}
820
823
}
0 commit comments