Skip to content

Commit b32a568

Browse files
authored
store locationData on request and use when resending (#225509)
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
1 parent eaa41d5 commit b32a568

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/vs/workbench/contrib/chat/common/chatModel.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
2121
import { ILogService } from 'vs/platform/log/common/log';
2222
import { ChatAgentLocation, IChatAgentCommand, IChatAgentData, IChatAgentHistoryEntry, IChatAgentRequest, IChatAgentResult, IChatAgentService, reviveSerializedAgent } from 'vs/workbench/contrib/chat/common/chatAgents';
2323
import { ChatRequestTextPart, IParsedChatRequest, getPromptText, reviveParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes';
24-
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';
24+
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';
2525
import { IChatRequestVariableValue } from 'vs/workbench/contrib/chat/common/chatVariables';
2626

2727
export interface IChatRequestVariableEntry {
@@ -52,6 +52,7 @@ export interface IChatRequestModel {
5252
readonly message: IParsedChatRequest;
5353
readonly attempt: number;
5454
readonly variableData: IChatRequestVariableData;
55+
readonly locationData?: IChatLocationData;
5556
readonly response?: IChatResponseModel;
5657
}
5758

@@ -144,11 +145,16 @@ export class ChatRequestModel implements IChatRequestModel {
144145
this._variableData = v;
145146
}
146147

148+
public get locationData(): IChatLocationData | undefined {
149+
return this._locationData;
150+
}
151+
147152
constructor(
148153
private _session: ChatModel,
149154
public readonly message: IParsedChatRequest,
150155
private _variableData: IChatRequestVariableData,
151-
private _attempt: number = 0
156+
private _attempt: number = 0,
157+
private _locationData?: IChatLocationData
152158
) {
153159
this.id = 'request_' + ChatRequestModel.nextId++;
154160
}
@@ -861,8 +867,8 @@ export class ChatModel extends Disposable implements IChatModel {
861867
return this._requests;
862868
}
863869

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

868874
this._requests.push(request);

src/vs/workbench/contrib/chat/common/chatServiceImpl.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ export class ChatService extends Disposable implements IChatService {
350350

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

353-
await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, defaultAgent, location, options).responseCompletePromise;
353+
const resendOptions: IChatSendRequestOptions = {
354+
...options,
355+
locationData: request.locationData
356+
};
357+
await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, defaultAgent, location, resendOptions).responseCompletePromise;
354358
}
355359

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

484488
const initVariableData: IChatRequestVariableData = { variables: [] };
485-
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command);
489+
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command, options?.locationData);
486490
completeResponseCreated();
487491
const variableData = await this.chatVariablesService.resolveVariables(parsedRequest, options?.attachedContext, model, progressCallback, token);
488492
model.updateRequest(request, variableData);
@@ -500,7 +504,7 @@ export class ChatService extends Disposable implements IChatService {
500504
enableCommandDetection,
501505
attempt,
502506
location,
503-
locationData: options?.locationData,
507+
locationData: request.locationData,
504508
acceptedConfirmationData: options?.acceptedConfirmationData,
505509
rejectedConfirmationData: options?.rejectedConfirmationData,
506510
};

0 commit comments

Comments
 (0)