Skip to content

Commit 7e1ac86

Browse files
authored
Merge pull request #395 from shuzijun/gradle
fix Question ID
2 parents c2dca14 + 7418849 commit 7e1ac86

File tree

13 files changed

+84
-55
lines changed

13 files changed

+84
-55
lines changed

src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
2828
if (leetcodeEditor == null) {
2929
return;
3030
}
31-
Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject());
31+
Question question = ViewManager.getQuestionById(leetcodeEditor.getFrontendQuestionId(), anActionEvent.getProject());
3232
if (question == null) {
3333
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null"));
3434
return;

src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenSolutionAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void update(@NotNull AnActionEvent anActionEvent) {
3030
if (leetcodeEditor == null) {
3131
return;
3232
}
33-
Question question = ViewManager.getDumbQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject());
33+
Question question = ViewManager.getDumbQuestionById(leetcodeEditor.getFrontendQuestionId(), anActionEvent.getProject());
3434
if (question == null) {
3535
anActionEvent.getPresentation().setEnabled(false);
3636
return;

src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public boolean isSelected(AnActionEvent anActionEvent) {
3737
if (question == null) {
3838
return false;
3939
}
40-
return tag.getQuestions().contains(question.getQuestionId());
40+
return tag.getFrontendQuestionId().contains(question.getFrontendQuestionId());
4141
}
4242

4343
@Override

src/main/java/com/shuzijun/leetcode/plugin/listener/TreeWillListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException
5454
ProgressManager.getInstance().run(new Task.Backgroundable(project, PluginConstant.LEETCODE_EDITOR_TREE,false) {
5555
@Override
5656
public void run(@NotNull ProgressIndicator progressIndicator) {
57-
loadData(question,node,selPath,tree,toolWindow);
57+
//loadData(question,node,selPath,tree,toolWindow);
58+
MessageUtils.showMsg(toolWindow.getContentManager().getComponent(), MessageType.INFO, "info", "Temporarily disabled");
5859
}
5960
});
6061
throw new ExpandVetoException(event);

src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void openCode(Question question, Project project) {
3131
return;
3232
}
3333

34-
if (!fillQuestion(question, project)) {
34+
if (!fillQuestion(question, codeTypeEnum, project)) {
3535
return;
3636
}
3737

@@ -46,11 +46,9 @@ public static void openCode(Question question, Project project) {
4646
if (file.exists()) {
4747
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,true);
4848
} else {
49-
if (getQuestion(question, codeTypeEnum, project)) {
50-
question.setContent(CommentUtils.createComment(question.getContent(), codeTypeEnum,config));
51-
FileUtils.saveFile(file, VelocityUtils.convert(config.getCustomTemplate(), question));
52-
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,true);
53-
}
49+
question.setContent(CommentUtils.createComment(question.getContent(), codeTypeEnum, config));
50+
FileUtils.saveFile(file, VelocityUtils.convert(config.getCustomTemplate(), question));
51+
FileUtils.openFileEditorAndSaveState(file, project, question, fillPath, true);
5452
}
5553
}
5654

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

67-
if (!fillQuestion(question, project)) {
65+
if (!fillQuestion(question,codeTypeEnum, project)) {
6866
return;
6967
}
7068

@@ -75,11 +73,8 @@ public static void openContent(Question question, Project project,boolean isOpen
7573
if (file.exists()) {
7674
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,isOpen);
7775
} else {
78-
if (getQuestion(question, codeTypeEnum, project)) {
79-
FileUtils.saveFile(file, question.getContent());
80-
FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,isOpen);
81-
}
82-
76+
FileUtils.saveFile(file, question.getContent());
77+
FileUtils.openFileEditorAndSaveState(file, project, question, fillPath, isOpen);
8378
}
8479
}
8580

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

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

93+
question.setQuestionId(jsonObject.getString("questionId"));
9894
question.setContent(getContent(jsonObject));
99-
10095
question.setTestCase(jsonObject.getString("sampleTestCase"));
10196

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

139-
if (!fillQuestion(question, project)) {
134+
if (!fillQuestion(question,codeTypeEnum, project)) {
140135
return;
141136
}
142137

@@ -178,7 +173,7 @@ public static void RunCodeCode(Question question, Project project) {
178173
return;
179174
}
180175

181-
if (!fillQuestion(question, project)) {
176+
if (!fillQuestion(question,codeTypeEnum, project)) {
182177
return;
183178
}
184179

@@ -199,7 +194,9 @@ public static void RunCodeCode(Question question, Project project) {
199194
JSONObject returnObj = JSONObject.parseObject(body);
200195
ProgressManager.getInstance().run(new RunCodeCheckTask(returnObj, project, question.getTestCase()));
201196
MessageUtils.getInstance(project).showInfoMsg("info", PropertiesUtils.getInfo("request.pending"));
202-
} else {
197+
}else if (response != null && response.getStatusCode() == 429) {
198+
MessageUtils.getInstance(project).showWarnMsg("error", "Please wait for the result.");
199+
}else {
203200
LogUtils.LOG.error("RuncodeCode failure " + response == null ? "" : response.getBody());
204201
MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("request.failed"));
205202
}
@@ -244,7 +241,7 @@ public static void setTestCaeAndLang(Question question, CodeTypeEnum codeTypeEnu
244241
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
245242
return;
246243
}
247-
if (!fillQuestion(question, project)) {
244+
if (!fillQuestion(question,codeTypeEnum, project)) {
248245
return;
249246
}
250247

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

280277
}
281278

282-
private static boolean fillQuestion(Question question, Project project) {
279+
public static boolean fillQuestion(Question question,CodeTypeEnum codeTypeEnum, Project project) {
283280

284281
if (Constant.NODETYPE_ITEM.equals(question.getNodeType())) {
285282
ExploreManager.getItem(question);
@@ -288,9 +285,11 @@ private static boolean fillQuestion(Question question, Project project) {
288285
return false;
289286
} else {
290287
question.setNodeType(Constant.NODETYPE_DEF);
291-
return true;
292288
}
293289
}
290+
if (StringUtils.isBlank(question.getQuestionId())){
291+
return getQuestion(question,codeTypeEnum,project);
292+
}
294293
return true;
295294
}
296295

src/main/java/com/shuzijun/leetcode/plugin/manager/FavoriteManager.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.alibaba.fastjson.JSONObject;
44
import com.intellij.openapi.project.Project;
5+
import com.shuzijun.leetcode.plugin.model.CodeTypeEnum;
56
import com.shuzijun.leetcode.plugin.model.Question;
67
import com.shuzijun.leetcode.plugin.model.Tag;
8+
import com.shuzijun.leetcode.plugin.setting.PersistentConfig;
79
import com.shuzijun.leetcode.plugin.utils.*;
810

911
/**
@@ -16,6 +18,15 @@ public static void addQuestionToFavorite(Tag tag, Question question, Project pro
1618
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("login.not"));
1719
return ;
1820
}
21+
CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(PersistentConfig.getInstance().getInitConfig().getCodeType());
22+
if (codeTypeEnum == null) {
23+
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
24+
return;
25+
}
26+
27+
if(!CodeManager.fillQuestion(question,codeTypeEnum,project)){
28+
return;
29+
}
1930

2031
try {
2132
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(),"application/json");
@@ -27,7 +38,7 @@ public static void addQuestionToFavorite(Tag tag, Question question, Project pro
2738
String body = response.getBody();
2839
JSONObject object = JSONObject.parseObject(body).getJSONObject("data").getJSONObject("addQuestionToFavorite");
2940
if (object.getBoolean("ok")) {
30-
tag.getQuestions().add(question.getQuestionId());
41+
tag.getFrontendQuestionId().add(question.getFrontendQuestionId());
3142
} else {
3243
MessageUtils.getInstance(project).showWarnMsg("info", object.getString("error"));
3344
}
@@ -44,6 +55,15 @@ public static void removeQuestionFromFavorite(Tag tag, Question question,Project
4455
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("login.not"));
4556
return ;
4657
}
58+
CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(PersistentConfig.getInstance().getInitConfig().getCodeType());
59+
if (codeTypeEnum == null) {
60+
MessageUtils.getInstance(project).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
61+
return;
62+
}
63+
64+
if(!CodeManager.fillQuestion(question,codeTypeEnum,project)){
65+
return;
66+
}
4767

4868
try {
4969
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(),"application/json");
@@ -55,7 +75,7 @@ public static void removeQuestionFromFavorite(Tag tag, Question question,Project
5575
String body = response.getBody();
5676
JSONObject object = JSONObject.parseObject(body).getJSONObject("data").getJSONObject("removeQuestionFromFavorite");
5777
if (object.getBoolean("ok")) {
58-
tag.getQuestions().remove(question.getQuestionId());
78+
tag.getFrontendQuestionId().remove(question.getFrontendQuestionId());
5979
} else {
6080
MessageUtils.getInstance(project).showWarnMsg("info", object.getString("error"));
6181
}

src/main/java/com/shuzijun/leetcode/plugin/manager/QuestionManager.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public String apply(Question question) {
148148
Tag tag = new Tag();
149149
tag.setName(key);
150150
for (Question question : questionImmutableMap.get(key)) {
151-
tag.addQuestion(question.getQuestionId());
151+
tag.addFrontendQuestionId(question.getFrontendQuestionId());
152152
}
153153
difficultyList.add(tag);
154154
}
@@ -179,7 +179,7 @@ public String apply(Question question) {
179179
Tag tag = new Tag();
180180
tag.setName(key);
181181
for (Question question : questionImmutableMap.get(key)) {
182-
tag.addQuestion(question.getQuestionId());
182+
tag.addFrontendQuestionId(question.getFrontendQuestionId());
183183
}
184184
statusList.add(tag);
185185
}
@@ -256,7 +256,7 @@ private static List<Question> parseQuestion(String str, Boolean isPremium) {
256256
question.setTitle(object.getString("titleCn"));
257257
}
258258
question.setLeaf(Boolean.TRUE);
259-
question.setQuestionId(object.getString("frontendQuestionId"));
259+
//question.setQuestionId(object.getString("frontendQuestionId"));
260260
question.setFrontendQuestionId(object.getString("frontendQuestionId"));
261261
question.setAcceptance(object.getDouble("acRate"));
262262
try {
@@ -298,7 +298,7 @@ private static List<Question> parseQuestion(String str, Boolean isPremium) {
298298
return questionList;
299299
}
300300

301-
private static void translation(List<Question> questions) {
301+
/* private static void translation(List<Question> questions) {
302302
303303
if (URLUtils.isCn() && !PersistentConfig.getInstance().getConfig().getEnglishContent()) {
304304
@@ -338,7 +338,7 @@ private static void translation(List<Question> questions) {
338338
}
339339
340340
}
341-
}
341+
}*/
342342

343343
private static void questionOfToday() {
344344
if (URLUtils.isCn()) {
@@ -377,7 +377,7 @@ private static List<Tag> parseTag(String str) {
377377
tag.setName(name);
378378
JSONArray questionArray = object.getJSONArray("questions");
379379
for (int j = 0; j < questionArray.size(); j++) {
380-
tag.addQuestion(questionArray.getInteger(j).toString());
380+
tag.addFrontendQuestionId(questionArray.getInteger(j).toString());
381381
}
382382
tags.add(tag);
383383
}
@@ -424,7 +424,7 @@ private static List<Tag> parseList(String str) {
424424
tag.setName(name);
425425
JSONArray questionArray = object.getJSONArray("questions");
426426
for (int j = 0; j < questionArray.size(); j++) {
427-
tag.addQuestion(questionArray.getInteger(j).toString());
427+
tag.addFrontendQuestionId(questionArray.getInteger(j).toString());
428428
}
429429
tags.add(tag);
430430
}

src/main/java/com/shuzijun/leetcode/plugin/manager/ViewManager.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
1414
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
1515
import com.shuzijun.leetcode.plugin.window.WindowFactory;
16+
import org.apache.commons.lang.StringUtils;
1617

1718
import javax.swing.*;
1819
import javax.swing.tree.DefaultMutableTreeNode;
@@ -62,14 +63,14 @@ public static void loadServiceData(JTree tree, Project project, String categoryS
6263
question = Maps.uniqueIndex(questionList.iterator(), new Function<Question, String>() {
6364
@Override
6465
public String apply(Question question) {
65-
return question.getQuestionId();
66+
return question.getFrontendQuestionId();
6667
}
6768
});
6869

6970
filter.put(Constant.FIND_TYPE_DIFFICULTY, QuestionManager.getDifficulty());
70-
filter.put(Constant.FIND_TYPE_STATUS, QuestionManager.getStatus());
71-
filter.put(Constant.FIND_TYPE_LISTS, QuestionManager.getLists());
72-
filter.put(Constant.FIND_TYPE_TAGS, QuestionManager.getTags());
71+
//filter.put(Constant.FIND_TYPE_STATUS, QuestionManager.getStatus());
72+
// filter.put(Constant.FIND_TYPE_LISTS, QuestionManager.getLists());
73+
// filter.put(Constant.FIND_TYPE_TAGS, QuestionManager.getTags()); Temporarily disabled
7374
filter.put(Constant.FIND_TYPE_CATEGORY, QuestionManager.getCategory(categorySlug));
7475

7576

@@ -140,12 +141,20 @@ public static void update(JTree tree) {
140141
TreeSet<String> tagQuestionList = null;
141142
for (Tag tag : tagList) {
142143
if (tag.isSelect()) {
143-
TreeSet<String> temp = tag.getQuestions();
144+
TreeSet<String> temp = tag.getFrontendQuestionId();
144145
if (tagQuestionList == null) {
145146
tagQuestionList = new TreeSet(new Comparator<String>() {
146147
@Override
147148
public int compare(String arg0, String arg1) {
148-
return Integer.valueOf(arg0).compareTo(Integer.valueOf(arg1));
149+
if (StringUtils.isNumeric(arg0) && StringUtils.isNumeric(arg1)) {
150+
return Integer.valueOf(arg0).compareTo(Integer.valueOf(arg1));
151+
} else if (StringUtils.isNumeric(arg0)) {
152+
return -1;
153+
} else if (StringUtils.isNumeric(arg1)) {
154+
return 1;
155+
} else {
156+
return arg0.compareTo(arg1);
157+
}
149158
}
150159
});
151160
tagQuestionList.addAll(temp);
@@ -279,11 +288,11 @@ public static Question getDumbQuestionById(String id, Project project) {
279288
private static void addChild(DefaultMutableTreeNode rootNode, List<Tag> Lists, Map<String, Question> questionMap) {
280289
if (!Lists.isEmpty()) {
281290
for (Tag tag : Lists) {
282-
long qCnt = tag.getQuestions().stream().filter(q -> questionMap.get(q) != null).count();
291+
long qCnt = tag.getFrontendQuestionId().stream().filter(q -> questionMap.get(q) != null).count();
283292
DefaultMutableTreeNode tagNode = new DefaultMutableTreeNode(new Question(String.format("%s(%d)",
284293
tag.getName(), qCnt)));
285294
rootNode.add(tagNode);
286-
for (String key : tag.getQuestions()) {
295+
for (String key : tag.getFrontendQuestionId()) {
287296
if (questionMap.get(key) != null) {
288297
tagNode.add(new DefaultMutableTreeNode(questionMap.get(key)));
289298
}
@@ -309,7 +318,7 @@ public static void position(JTree tree, JBScrollPane scrollPane, Question questi
309318
for (int i = 0, j = node.getChildCount(); i < j; i++) {
310319
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i);
311320
Question nodeData = (Question) childNode.getUserObject();
312-
if (nodeData.getQuestionId().equals(question.getQuestionId())) {
321+
if (nodeData.getFrontendQuestionId().equals(question.getFrontendQuestionId())) {
313322
TreePath toShowPath = new TreePath(childNode.getPath());
314323
tree.setSelectionPath(toShowPath);
315324
Rectangle bounds = tree.getPathBounds(toShowPath);

src/main/java/com/shuzijun/leetcode/plugin/model/LeetcodeEditor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class LeetcodeEditor {
1313
private String path;
1414

1515
/**
16-
* questionId
16+
* frontendQuestionId
1717
*/
18-
private String questionId;
18+
private String frontendQuestionId;
1919

2020

2121
/**
@@ -39,12 +39,12 @@ public void setPath(String path) {
3939
this.path = path;
4040
}
4141

42-
public String getQuestionId() {
43-
return questionId;
42+
public String getFrontendQuestionId() {
43+
return frontendQuestionId;
4444
}
4545

46-
public void setQuestionId(String questionId) {
47-
this.questionId = questionId;
46+
public void setFrontendQuestionId(String frontendQuestionId) {
47+
this.frontendQuestionId = frontendQuestionId;
4848
}
4949

5050
public String getContentPath() {

src/main/java/com/shuzijun/leetcode/plugin/model/Tag.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public void setName(String name) {
4545
this.name = name;
4646
}
4747

48-
public TreeSet<String> getQuestions() {
48+
public TreeSet<String> getFrontendQuestionId() {
4949
return questions;
5050
}
51-
public void addQuestion(String questionId) {
52-
questions.add(questionId);
51+
public void addFrontendQuestionId(String frontendQuestionId) {
52+
questions.add(frontendQuestionId);
5353
}
5454

5555
public String getType() {

0 commit comments

Comments
 (0)