From 79ee3dfcfb5f4ec3ab9962914820ced340dd28a3 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Tue, 14 Nov 2023 16:35:07 +0800 Subject: [PATCH] Add view diff button api part 1 Signed-off-by: Daniel Hu --- .../devchat/devchat/ActionHandlerFactory.java | 1 + .../ai/devchat/devchat/DevChatActions.java | 2 + .../handler/ViewDiffRequestHandler.java | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/ai/devchat/devchat/handler/ViewDiffRequestHandler.java diff --git a/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java b/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java index 515f4e5..d41609d 100644 --- a/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java +++ b/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java @@ -17,6 +17,7 @@ public class ActionHandlerFactory { put(DevChatActions.LIST_TOPICS_REQUEST, ListTopicsRequestHandler.class); put(DevChatActions.INSERT_CODE_REQUEST, InsertCodeRequestHandler.class); put(DevChatActions.REPLACE_FILE_CONTENT_REQUEST, ReplaceFileContentHandler.class); + put(DevChatActions.VIEW_DIFF_REQUEST, ViewDiffRequestHandler.class); } }; diff --git a/src/main/java/ai/devchat/devchat/DevChatActions.java b/src/main/java/ai/devchat/devchat/DevChatActions.java index 4facc56..dfb4f03 100644 --- a/src/main/java/ai/devchat/devchat/DevChatActions.java +++ b/src/main/java/ai/devchat/devchat/DevChatActions.java @@ -17,4 +17,6 @@ public class DevChatActions { public static final String INSERT_CODE_RESPONSE = "insertCode/response"; public static final String REPLACE_FILE_CONTENT_REQUEST = "replaceFileContent/request"; public static final String REPLACE_FILE_CONTENT_RESPONSE = "replaceFileContent/response"; + public static final String VIEW_DIFF_REQUEST = "viewDiff/request"; + public static final String VIEW_DIFF_RESPONSE = "viewDiff/response"; } diff --git a/src/main/java/ai/devchat/devchat/handler/ViewDiffRequestHandler.java b/src/main/java/ai/devchat/devchat/handler/ViewDiffRequestHandler.java new file mode 100644 index 0000000..a4e85c4 --- /dev/null +++ b/src/main/java/ai/devchat/devchat/handler/ViewDiffRequestHandler.java @@ -0,0 +1,37 @@ +package ai.devchat.devchat.handler; + +import ai.devchat.common.Log; +import ai.devchat.devchat.ActionHandler; +import ai.devchat.devchat.DevChatActionHandler; +import com.alibaba.fastjson.JSONObject; +import com.intellij.psi.PsiFileFactory; + +public class ViewDiffRequestHandler implements ActionHandler { + private JSONObject metadata; + private JSONObject payload; + private final DevChatActionHandler devChatActionHandler; + + public ViewDiffRequestHandler(DevChatActionHandler devChatActionHandler) { + this.devChatActionHandler = devChatActionHandler; + } + + @Override + public void executeAction() { + Log.info("Handling view diff request"); + String callbackFunc = metadata.getString("callback"); + String diffContent = payload.getString("content"); + + PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(devChatActionHandler.getProject()); +// PsiFile psiFile = psiFileFactory.createFileFromText("yourFileName.java", , diffContent); + } + + @Override + public void setMetadata(JSONObject metadata) { + this.metadata = metadata; + } + + @Override + public void setPayload(JSONObject payload) { + this.payload = payload; + } +}