From b32a568da95813d67b4953e338c4deaba02102e4 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 14 Aug 2024 16:54:09 +0200 Subject: [PATCH] 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 https://github.com/microsoft/vscode-copilot/issues/7195 --- src/vs/workbench/contrib/chat/common/chatModel.ts | 14 ++++++++++---- .../contrib/chat/common/chatServiceImpl.ts | 10 +++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/chat/common/chatModel.ts b/src/vs/workbench/contrib/chat/common/chatModel.ts index 78284279f6082..466fe4ecc43ce 100644 --- a/src/vs/workbench/contrib/chat/common/chatModel.ts +++ b/src/vs/workbench/contrib/chat/common/chatModel.ts @@ -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 { @@ -52,6 +52,7 @@ export interface IChatRequestModel { readonly message: IParsedChatRequest; readonly attempt: number; readonly variableData: IChatRequestVariableData; + readonly locationData?: IChatLocationData; readonly response?: IChatResponseModel; } @@ -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++; } @@ -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); diff --git a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts index 68a88c6c79193..632335afce3b9 100644 --- a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts +++ b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts @@ -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 { @@ -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); @@ -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, };