Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure EditModeStrategy#apply/cancel isn't called twice, keep reference onto editor model to prevent dispose before reset #180952

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ModelDecorationOptions, createTextBufferFactoryFromSnapshot } from 'vs/
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker';
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { IModelService } from 'vs/editor/common/services/model';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { InlineCompletionsController } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController';
import { localize } from 'vs/nls';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -310,6 +311,7 @@ export class InteractiveEditorController implements IEditorContribution {
@IStorageService private readonly _storageService: IStorageService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IModelService private readonly _modelService: IModelService,
@ITextModelService private readonly _textModelService: ITextModelService,
@INotebookEditorService private readonly _notebookEditorService: INotebookEditorService,
@IContextKeyService contextKeyService: IContextKeyService,

Expand Down Expand Up @@ -375,15 +377,16 @@ export class InteractiveEditorController implements IEditorContribution {

const store = new DisposableStore();

// keep a snapshot of the "actual" model
const textModel0 = this._modelService.createModel(createTextBufferFactoryFromSnapshot(textModel.createSnapshot()), { languageId: textModel.getLanguageId(), onDidChange: Event.None }, undefined, true);
store.add(textModel0);

// keep a reference to prevent disposal of the "actual" model
const refTextModelN = await this._textModelService.createModelReference(textModel.uri);
store.add(refTextModelN);

let textModel0Changes: LineRangeMapping[] | undefined;
const textModel0 = this._modelService.createModel(
createTextBufferFactoryFromSnapshot(textModel.createSnapshot()),
{ languageId: textModel.getLanguageId(), onDidChange: Event.None },
undefined, true
);

store.add(textModel0);
this._currentSession = new Session(editMode, textModel0, textModel, provider, session);
this._strategy = this._instaService.createInstance(EditModeStrategy.ctor(editMode), this._currentSession);

Expand Down Expand Up @@ -459,9 +462,6 @@ export class InteractiveEditorController implements IEditorContribution {

}, undefined, store);

const roundStore = new DisposableStore();
store.add(roundStore);

const diffZone = this._instaService.createInstance(InteractiveEditorDiffWidget, this._editor, textModel0);

do {
Expand Down Expand Up @@ -507,7 +507,6 @@ export class InteractiveEditorController implements IEditorContribution {
this.accept();
}
const input = await inputPromise;
roundStore.clear();

if (!input) {
continue;
Expand Down Expand Up @@ -805,16 +804,20 @@ export class InteractiveEditorController implements IEditorContribution {
}

async applyChanges(): Promise<EditResponse | void> {
if (this._currentSession?.lastResponse instanceof EditResponse) {
if (this._currentSession?.lastResponse instanceof EditResponse && this._strategy) {
const { lastResponse } = this._currentSession;
await this._strategy?.apply();
const strategy = this._strategy;
this._strategy = undefined;
await strategy?.apply();
this._ctsSession.cancel();
return lastResponse;
}
}

async cancelSession() {
await this._strategy?.cancel();
const strategy = this._strategy;
this._strategy = undefined;
await strategy?.cancel();
this._ctsSession.cancel();
}
}
Expand Down