From affc7e10aa489680f7dc93843689237d470db8f5 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Wed, 15 Nov 2023 11:27:44 +0800 Subject: [PATCH] Chore: rename old addContext/request to addContext/notify Signed-off-by: Daniel Hu --- .../ai/devchat/devchat/DevChatActions.java | 1 + .../handler/AddContextNotifyHandler.java | 40 +++++++++++++++++++ .../handler/AddContextRequestHandler.java | 32 --------------- .../idea/action/AddToDevChatAction.java | 8 ++-- 4 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 src/main/java/ai/devchat/devchat/handler/AddContextNotifyHandler.java delete mode 100644 src/main/java/ai/devchat/devchat/handler/AddContextRequestHandler.java diff --git a/src/main/java/ai/devchat/devchat/DevChatActions.java b/src/main/java/ai/devchat/devchat/DevChatActions.java index 6f596ca..ecad83d 100644 --- a/src/main/java/ai/devchat/devchat/DevChatActions.java +++ b/src/main/java/ai/devchat/devchat/DevChatActions.java @@ -7,6 +7,7 @@ public class DevChatActions { public static final String SET_OR_UPDATE_KEY_RESPONSE = "setOrUpdateKey/response"; public static final String ADD_CONTEXT_REQUEST = "addContext/request"; public static final String ADD_CONTEXT_RESPONSE = "addContext/response"; + public static final String ADD_CONTEXT_NOTIFY = "addContext/notify"; public static final String LIST_COMMANDS_REQUEST = "listCommands/request"; public static final String LIST_COMMANDS_RESPONSE = "listCommands/response"; public static final String LIST_CONVERSATIONS_REQUEST = "listConversations/request"; diff --git a/src/main/java/ai/devchat/devchat/handler/AddContextNotifyHandler.java b/src/main/java/ai/devchat/devchat/handler/AddContextNotifyHandler.java new file mode 100644 index 0000000..1b70a2a --- /dev/null +++ b/src/main/java/ai/devchat/devchat/handler/AddContextNotifyHandler.java @@ -0,0 +1,40 @@ +package ai.devchat.devchat.handler; + +import ai.devchat.devchat.ActionHandler; +import ai.devchat.devchat.DevChatActionHandler; +import ai.devchat.devchat.DevChatActions; + +import com.alibaba.fastjson.JSONObject; + +public class AddContextNotifyHandler implements ActionHandler { + private JSONObject metadata; + private JSONObject payload; + private final DevChatActionHandler devChatActionHandler; + + public final String RESPONSE_FUNC = "AddContextFromEditor"; + + public AddContextNotifyHandler(DevChatActionHandler devChatActionHandler) { + this.devChatActionHandler = devChatActionHandler; + } + + @Override + public void executeAction() { + devChatActionHandler.sendResponse(DevChatActions.ADD_CONTEXT_NOTIFY, RESPONSE_FUNC, (metadata, payload) -> { + metadata.put("status", "success"); + metadata.put("error", ""); + + payload.put("path", this.payload.getString("path")); + payload.put("content", this.payload.getString("content")); + payload.put("languageId", this.payload.getString("languageId")); + payload.put("startLine", this.payload.getInteger("startLine")); + }); + } + + public void setMetadata(JSONObject metadata) { + this.metadata = metadata; + } + + public void setPayload(JSONObject payload) { + this.payload = payload; + } +} diff --git a/src/main/java/ai/devchat/devchat/handler/AddContextRequestHandler.java b/src/main/java/ai/devchat/devchat/handler/AddContextRequestHandler.java deleted file mode 100644 index 6480e54..0000000 --- a/src/main/java/ai/devchat/devchat/handler/AddContextRequestHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package ai.devchat.devchat.handler; - -import ai.devchat.devchat.ActionHandler; -import ai.devchat.devchat.DevChatActionHandler; -import com.alibaba.fastjson.JSONObject; - -public class AddContextRequestHandler implements ActionHandler { - private JSONObject metadata; - private JSONObject payload; - - private final DevChatActionHandler devChatActionHandler; - - public AddContextRequestHandler(DevChatActionHandler devChatActionHandler) { - this.devChatActionHandler = devChatActionHandler; - } - - @Override - public void executeAction() { - devChatActionHandler.sendResponse("addContext/notify", "AddContextFromEditor", (metadata, payload) -> { - payload.put("path", payload.getString("path")); - payload.put("content", payload.getString("content")); - }); - } - - public void setMetadata(JSONObject metadata) { - this.metadata = metadata; - } - - public void setPayload(JSONObject payload) { - this.payload = payload; - } -} diff --git a/src/main/java/ai/devchat/idea/action/AddToDevChatAction.java b/src/main/java/ai/devchat/idea/action/AddToDevChatAction.java index 7fd5792..0d8c7f3 100644 --- a/src/main/java/ai/devchat/idea/action/AddToDevChatAction.java +++ b/src/main/java/ai/devchat/idea/action/AddToDevChatAction.java @@ -2,7 +2,7 @@ import ai.devchat.common.Log; import ai.devchat.devchat.DevChatActionHandler; -import ai.devchat.devchat.handler.AddContextRequestHandler; +import ai.devchat.devchat.handler.AddContextNotifyHandler; import com.alibaba.fastjson.JSONObject; public class AddToDevChatAction { @@ -24,8 +24,8 @@ public void execute(String filePath, String fileContent, String language, int st payload.put("languageId", language); payload.put("startLine", startLine); - AddContextRequestHandler addContextRequestHandler = new AddContextRequestHandler(actionHandler); - addContextRequestHandler.setPayload(payload); - addContextRequestHandler.executeAction(); + AddContextNotifyHandler addContextNotifyHandler = new AddContextNotifyHandler(actionHandler); + addContextNotifyHandler.setPayload(payload); + addContextNotifyHandler.executeAction(); } }