do not show errors when switching to the next subtask
[idea/community.git] / python / educational-core / student / src / com / jetbrains / edu / learning / StudySubtaskUtils.java
index 45499d5aa637d4bb5a08db9798501d03bf4e2651..895acdba3c2c691e93e74a7005104442ca869dc7 100644 (file)
@@ -5,13 +5,11 @@ import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.problems.WolfTheProblemSolver;
 import com.intellij.ui.EditorNotifications;
-import com.intellij.util.containers.ContainerUtil;
 import com.jetbrains.edu.learning.checker.StudyCheckUtils;
 import com.jetbrains.edu.learning.core.EduNames;
-import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
-import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo;
 import com.jetbrains.edu.learning.courseFormat.Task;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.ui.StudyToolWindow;
@@ -52,6 +50,10 @@ public class StudySubtaskUtils {
       }
       updatePlaceholderTexts(project, document, taskFile, fromSubtaskIndex, toSubtaskIndex);
       EditorNotifications.getInstance(project).updateNotifications(virtualFile);
+      if (StudyUtils.isStudyProject(project)) {
+        WolfTheProblemSolver.getInstance(project).clearProblems(virtualFile);
+        taskFile.setHighlightErrors(false);
+      }
     }
     task.setActiveSubtaskIndex(toSubtaskIndex);
     update(project, task, taskDir);
@@ -71,51 +73,14 @@ public class StudySubtaskUtils {
     }
   }
 
-  public static void updatePlaceholderTexts(@NotNull Project project,
+  private static void updatePlaceholderTexts(@NotNull Project project,
                                              @NotNull Document document,
                                              @NotNull TaskFile taskFile,
                                              int fromSubtaskIndex,
                                              int toSubtaskIndex) {
     taskFile.setTrackLengths(false);
     for (AnswerPlaceholder placeholder : taskFile.getAnswerPlaceholders()) {
-      AnswerPlaceholderSubtaskInfo fromSubtaskInfo = placeholder.getSubtaskInfos().get(fromSubtaskIndex);
-      if (fromSubtaskIndex == toSubtaskIndex && fromSubtaskInfo != null) {
-        String placeholderText = fromSubtaskInfo.getPlaceholderText();
-        if (placeholderText != null) {
-          EduUtils.replaceAnswerPlaceholder(project, document, placeholder, placeholder.getRealLength(), placeholderText);
-        }
-        continue;
-      }
-      Set<Integer> indexes = placeholder.getSubtaskInfos().keySet();
-      Integer minIndex = Collections.min(indexes);
-      int visibleLength = placeholder.getVisibleLength(fromSubtaskIndex);
-      if (indexes.contains(toSubtaskIndex) && indexes.contains(fromSubtaskIndex)) {
-        if (!placeholder.getUseLength()) {
-          String replacementText = placeholder.getSubtaskInfos().get(toSubtaskIndex).getPossibleAnswer();
-          EduUtils.replaceAnswerPlaceholder(project, document, placeholder, visibleLength, replacementText);
-        }
-        continue;
-      }
-      if (fromSubtaskIndex < toSubtaskIndex) {
-        if (minIndex > fromSubtaskIndex && minIndex <= toSubtaskIndex) {
-          Integer maxIndex = Collections.max(ContainerUtil.filter(indexes, integer -> integer <= toSubtaskIndex));
-          AnswerPlaceholderSubtaskInfo maxInfo = placeholder.getSubtaskInfos().get(maxIndex);
-          String replacementText = placeholder.getUseLength() ? maxInfo.getPlaceholderText() : maxInfo.getPossibleAnswer();
-          EduUtils.replaceAnswerPlaceholder(project, document, placeholder, visibleLength, replacementText);
-        }
-      }
-      else {
-        if (minIndex > toSubtaskIndex && minIndex <= fromSubtaskIndex) {
-          AnswerPlaceholderSubtaskInfo minInfo = placeholder.getSubtaskInfos().get(minIndex);
-          if (minInfo.isNeedInsertText()) {
-            EduUtils.replaceAnswerPlaceholder(project, document, placeholder, visibleLength, "");
-          }
-          else {
-            String replacementText = minInfo.getPlaceholderText();
-            EduUtils.replaceAnswerPlaceholder(project, document, placeholder, visibleLength, replacementText);
-          }
-        }
-      }
+      placeholder.switchSubtask(project, document, fromSubtaskIndex, toSubtaskIndex);
     }
     taskFile.setTrackLengths(true);
   }