Skip to content

fix Question ID #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
if (leetcodeEditor == null) {
return;
}
Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject());
Question question = ViewManager.getQuestionById(leetcodeEditor.getFrontendQuestionId(), anActionEvent.getProject());
if (question == null) {
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null"));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void update(@NotNull AnActionEvent anActionEvent) {
if (leetcodeEditor == null) {
return;
}
Question question = ViewManager.getDumbQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject());
Question question = ViewManager.getDumbQuestionById(leetcodeEditor.getFrontendQuestionId(), anActionEvent.getProject());
if (question == null) {
anActionEvent.getPresentation().setEnabled(false);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean isSelected(AnActionEvent anActionEvent) {
if (question == null) {
return false;
}
return tag.getQuestions().contains(question.getQuestionId());
return tag.getFrontendQuestionId().contains(question.getFrontendQuestionId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException
ProgressManager.getInstance().run(new Task.Backgroundable(project, PluginConstant.LEETCODE_EDITOR_TREE,false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
loadData(question,node,selPath,tree,toolWindow);
//loadData(question,node,selPath,tree,toolWindow);
MessageUtils.showMsg(toolWindow.getContentManager().getComponent(), MessageType.INFO, "info", "Temporarily disabled");
}
});
throw new ExpandVetoException(event);
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void openCode(Question question, Project project) {
return;
}

if (!fillQuestion(question, project)) {
if (!fillQuestion(question, codeTypeEnum, project)) {
return;
}

Expand All @@ -46,11 +46,9 @@ public static void openCode(Question question, Project project) {
if (file.exists()) {
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,true);
} else {
if (getQuestion(question, codeTypeEnum, project)) {
question.setContent(CommentUtils.createComment(question.getContent(), codeTypeEnum,config));
FileUtils.saveFile(file, VelocityUtils.convert(config.getCustomTemplate(), question));
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,true);
}
question.setContent(CommentUtils.createComment(question.getContent(), codeTypeEnum, config));
FileUtils.saveFile(file, VelocityUtils.convert(config.getCustomTemplate(), question));
FileUtils.openFileEditorAndSaveState(file, project, question, fillPath, true);
}
}

Expand All @@ -64,7 +62,7 @@ public static void openContent(Question question, Project project,boolean isOpen
return;
}

if (!fillQuestion(question, project)) {
if (!fillQuestion(question,codeTypeEnum, project)) {
return;
}

Expand All @@ -75,11 +73,8 @@ public static void openContent(Question question, Project project,boolean isOpen
if (file.exists()) {
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,isOpen);
} else {
if (getQuestion(question, codeTypeEnum, project)) {
FileUtils.saveFile(file, question.getContent());
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,isOpen);
}

FileUtils.saveFile(file, question.getContent());
FileUtils.openFileEditorAndSaveState(file, project, question, fillPath, isOpen);
}
}

Expand All @@ -95,8 +90,8 @@ private static boolean getQuestion(Question question, CodeTypeEnum codeTypeEnum,

JSONObject jsonObject = JSONObject.parseObject(body).getJSONObject("data").getJSONObject("question");

question.setQuestionId(jsonObject.getString("questionId"));
question.setContent(getContent(jsonObject));

question.setTestCase(jsonObject.getString("sampleTestCase"));

JSONArray jsonArray = jsonObject.getJSONArray("codeSnippets");
Expand Down Expand Up @@ -136,7 +131,7 @@ public static void SubmitCode(Question question, Project project) {
return;
}

if (!fillQuestion(question, project)) {
if (!fillQuestion(question,codeTypeEnum, project)) {
return;
}

Expand Down Expand Up @@ -178,7 +173,7 @@ public static void RunCodeCode(Question question, Project project) {
return;
}

if (!fillQuestion(question, project)) {
if (!fillQuestion(question,codeTypeEnum, project)) {
return;
}

Expand All @@ -199,7 +194,9 @@ public static void RunCodeCode(Question question, Project project) {
JSONObject returnObj = JSONObject.parseObject(body);
ProgressManager.getInstance().run(new RunCodeCheckTask(returnObj, project, question.getTestCase()));
MessageUtils.getInstance(project).showInfoMsg("info", PropertiesUtils.getInfo("request.pending"));
} else {
}else if (response != null && response.getStatusCode() == 429) {
MessageUtils.getInstance(project).showWarnMsg("error", "Please wait for the result.");
}else {
LogUtils.LOG.error("RuncodeCode failure " + response == null ? "" : response.getBody());
MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("request.failed"));
}
Expand Down Expand Up @@ -244,7 +241,7 @@ public static void setTestCaeAndLang(Question question, CodeTypeEnum codeTypeEnu
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
return;
}
if (!fillQuestion(question, project)) {
if (!fillQuestion(question,codeTypeEnum, project)) {
return;
}

Expand Down Expand Up @@ -279,7 +276,7 @@ public static void setTestCaeAndLang(Question question, CodeTypeEnum codeTypeEnu

}

private static boolean fillQuestion(Question question, Project project) {
public static boolean fillQuestion(Question question,CodeTypeEnum codeTypeEnum, Project project) {

if (Constant.NODETYPE_ITEM.equals(question.getNodeType())) {
ExploreManager.getItem(question);
Expand All @@ -288,9 +285,11 @@ private static boolean fillQuestion(Question question, Project project) {
return false;
} else {
question.setNodeType(Constant.NODETYPE_DEF);
return true;
}
}
if (StringUtils.isBlank(question.getQuestionId())){
return getQuestion(question,codeTypeEnum,project);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.alibaba.fastjson.JSONObject;
import com.intellij.openapi.project.Project;
import com.shuzijun.leetcode.plugin.model.CodeTypeEnum;
import com.shuzijun.leetcode.plugin.model.Question;
import com.shuzijun.leetcode.plugin.model.Tag;
import com.shuzijun.leetcode.plugin.setting.PersistentConfig;
import com.shuzijun.leetcode.plugin.utils.*;

/**
Expand All @@ -16,6 +18,15 @@ public static void addQuestionToFavorite(Tag tag, Question question, Project pro
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("login.not"));
return ;
}
CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(PersistentConfig.getInstance().getInitConfig().getCodeType());
if (codeTypeEnum == null) {
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
return;
}

if(!CodeManager.fillQuestion(question,codeTypeEnum,project)){
return;
}

try {
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(),"application/json");
Expand All @@ -27,7 +38,7 @@ public static void addQuestionToFavorite(Tag tag, Question question, Project pro
String body = response.getBody();
JSONObject object = JSONObject.parseObject(body).getJSONObject("data").getJSONObject("addQuestionToFavorite");
if (object.getBoolean("ok")) {
tag.getQuestions().add(question.getQuestionId());
tag.getFrontendQuestionId().add(question.getFrontendQuestionId());
} else {
MessageUtils.getInstance(project).showWarnMsg("info", object.getString("error"));
}
Expand All @@ -44,6 +55,15 @@ public static void removeQuestionFromFavorite(Tag tag, Question question,Project
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("login.not"));
return ;
}
CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(PersistentConfig.getInstance().getInitConfig().getCodeType());
if (codeTypeEnum == null) {
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
return;
}

if(!CodeManager.fillQuestion(question,codeTypeEnum,project)){
return;
}

try {
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(),"application/json");
Expand All @@ -55,7 +75,7 @@ public static void removeQuestionFromFavorite(Tag tag, Question question,Project
String body = response.getBody();
JSONObject object = JSONObject.parseObject(body).getJSONObject("data").getJSONObject("removeQuestionFromFavorite");
if (object.getBoolean("ok")) {
tag.getQuestions().remove(question.getQuestionId());
tag.getFrontendQuestionId().remove(question.getFrontendQuestionId());
} else {
MessageUtils.getInstance(project).showWarnMsg("info", object.getString("error"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public String apply(Question question) {
Tag tag = new Tag();
tag.setName(key);
for (Question question : questionImmutableMap.get(key)) {
tag.addQuestion(question.getQuestionId());
tag.addFrontendQuestionId(question.getFrontendQuestionId());
}
difficultyList.add(tag);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public String apply(Question question) {
Tag tag = new Tag();
tag.setName(key);
for (Question question : questionImmutableMap.get(key)) {
tag.addQuestion(question.getQuestionId());
tag.addFrontendQuestionId(question.getFrontendQuestionId());
}
statusList.add(tag);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ private static List<Question> parseQuestion(String str, Boolean isPremium) {
question.setTitle(object.getString("titleCn"));
}
question.setLeaf(Boolean.TRUE);
question.setQuestionId(object.getString("frontendQuestionId"));
//question.setQuestionId(object.getString("frontendQuestionId"));
question.setFrontendQuestionId(object.getString("frontendQuestionId"));
question.setAcceptance(object.getDouble("acRate"));
try {
Expand Down Expand Up @@ -298,7 +298,7 @@ private static List<Question> parseQuestion(String str, Boolean isPremium) {
return questionList;
}

private static void translation(List<Question> questions) {
/* private static void translation(List<Question> questions) {

if (URLUtils.isCn() && !PersistentConfig.getInstance().getConfig().getEnglishContent()) {

Expand Down Expand Up @@ -338,7 +338,7 @@ private static void translation(List<Question> questions) {
}

}
}
}*/

private static void questionOfToday() {
if (URLUtils.isCn()) {
Expand Down Expand Up @@ -377,7 +377,7 @@ private static List<Tag> parseTag(String str) {
tag.setName(name);
JSONArray questionArray = object.getJSONArray("questions");
for (int j = 0; j < questionArray.size(); j++) {
tag.addQuestion(questionArray.getInteger(j).toString());
tag.addFrontendQuestionId(questionArray.getInteger(j).toString());
}
tags.add(tag);
}
Expand Down Expand Up @@ -424,7 +424,7 @@ private static List<Tag> parseList(String str) {
tag.setName(name);
JSONArray questionArray = object.getJSONArray("questions");
for (int j = 0; j < questionArray.size(); j++) {
tag.addQuestion(questionArray.getInteger(j).toString());
tag.addFrontendQuestionId(questionArray.getInteger(j).toString());
}
tags.add(tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
import com.shuzijun.leetcode.plugin.window.WindowFactory;
import org.apache.commons.lang.StringUtils;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
Expand Down Expand Up @@ -62,14 +63,14 @@ public static void loadServiceData(JTree tree, Project project, String categoryS
question = Maps.uniqueIndex(questionList.iterator(), new Function<Question, String>() {
@Override
public String apply(Question question) {
return question.getQuestionId();
return question.getFrontendQuestionId();
}
});

filter.put(Constant.FIND_TYPE_DIFFICULTY, QuestionManager.getDifficulty());
filter.put(Constant.FIND_TYPE_STATUS, QuestionManager.getStatus());
filter.put(Constant.FIND_TYPE_LISTS, QuestionManager.getLists());
filter.put(Constant.FIND_TYPE_TAGS, QuestionManager.getTags());
//filter.put(Constant.FIND_TYPE_STATUS, QuestionManager.getStatus());
// filter.put(Constant.FIND_TYPE_LISTS, QuestionManager.getLists());
// filter.put(Constant.FIND_TYPE_TAGS, QuestionManager.getTags()); Temporarily disabled
filter.put(Constant.FIND_TYPE_CATEGORY, QuestionManager.getCategory(categorySlug));


Expand Down Expand Up @@ -140,12 +141,20 @@ public static void update(JTree tree) {
TreeSet<String> tagQuestionList = null;
for (Tag tag : tagList) {
if (tag.isSelect()) {
TreeSet<String> temp = tag.getQuestions();
TreeSet<String> temp = tag.getFrontendQuestionId();
if (tagQuestionList == null) {
tagQuestionList = new TreeSet(new Comparator<String>() {
@Override
public int compare(String arg0, String arg1) {
return Integer.valueOf(arg0).compareTo(Integer.valueOf(arg1));
if (StringUtils.isNumeric(arg0) && StringUtils.isNumeric(arg1)) {
return Integer.valueOf(arg0).compareTo(Integer.valueOf(arg1));
} else if (StringUtils.isNumeric(arg0)) {
return -1;
} else if (StringUtils.isNumeric(arg1)) {
return 1;
} else {
return arg0.compareTo(arg1);
}
}
});
tagQuestionList.addAll(temp);
Expand Down Expand Up @@ -279,11 +288,11 @@ public static Question getDumbQuestionById(String id, Project project) {
private static void addChild(DefaultMutableTreeNode rootNode, List<Tag> Lists, Map<String, Question> questionMap) {
if (!Lists.isEmpty()) {
for (Tag tag : Lists) {
long qCnt = tag.getQuestions().stream().filter(q -> questionMap.get(q) != null).count();
long qCnt = tag.getFrontendQuestionId().stream().filter(q -> questionMap.get(q) != null).count();
DefaultMutableTreeNode tagNode = new DefaultMutableTreeNode(new Question(String.format("%s(%d)",
tag.getName(), qCnt)));
rootNode.add(tagNode);
for (String key : tag.getQuestions()) {
for (String key : tag.getFrontendQuestionId()) {
if (questionMap.get(key) != null) {
tagNode.add(new DefaultMutableTreeNode(questionMap.get(key)));
}
Expand All @@ -309,7 +318,7 @@ public static void position(JTree tree, JBScrollPane scrollPane, Question questi
for (int i = 0, j = node.getChildCount(); i < j; i++) {
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i);
Question nodeData = (Question) childNode.getUserObject();
if (nodeData.getQuestionId().equals(question.getQuestionId())) {
if (nodeData.getFrontendQuestionId().equals(question.getFrontendQuestionId())) {
TreePath toShowPath = new TreePath(childNode.getPath());
tree.setSelectionPath(toShowPath);
Rectangle bounds = tree.getPathBounds(toShowPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class LeetcodeEditor {
private String path;

/**
* questionId
* frontendQuestionId
*/
private String questionId;
private String frontendQuestionId;


/**
Expand All @@ -39,12 +39,12 @@ public void setPath(String path) {
this.path = path;
}

public String getQuestionId() {
return questionId;
public String getFrontendQuestionId() {
return frontendQuestionId;
}

public void setQuestionId(String questionId) {
this.questionId = questionId;
public void setFrontendQuestionId(String frontendQuestionId) {
this.frontendQuestionId = frontendQuestionId;
}

public String getContentPath() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/shuzijun/leetcode/plugin/model/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public void setName(String name) {
this.name = name;
}

public TreeSet<String> getQuestions() {
public TreeSet<String> getFrontendQuestionId() {
return questions;
}
public void addQuestion(String questionId) {
questions.add(questionId);
public void addFrontendQuestionId(String frontendQuestionId) {
questions.add(frontendQuestionId);
}

public String getType() {
Expand Down
Loading