Skip to content

Commit

Permalink
store locationData on request and use when resending (#225509)
Browse files Browse the repository at this point in the history
there is propably more that should be stored on the request and reused like this but this change is deliberatly small so that can be a candidate fix too

microsoft/vscode-copilot#7195
  • Loading branch information
jrieken authored Aug 14, 2024
1 parent eaa41d5 commit b32a568
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/vs/workbench/contrib/chat/common/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ILogService } from 'vs/platform/log/common/log';
import { ChatAgentLocation, IChatAgentCommand, IChatAgentData, IChatAgentHistoryEntry, IChatAgentRequest, IChatAgentResult, IChatAgentService, reviveSerializedAgent } from 'vs/workbench/contrib/chat/common/chatAgents';
import { ChatRequestTextPart, IParsedChatRequest, getPromptText, reviveParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes';
import { ChatAgentVoteDirection, IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatMarkdownContent, IChatProgress, IChatProgressMessage, IChatResponseProgressFileTreeData, IChatTask, IChatTextEdit, IChatTreeData, IChatUsedContext, IChatWarningMessage, isIUsedContext } from 'vs/workbench/contrib/chat/common/chatService';
import { ChatAgentVoteDirection, IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatLocationData, IChatMarkdownContent, IChatProgress, IChatProgressMessage, IChatResponseProgressFileTreeData, IChatTask, IChatTextEdit, IChatTreeData, IChatUsedContext, IChatWarningMessage, isIUsedContext } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatRequestVariableValue } from 'vs/workbench/contrib/chat/common/chatVariables';

export interface IChatRequestVariableEntry {
Expand Down Expand Up @@ -52,6 +52,7 @@ export interface IChatRequestModel {
readonly message: IParsedChatRequest;
readonly attempt: number;
readonly variableData: IChatRequestVariableData;
readonly locationData?: IChatLocationData;
readonly response?: IChatResponseModel;
}

Expand Down Expand Up @@ -144,11 +145,16 @@ export class ChatRequestModel implements IChatRequestModel {
this._variableData = v;
}

public get locationData(): IChatLocationData | undefined {
return this._locationData;
}

constructor(
private _session: ChatModel,
public readonly message: IParsedChatRequest,
private _variableData: IChatRequestVariableData,
private _attempt: number = 0
private _attempt: number = 0,
private _locationData?: IChatLocationData
) {
this.id = 'request_' + ChatRequestModel.nextId++;
}
Expand Down Expand Up @@ -861,8 +867,8 @@ export class ChatModel extends Disposable implements IChatModel {
return this._requests;
}

addRequest(message: IParsedChatRequest, variableData: IChatRequestVariableData, attempt: number, chatAgent?: IChatAgentData, slashCommand?: IChatAgentCommand): ChatRequestModel {
const request = new ChatRequestModel(this, message, variableData, attempt);
addRequest(message: IParsedChatRequest, variableData: IChatRequestVariableData, attempt: number, chatAgent?: IChatAgentData, slashCommand?: IChatAgentCommand, locationData?: IChatLocationData): ChatRequestModel {
const request = new ChatRequestModel(this, message, variableData, attempt, locationData);
request.response = new ChatResponseModel([], this, chatAgent, slashCommand, request.id);

this._requests.push(request);
Expand Down
10 changes: 7 additions & 3 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ export class ChatService extends Disposable implements IChatService {

model.removeRequest(request.id, ChatRequestRemovalReason.Resend);

await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, defaultAgent, location, options).responseCompletePromise;
const resendOptions: IChatSendRequestOptions = {
...options,
locationData: request.locationData
};
await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, defaultAgent, location, resendOptions).responseCompletePromise;
}

async sendRequest(sessionId: string, request: string, options?: IChatSendRequestOptions): Promise<IChatSendRequestData | undefined> {
Expand Down Expand Up @@ -482,7 +486,7 @@ export class ChatService extends Disposable implements IChatService {
const history = getHistoryEntriesFromModel(model, agentPart?.agent.id);

const initVariableData: IChatRequestVariableData = { variables: [] };
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command);
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command, options?.locationData);
completeResponseCreated();
const variableData = await this.chatVariablesService.resolveVariables(parsedRequest, options?.attachedContext, model, progressCallback, token);
model.updateRequest(request, variableData);
Expand All @@ -500,7 +504,7 @@ export class ChatService extends Disposable implements IChatService {
enableCommandDetection,
attempt,
location,
locationData: options?.locationData,
locationData: request.locationData,
acceptedConfirmationData: options?.acceptedConfirmationData,
rejectedConfirmationData: options?.rejectedConfirmationData,
};
Expand Down

0 comments on commit b32a568

Please sign in to comment.