Allow to skip prediction calculation IDEA-211599

GitOrigin-RevId: d35bae9481714df5f3af13b79bf326b1d55cba75
This commit is contained in:
Nikolay.Rykunov
2019-04-29 12:36:28 +03:00
committed by intellij-monorepo-bot
parent 2fe6f9c5bc
commit 581f7353f4
2 changed files with 14 additions and 11 deletions
@@ -4,9 +4,10 @@ package com.jetbrains.changeReminder.commit.handle
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.ThrowableComputable
import com.intellij.openapi.vcs.CheckinProjectPanel
import com.intellij.openapi.vcs.FilePath
import com.intellij.openapi.vcs.changes.ChangeListManager
@@ -37,6 +38,7 @@ class ChangeReminderCheckinHandler(private val panel: CheckinProjectPanel,
private val dataGetter: IndexDataGetter) : CheckinHandler() {
companion object {
private val LOG = Logger.getInstance(ChangeReminderCheckinHandler::class.java)
private const val PROGRESS_TITLE = "Calculating whether something should be added to this commit"
}
private val project: Project = panel.project
@@ -102,16 +104,15 @@ class ChangeReminderCheckinHandler(private val panel: CheckinProjectPanel,
}
val commitOptions = CommitOptions(panel.author(), panel.isAmend())
val task =
object : Task.WithResult<List<PredictedFile>, Exception>(project, PROGRESS_TITLE, true) {
override fun compute(indicator: ProgressIndicator): List<PredictedFile> = getPredictedFiles(rootFiles, commitOptions)
}.apply {
cancelText = "Skip"
}
val (executionTime, predictedFiles) = measureSupplierTimeMillis {
ProgressManager.getInstance()
.runProcessWithProgressSynchronously(
ThrowableComputable<List<PredictedFile>, Exception> {
getPredictedFiles(rootFiles, commitOptions)
},
"Calculating whether something should be added to this commit",
true,
project
)
ProgressManager.getInstance().run(task)
}
logEvent(project, ChangeReminderEvent.PREDICTION_CALCULATED, ChangeReminderData.EXECUTION_TIME, executionTime)
@@ -138,7 +139,7 @@ class ChangeReminderCheckinHandler(private val panel: CheckinProjectPanel,
}
}
catch (e: ProcessCanceledException) {
throw e
return ReturnResult.COMMIT
}
catch (e: Exception) {
LOG.error("Unexpected problem with ChangeReminder prediction", e)
@@ -1,6 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.changeReminder.predict
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vcs.FilePath
import com.jetbrains.changeReminder.prediction.model.PredictionModel
@@ -119,6 +120,7 @@ class PredictionProvider(private val minProb: Double = 0.55) {
getRelatedFiles(commit, history)
.asSequence()
.map { (candidateFile, candidateFileHistory) ->
ProgressManager.checkCanceled()
val fileScore = PredictionModel.makePrediction(collectFileFactors(commit, candidateFile, candidateFileHistory))
candidateFile to fileScore
}