Skip to content

Commit ee1e743

Browse files
authored
Merge pull request microsoft#186729 from microsoft/aiday/activeSessionTypeAssertion
Ending current inline chat session when new session created
2 parents dfb7831 + d25139c commit ee1e743

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,17 @@ export class InlineChatController implements IEditorContribution {
176176
return this._zone.value.position;
177177
}
178178

179+
private _currentRun?: Promise<void>;
180+
179181
async run(options: InlineChatRunOptions | undefined = {}): Promise<void> {
180-
this._log('session starting');
181-
await this.finishExistingSession();
182+
this.finishExistingSession();
183+
if (this._currentRun) {
184+
await this._currentRun;
185+
}
182186
this._stashedSession.clear();
183-
184-
await this._nextState(State.CREATE_SESSION, options);
185-
this._log('session done or paused');
187+
this._currentRun = this._nextState(State.CREATE_SESSION, options);
188+
await this._currentRun;
189+
this._currentRun = undefined;
186190
}
187191

188192
// ---- state machine
@@ -815,7 +819,7 @@ export class InlineChatController implements IEditorContribution {
815819
return result;
816820
}
817821

818-
async finishExistingSession(): Promise<void> {
822+
finishExistingSession(): void {
819823
if (this._activeSession) {
820824
if (this._activeSession.editMode === EditMode.Preview) {
821825
this._log('finishing existing session, using CANCEL', this._activeSession.editMode);

src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ suite('InteractiveChatController', function () {
148148

149149
test('run (show/hide)', async function () {
150150
ctrl = instaService.createInstance(TestController, editor);
151+
const p = ctrl.waitFor(TestController.INIT_SEQUENCE_AUTO_SEND);
151152
const run = ctrl.run({ message: 'Hello', autoSend: true });
152-
153-
await ctrl.waitFor(TestController.INIT_SEQUENCE_AUTO_SEND);
153+
await p;
154154
assert.ok(ctrl.getWidgetPosition() !== undefined);
155155
ctrl.cancelSession();
156156

@@ -218,9 +218,10 @@ suite('InteractiveChatController', function () {
218218

219219
test('typing outside of wholeRange finishes session', async function () {
220220
ctrl = instaService.createInstance(TestController, editor);
221+
const p = ctrl.waitFor(TestController.INIT_SEQUENCE_AUTO_SEND);
221222
ctrl.run({ message: 'Hello', autoSend: true });
222223

223-
await ctrl.waitFor(TestController.INIT_SEQUENCE_AUTO_SEND);
224+
await p;
224225

225226
const session = inlineChatSessionService.getSession(editor, editor.getModel()!.uri);
226227
assert.ok(session);
@@ -257,9 +258,10 @@ suite('InteractiveChatController', function () {
257258
});
258259
store.add(d);
259260
ctrl = instaService.createInstance(TestController, editor);
261+
const p = ctrl.waitFor(TestController.INIT_SEQUENCE);
260262
ctrl.run({ message: 'Hello', autoSend: false });
261263

262-
await ctrl.waitFor(TestController.INIT_SEQUENCE);
264+
await p;
263265

264266
const session = inlineChatSessionService.getSession(editor, editor.getModel()!.uri);
265267
assert.ok(session);
@@ -298,12 +300,13 @@ suite('InteractiveChatController', function () {
298300
});
299301
store.add(d);
300302
ctrl = instaService.createInstance(TestController, editor);
301-
const p = ctrl.run({ message: 'Hello', autoSend: true });
303+
const p = ctrl.waitFor([...TestController.INIT_SEQUENCE, State.MAKE_REQUEST]);
304+
const r = ctrl.run({ message: 'Hello', autoSend: true });
302305

303-
await ctrl.waitFor([...TestController.INIT_SEQUENCE, State.MAKE_REQUEST]);
306+
await p;
304307
ctrl.acceptSession();
305308

306-
await p;
309+
await r;
307310
assert.strictEqual(ctrl.getWidgetPosition(), undefined);
308311
});
309312
});

0 commit comments

Comments
 (0)