mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inlay hints: exception from one provider should not crash other providers
GitOrigin-RevId: bcbf8d4374d5cbf3f20a43491c3d1d54f9bf03b3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b4c3e87358
commit
462422eb89
@@ -8,6 +8,9 @@ import com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager
|
||||
import com.intellij.codeInsight.hints.presentation.PresentationFactory
|
||||
import com.intellij.concurrency.ConcurrentCollectionFactory
|
||||
import com.intellij.concurrency.JobLauncher
|
||||
import com.intellij.diff.tools.util.base.DiffViewerBase
|
||||
import com.intellij.idea.IdeaLogger
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.Inlay
|
||||
import com.intellij.openapi.editor.InlayModel
|
||||
@@ -36,7 +39,6 @@ class InlayHintsPass(
|
||||
private val priorityRange: ProperTextRange,
|
||||
private val sharedSink: InlayHintsSinkImpl,
|
||||
) : EditorBoundHighlightingPass(editor, rootElement.containingFile, true), DumbAware {
|
||||
|
||||
override fun doCollectInformation(progress: ProgressIndicator) {
|
||||
if (!HighlightingLevelManager.getInstance(myFile.project).shouldHighlight(myFile)) return
|
||||
if (enabledCollectors.isEmpty()) return
|
||||
@@ -53,7 +55,7 @@ class InlayHintsPass(
|
||||
val skippedCollectors = ConcurrentCollectionFactory.createConcurrentSet<Int>()
|
||||
|
||||
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(
|
||||
(elementsInside + elementsOutside),
|
||||
elementsInside + elementsOutside,
|
||||
progress,
|
||||
true,
|
||||
false,
|
||||
@@ -68,6 +70,10 @@ class InlayHintsPass(
|
||||
}
|
||||
catch (_: IndexNotReadyException) {
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
if (Logger.shouldRethrow(e)) throw e;
|
||||
LOG.error(e)
|
||||
}
|
||||
progress.checkCanceled()
|
||||
}
|
||||
true
|
||||
@@ -89,6 +95,7 @@ class InlayHintsPass(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val LOG: Logger = Logger.getInstance(DiffViewerBase::class.java)
|
||||
private const val BULK_CHANGE_THRESHOLD = 1000
|
||||
private val MANAGED_KEY = Key.create<Boolean>("managed.inlay")
|
||||
private val PLACEHOLDER_KEY = Key.create<Boolean>("inlay.placeholder")
|
||||
@@ -156,7 +163,7 @@ class InlayHintsPass(
|
||||
inlayModel: InlayModel,
|
||||
map: ConcurrentIntObjectMap<MutableList<ConstrainedPresentation<*, BlockConstraints>>>,
|
||||
showAbove: Boolean,
|
||||
isPlaceholder: Boolean
|
||||
isPlaceholder: Boolean,
|
||||
) {
|
||||
for (entry in map.entrySet()) {
|
||||
val presentations = entry.value
|
||||
@@ -172,10 +179,12 @@ class InlayHintsPass(
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldBeBulk(hints: HintsBuffer?,
|
||||
existingInlineInlays: MutableList<Inlay<out InlineInlayRenderer>>,
|
||||
existingBlockAboveInlays: MutableList<Inlay<out PresentationContainerRenderer<*>>>,
|
||||
existingBlockBelowInlays: MutableList<Inlay<out PresentationContainerRenderer<*>>>): Boolean {
|
||||
private fun shouldBeBulk(
|
||||
hints: HintsBuffer?,
|
||||
existingInlineInlays: MutableList<Inlay<out InlineInlayRenderer>>,
|
||||
existingBlockAboveInlays: MutableList<Inlay<out PresentationContainerRenderer<*>>>,
|
||||
existingBlockBelowInlays: MutableList<Inlay<out PresentationContainerRenderer<*>>>,
|
||||
): Boolean {
|
||||
val totalChangesCount = when {
|
||||
hints != null -> estimateChangesCountForPlacement(existingInlineInlays.offsets(), hints, Inlay.Placement.INLINE) +
|
||||
estimateChangesCountForPlacement(existingBlockAboveInlays.offsets(), hints, Inlay.Placement.ABOVE_LINE) +
|
||||
@@ -187,11 +196,12 @@ class InlayHintsPass(
|
||||
|
||||
private fun List<Inlay<*>>.offsets(): IntStream = stream().mapToInt { it.offset }
|
||||
|
||||
private fun updateOrDispose(existing: List<Inlay<out PresentationContainerRenderer<*>>>,
|
||||
hints: HintsBuffer?,
|
||||
placement: Inlay.Placement,
|
||||
factory: InlayPresentationFactory,
|
||||
editor: Editor
|
||||
private fun updateOrDispose(
|
||||
existing: List<Inlay<out PresentationContainerRenderer<*>>>,
|
||||
hints: HintsBuffer?,
|
||||
placement: Inlay.Placement,
|
||||
factory: InlayPresentationFactory,
|
||||
editor: Editor,
|
||||
) {
|
||||
for (inlay in existing) {
|
||||
val managed = inlay.getUserData(MANAGED_KEY) ?: continue
|
||||
@@ -233,7 +243,7 @@ class InlayHintsPass(
|
||||
new: List<ConstrainedPresentation<*, *>>,
|
||||
factory: InlayPresentationFactory,
|
||||
placement: Inlay.Placement,
|
||||
editor: Editor
|
||||
editor: Editor,
|
||||
) {
|
||||
if (!isAcceptablePlacement(placement)) {
|
||||
throw IllegalArgumentException()
|
||||
|
||||
Reference in New Issue
Block a user