Skip to content

Commit

Permalink
Polish query accepting (#183995)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TylerLeonhardt committed May 31, 2023
1 parent 14977db commit c4cfd83
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AskQuickQuestionAction extends Action2 {

private _currentSession: InteractiveQuickPickSession | undefined;
private _currentQuery: string | undefined;
private _lastAcceptedQuery: string | undefined;
private _currentTimer: any | undefined;
private _input: IQuickPick<IQuickPickItem> | undefined;

Expand Down Expand Up @@ -93,8 +94,9 @@ class AskQuickQuestionAction extends Action2 {
});
disposableStore.add(openInChat);
disposableStore.add(openInChat.onChange(async () => {
await this._currentSession?.openInChat(this._input!.value);
await this._currentSession?.openInChat(this._lastAcceptedQuery ?? this._input!.value);
this._currentQuery = undefined;
this._lastAcceptedQuery = undefined;
this._currentSession?.dispose();
this._currentSession = undefined;
}));
Expand All @@ -120,12 +122,14 @@ class AskQuickQuestionAction extends Action2 {
this._input = undefined;
this._currentTimer = setTimeout(() => {
this._currentQuery = undefined;
this._lastAcceptedQuery = undefined;
this._currentSession?.dispose();
this._currentSession = undefined;
}, 1000 * 30); // 30 seconds
}));
disposableStore.add(this._input.onDidAccept(async () => {
await this._currentSession?.accept(this._input!.value);
this._lastAcceptedQuery = this._input!.value;
}));

//#endregion
Expand Down Expand Up @@ -249,10 +253,13 @@ class InteractiveQuickPickSession extends Disposable {

async accept(query: string) {
await this._model.waitForInitialization();
const requests = this._model.getRequests();
const lastRequest = requests[requests.length - 1];
if (lastRequest?.message && lastRequest?.message === query) {
return;
}
if (this._model.requestInProgress) {
const requests = this._model.getRequests();
const lastRequest = requests[requests.length - 1];
this._model.cancelRequest(lastRequest);
this._chatService.cancelCurrentRequestForSession(this.sessionId);
}
await this._chatService.sendRequest(this.sessionId, query);
}
Expand Down

0 comments on commit c4cfd83

Please sign in to comment.