From 42ca54fbf9e42da44dd3121cf55d6bc61e3e11cb Mon Sep 17 00:00:00 2001 From: xinyi-gong Date: Fri, 8 May 2026 14:31:47 +0800 Subject: [PATCH 1/2] fix restore chat session related issues --- .../eclipse/core/lsp/CopilotLanguageServerConnection.java | 4 ++-- .../eclipse/core/persistence/ConversationDataFactory.java | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java index 8aaa7f6d..5f8b26f1 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java @@ -298,9 +298,9 @@ public CompletableFuture createConversation(String workDoneTok param.setWorkspaceFolder(agentJobWorkspaceFolder); } - // Set historical turns if provided. + // Set historical turns if provided, inserting them before the current user message. if (turns != null && turns.size() > 0) { - param.getTurns().addAll(turns); + param.getTurns().addAll(0, turns); } // TODO: remove needToolCallConfirmation when CLS fully supports it across all IDEs. diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java index 8ba73a6e..bc21f228 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java @@ -26,7 +26,7 @@ import com.microsoft.copilot.eclipse.core.persistence.CopilotTurnData.ReplyData; import com.microsoft.copilot.eclipse.core.persistence.CopilotTurnData.ToolCallData; import com.microsoft.copilot.eclipse.core.persistence.UserTurnData.MessageData; -import com.microsoft.copilot.eclipse.core.utils.ChatMessageUtils; + /** * Factory for creating and transforming conversation data objects. Responsible only for pure data transformation with @@ -221,9 +221,8 @@ public List convertToTurns(List turnDataList) { // TODO: We don't persist images for now, so hard code the modelSupportVersion to false. In the future, handle // images in responses and pass the model support version here if needed. String responseText = extractResponseFromCopilotTurnData(copilotTurnData); - Either> response = ChatMessageUtils - .createMessageWithImages(responseText, new ArrayList<>(), false); - result.add(new Turn(response, responseText, null)); + Either> request = Either.forLeft(""); + result.add(new Turn(request, responseText, null)); } } return result; From 26c318f4d135801b9e43140e5b5d221ce507945d Mon Sep 17 00:00:00 2001 From: xinyi-gong Date: Fri, 8 May 2026 14:45:07 +0800 Subject: [PATCH 2/2] resolve comments --- .../core/lsp/CopilotLanguageServerConnection.java | 14 +++++++------- .../core/persistence/ConversationDataFactory.java | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java index 5f8b26f1..44892c10 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java @@ -286,23 +286,23 @@ public CompletableFuture createConversation(String workDoneTok param.setChatMode(chatModeName); param.setCustomChatModeId(customChatModeId); + // Set historical turns if provided, inserting them before the current user message. + if (turns != null && turns.size() > 0) { + param.getTurns().addAll(0, turns); + } + if (StringUtils.isBlank(agentSlug)) { param.setWorkspaceFolder(PlatformUtils.getWorkspaceRootUri()); param.setWorkspaceFolders(LSPEclipseUtils.getWorkspaceFolders()); param.setTodoList(todos); } else { - // Set agentSlug if provided - this will modify the first turn's agentSlug + // Set agentSlug on the last turn (current user message) after history insertion if (param.getTurns() != null && !param.getTurns().isEmpty()) { - param.getTurns().get(0).setAgentSlug(agentSlug); + param.getTurns().get(param.getTurns().size() - 1).setAgentSlug(agentSlug); } param.setWorkspaceFolder(agentJobWorkspaceFolder); } - // Set historical turns if provided, inserting them before the current user message. - if (turns != null && turns.size() > 0) { - param.getTurns().addAll(0, turns); - } - // TODO: remove needToolCallConfirmation when CLS fully supports it across all IDEs. param.setNeedToolCallConfirmation(true); if (currentFile != null) { diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java index bc21f228..530f3baa 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java @@ -218,8 +218,7 @@ public List convertToTurns(List turnDataList) { .forLeft(requestText == null ? "" : requestText); result.add(new Turn(request, null, null)); } else if (turnData instanceof CopilotTurnData copilotTurnData) { - // TODO: We don't persist images for now, so hard code the modelSupportVersion to false. In the future, handle - // images in responses and pass the model support version here if needed. + // Assistant turns only contribute the response text; the request field is intentionally empty. String responseText = extractResponseFromCopilotTurnData(copilotTurnData); Either> request = Either.forLeft(""); result.add(new Turn(request, responseText, null));