Dispose range markers in UI thread to prevent race condition at getting range (KT-28870)
#KT-28870 Fixed
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.conversion.copy
|
package org.jetbrains.kotlin.idea.conversion.copy
|
||||||
|
|
||||||
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
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
|
||||||
@@ -32,4 +33,16 @@ val PsiElement.range: TextRange
|
|||||||
get() = textRange!!
|
get() = textRange!!
|
||||||
|
|
||||||
val RangeMarker.range: TextRange?
|
val RangeMarker.range: TextRange?
|
||||||
get() = if (isValid) TextRange(startOffset, endOffset) else null
|
get() = if (isValid) {
|
||||||
|
val start = startOffset
|
||||||
|
val end = endOffset
|
||||||
|
if (start in 0..end) {
|
||||||
|
TextRange(start, end)
|
||||||
|
} else {
|
||||||
|
// Probably a race condition had happened
|
||||||
|
LOG.error("Invalid range [$start, $end] for range marker (valid = $isValid)")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
|
||||||
|
private val LOG = Logger.getInstance("RangeUtils")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.parameterInfo.custom
|
package org.jetbrains.kotlin.idea.parameterInfo.custom
|
||||||
|
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.editor.Document
|
import com.intellij.openapi.editor.Document
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.EditorFactory
|
import com.intellij.openapi.editor.EditorFactory
|
||||||
@@ -66,8 +67,11 @@ class KotlinCodeHintsModel(val project: Project) : EditorFactoryListenerWrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun dispose() {
|
fun dispose() {
|
||||||
for (marker in lineEndMarkers.keys()) {
|
val keys = lineEndMarkers.keys()
|
||||||
marker.dispose()
|
ApplicationManager.getApplication().invokeLater {
|
||||||
|
for (marker in keys) {
|
||||||
|
marker.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user