Use ModalityState.any() for J2K post processing
#KT-17870 fixed
This commit is contained in:
@@ -17,7 +17,9 @@
|
|||||||
package org.jetbrains.kotlin.idea.core.util
|
package org.jetbrains.kotlin.idea.core.util
|
||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.application.ModalityState
|
||||||
import kotlinx.coroutines.experimental.CoroutineDispatcher
|
import kotlinx.coroutines.experimental.CoroutineDispatcher
|
||||||
|
import kotlin.coroutines.experimental.AbstractCoroutineContextElement
|
||||||
import kotlin.coroutines.experimental.CoroutineContext
|
import kotlin.coroutines.experimental.CoroutineContext
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +29,11 @@ public object EDT : CoroutineDispatcher() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun dispatch(context: CoroutineContext, block: Runnable) {
|
override fun dispatch(context: CoroutineContext, block: Runnable) {
|
||||||
ApplicationManager.getApplication().invokeLater(block)
|
val modalityState = context[ModalityStateElement.Key]?.modalityState ?: ModalityState.defaultModalityState()
|
||||||
|
ApplicationManager.getApplication().invokeLater(block, modalityState)
|
||||||
|
}
|
||||||
|
|
||||||
|
class ModalityStateElement(val modalityState: ModalityState) : AbstractCoroutineContextElement(Key) {
|
||||||
|
companion object Key : CoroutineContext.Key<ModalityStateElement>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.j2k
|
package org.jetbrains.kotlin.idea.j2k
|
||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.application.ModalityState
|
||||||
import com.intellij.openapi.editor.RangeMarker
|
import com.intellij.openapi.editor.RangeMarker
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -55,46 +56,47 @@ class J2kPostProcessor(private val formatCode: Boolean) : PostProcessor {
|
|||||||
PROCESS
|
PROCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doAdditionalProcessing(file: KtFile, rangeMarker: RangeMarker?) = runBlocking {
|
override fun doAdditionalProcessing(file: KtFile, rangeMarker: RangeMarker?) =
|
||||||
do {
|
runBlocking(EDT.ModalityStateElement(ModalityState.any())) {
|
||||||
var modificationStamp: Long? = file.modificationStamp
|
do {
|
||||||
val elementToActions = runReadAction {
|
var modificationStamp: Long? = file.modificationStamp
|
||||||
collectAvailableActions(file, rangeMarker)
|
val elementToActions = runReadAction {
|
||||||
}
|
collectAvailableActions(file, rangeMarker)
|
||||||
|
|
||||||
run(EDT) {
|
|
||||||
for ((element, action, _) in elementToActions) {
|
|
||||||
if (element.isValid) {
|
|
||||||
action()
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
modificationStamp = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modificationStamp == file.modificationStamp) break
|
run(EDT) {
|
||||||
}
|
for ((element, action, _) in elementToActions) {
|
||||||
while (elementToActions.isNotEmpty())
|
if (element.isValid) {
|
||||||
|
action()
|
||||||
|
}
|
||||||
if (formatCode) {
|
else {
|
||||||
run(EDT) {
|
modificationStamp = null
|
||||||
runWriteAction {
|
}
|
||||||
val codeStyleManager = CodeStyleManager.getInstance(file.project)
|
|
||||||
if (rangeMarker != null) {
|
|
||||||
if (rangeMarker.isValid) {
|
|
||||||
codeStyleManager.reformatRange(file, rangeMarker.startOffset, rangeMarker.endOffset)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
codeStyleManager.reformat(file)
|
if (modificationStamp == file.modificationStamp) break
|
||||||
|
}
|
||||||
|
while (elementToActions.isNotEmpty())
|
||||||
|
|
||||||
|
|
||||||
|
if (formatCode) {
|
||||||
|
run(EDT) {
|
||||||
|
runWriteAction {
|
||||||
|
val codeStyleManager = CodeStyleManager.getInstance(file.project)
|
||||||
|
if (rangeMarker != null) {
|
||||||
|
if (rangeMarker.isValid) {
|
||||||
|
codeStyleManager.reformatRange(file, rangeMarker.startOffset, rangeMarker.endOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
codeStyleManager.reformat(file)
|
||||||
|
}
|
||||||
|
Unit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Unit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private data class ActionData(val element: KtElement, val action: () -> Unit, val priority: Int)
|
private data class ActionData(val element: KtElement, val action: () -> Unit, val priority: Int)
|
||||||
|
|||||||
Reference in New Issue
Block a user