Skip to content

Commit c4cfd83

Browse files
Polish query accepting (microsoft#183995)
We shouldn't send the same request to Copilot if the query hasn't changed. So if the query is the same, we short circut. Fixes microsoft/vscode-internalbacklog#4286 Also, when we open in chat, we should use the last accepted query, not what's in the input box. Fixes microsoft/vscode-internalbacklog#4280
1 parent 14977db commit c4cfd83

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AskQuickQuestionAction extends Action2 {
3535

3636
private _currentSession: InteractiveQuickPickSession | undefined;
3737
private _currentQuery: string | undefined;
38+
private _lastAcceptedQuery: string | undefined;
3839
private _currentTimer: any | undefined;
3940
private _input: IQuickPick<IQuickPickItem> | undefined;
4041

@@ -93,8 +94,9 @@ class AskQuickQuestionAction extends Action2 {
9394
});
9495
disposableStore.add(openInChat);
9596
disposableStore.add(openInChat.onChange(async () => {
96-
await this._currentSession?.openInChat(this._input!.value);
97+
await this._currentSession?.openInChat(this._lastAcceptedQuery ?? this._input!.value);
9798
this._currentQuery = undefined;
99+
this._lastAcceptedQuery = undefined;
98100
this._currentSession?.dispose();
99101
this._currentSession = undefined;
100102
}));
@@ -120,12 +122,14 @@ class AskQuickQuestionAction extends Action2 {
120122
this._input = undefined;
121123
this._currentTimer = setTimeout(() => {
122124
this._currentQuery = undefined;
125+
this._lastAcceptedQuery = undefined;
123126
this._currentSession?.dispose();
124127
this._currentSession = undefined;
125128
}, 1000 * 30); // 30 seconds
126129
}));
127130
disposableStore.add(this._input.onDidAccept(async () => {
128131
await this._currentSession?.accept(this._input!.value);
132+
this._lastAcceptedQuery = this._input!.value;
129133
}));
130134

131135
//#endregion
@@ -249,10 +253,13 @@ class InteractiveQuickPickSession extends Disposable {
249253

250254
async accept(query: string) {
251255
await this._model.waitForInitialization();
256+
const requests = this._model.getRequests();
257+
const lastRequest = requests[requests.length - 1];
258+
if (lastRequest?.message && lastRequest?.message === query) {
259+
return;
260+
}
252261
if (this._model.requestInProgress) {
253-
const requests = this._model.getRequests();
254-
const lastRequest = requests[requests.length - 1];
255-
this._model.cancelRequest(lastRequest);
262+
this._chatService.cancelCurrentRequestForSession(this.sessionId);
256263
}
257264
await this._chatService.sendRequest(this.sessionId, query);
258265
}

0 commit comments

Comments
 (0)