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 ba18c52fd6b0b03a2a35fa5f5e4179117bba3a5c..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;
@@ -46,8 +44,16 @@ public class StudySubtaskUtils {
         continue;
       }
       TaskFile taskFile = entry.getValue();
-      updatePlaceholderTexts(project, virtualFile, taskFile, fromSubtaskIndex, toSubtaskIndex);
+      Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
+      if (document == null) {
+        continue;
+      }
+      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);
@@ -68,46 +74,13 @@ public class StudySubtaskUtils {
   }
 
   private static void updatePlaceholderTexts(@NotNull Project project,
-                                             @NotNull VirtualFile virtualFile,
+                                             @NotNull Document document,
                                              @NotNull TaskFile taskFile,
                                              int fromSubtaskIndex,
                                              int toSubtaskIndex) {
-    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
-    if (document == null) {
-      return;
-    }
     taskFile.setTrackLengths(false);
     for (AnswerPlaceholder placeholder : taskFile.getAnswerPlaceholders()) {
-      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);
   }