override fun resolveConflicts()

in intellij-plugin/educational-core/src/com/jetbrains/edu/coursecreator/framework/diff/DiffConflictResolveStrategy.kt [39:82]


  override fun resolveConflicts(
    currentState: Map<String, String>,
    baseState: Map<String, String>,
    targetState: Map<String, String>
  ): FLConflictResolveStrategy.StateWithResolvedChanges {
    // try to resolve simple conflicts
    val (changedFiles, resolvedSimpleConflictsState) = resolveSimpleConflicts(currentState, baseState, targetState)
    if (changedFiles.isEmpty()) {
      return FLConflictResolveStrategy.StateWithResolvedChanges(changedFiles, resolvedSimpleConflictsState)
    }
    val conflictFiles = mutableListOf<String>()
    val resolvedState = resolvedSimpleConflictsState.toMutableMap()

    computeUnderProgress(project, EduCoreBundle.message("action.Educational.Educator.SyncChangesWithNextTasks.conflict.resolution.smart.indicator")) { indicator ->
      for (changedFile in changedFiles) {
        val leftContent = currentState[changedFile]
        val baseContent = baseState[changedFile]
        val rightContent = targetState[changedFile]

        // do not try to resolve if conflict isn't (modified, modified)
        if (leftContent == null || baseContent == null || rightContent == null) {
          conflictFiles += changedFile
          continue
        }

        val resolvedBaseContent = resolvedSimpleConflictsState[changedFile] ?: error("Base state with resolved conflicts shouldn't be null")

        val contents = ThreeSideContentInfo(leftContent, resolvedBaseContent, rightContent)

        // create a temporary document with base content for a merge model
        val baseDocument = EditorFactory.getInstance().createDocument(contents.baseContent)

        val allConflictsAreSolved = tryResolveConflictsForDocument(project, baseDocument, contents, indicator)
        // do not change an original base text if the file contains unresolvable conflicts
        if (!allConflictsAreSolved) {
          conflictFiles += changedFile
        }
        else {
          resolvedState[changedFile] = baseDocument.text
        }
      }
    }
    return FLConflictResolveStrategy.StateWithResolvedChanges(conflictFiles, resolvedState)
  }