Ability to disable caches reset on ProcessCanceledException via internal action

This commit is contained in:
Valentin Kipyatkov
2017-07-26 22:12:15 +03:00
parent 41b13d25f2
commit 454c5229f9
3 changed files with 27 additions and 12 deletions
@@ -16,10 +16,12 @@
package org.jetbrains.kotlin.storage package org.jetbrains.kotlin.storage
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.util.ModificationTracker import com.intellij.openapi.util.ModificationTracker
import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException
import java.util.concurrent.atomic.AtomicLong import org.jetbrains.kotlin.utils.isProcessCanceledException
import org.jetbrains.kotlin.utils.rethrow import org.jetbrains.kotlin.utils.rethrow
import java.util.concurrent.atomic.AtomicLong
open class ExceptionTracker : ModificationTracker, LockBasedStorageManager.ExceptionHandlingStrategy { open class ExceptionTracker : ModificationTracker, LockBasedStorageManager.ExceptionHandlingStrategy {
private val cancelledTracker: AtomicLong = AtomicLong() private val cancelledTracker: AtomicLong = AtomicLong()
@@ -27,7 +29,9 @@ open class ExceptionTracker : ModificationTracker, LockBasedStorageManager.Excep
override fun handleException(throwable: Throwable): RuntimeException { override fun handleException(throwable: Throwable): RuntimeException {
// should not increment counter when ReenteringLazyValueComputationException is thrown since it implements correct frontend behaviour // should not increment counter when ReenteringLazyValueComputationException is thrown since it implements correct frontend behaviour
if (throwable !is ReenteringLazyValueComputationException) { if (throwable !is ReenteringLazyValueComputationException) {
incCounter() if (!throwable.isProcessCanceledException() || CacheResetOnProcessCanceled.enabled) {
incCounter()
}
} }
throw rethrow(throwable) throw rethrow(throwable)
} }
@@ -44,3 +48,14 @@ open class ExceptionTracker : ModificationTracker, LockBasedStorageManager.Excep
return this::class.java.name + ": " + modificationCount return this::class.java.name + ": " + modificationCount
} }
} }
object CacheResetOnProcessCanceled {
private val PROPERTY = "kotlin.internal.cacheResetOnProcessCanceled"
private val DEFAULT_VALUE = true
var enabled: Boolean
get() = PropertiesComponent.getInstance()!!.getBoolean(PROPERTY, DEFAULT_VALUE)
set(value) {
PropertiesComponent.getInstance()!!.setValue(PROPERTY, value, DEFAULT_VALUE)
}
}
+3 -3
View File
@@ -150,9 +150,9 @@
class="org.jetbrains.kotlin.idea.actions.internal.benchmark.HighlightingBenchmarkAction" class="org.jetbrains.kotlin.idea.actions.internal.benchmark.HighlightingBenchmarkAction"
text="Benchmark highlighting"/> text="Benchmark highlighting"/>
<action id="CompletionBindingContextCachingToggleAction" <action id="CacheResetOnProcessCanceledToggleAction"
class="org.jetbrains.kotlin.idea.actions.internal.CompletionBindingContextCachingToggleAction" class="org.jetbrains.kotlin.idea.actions.internal.CacheResetOnProcessCanceledToggleAction"
text="Enable completion binding context caching"/> text="Reset caches on ProcessCanceledException"/>
<action id="CheckComponentsUsageSearchAction" class="org.jetbrains.kotlin.idea.actions.internal.CheckComponentsUsageSearchAction" <action id="CheckComponentsUsageSearchAction" class="org.jetbrains.kotlin.idea.actions.internal.CheckComponentsUsageSearchAction"
text="Check Component Functions Usage Search"/> text="Check Component Functions Usage Search"/>
@@ -18,18 +18,18 @@ package org.jetbrains.kotlin.idea.actions.internal
import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.ToggleAction import com.intellij.openapi.actionSystem.ToggleAction
import org.jetbrains.kotlin.idea.completion.CompletionBindingContextProvider import org.jetbrains.kotlin.storage.CacheResetOnProcessCanceled
class CompletionBindingContextCachingToggleAction : ToggleAction() { class CacheResetOnProcessCanceledToggleAction : ToggleAction() {
override fun isSelected(e: AnActionEvent?): Boolean = override fun isSelected(e: AnActionEvent): Boolean =
CompletionBindingContextProvider.ENABLED CacheResetOnProcessCanceled.enabled
override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(e: AnActionEvent?, state: Boolean) { CacheResetOnProcessCanceled.enabled = state
CompletionBindingContextProvider.ENABLED = state
} }
override fun update(e: AnActionEvent) { override fun update(e: AnActionEvent) {
super.update(e)
e.presentation.isEnabledAndVisible = KotlinInternalMode.enabled e.presentation.isEnabledAndVisible = KotlinInternalMode.enabled
} }
} }