Skip to content

Commit

Permalink
Add view diff button api part 1
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Hu <[email protected]>
  • Loading branch information
daniel-hutao committed Nov 14, 2023
1 parent ba46c78 commit 79ee3df
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/ai/devchat/devchat/ActionHandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ai/devchat/devchat/DevChatActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 79ee3df

Please sign in to comment.