From 462422eb893c409fca137a050003193a93044aa9 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 24 Sep 2025 16:30:01 +0200 Subject: [PATCH] inlay hints: exception from one provider should not crash other providers GitOrigin-RevId: bcbf8d4374d5cbf3f20a43491c3d1d54f9bf03b3 --- .../codeInsight/hints/InlayHintsPass.kt | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt b/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt index bcf16fd2ab9a..714c95d2d657 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt @@ -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() 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("managed.inlay") private val PLACEHOLDER_KEY = Key.create("inlay.placeholder") @@ -156,7 +163,7 @@ class InlayHintsPass( inlayModel: InlayModel, map: ConcurrentIntObjectMap>>, 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>, - existingBlockAboveInlays: MutableList>>, - existingBlockBelowInlays: MutableList>>): Boolean { + private fun shouldBeBulk( + hints: HintsBuffer?, + existingInlineInlays: MutableList>, + existingBlockAboveInlays: MutableList>>, + existingBlockBelowInlays: MutableList>>, + ): 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>.offsets(): IntStream = stream().mapToInt { it.offset } - private fun updateOrDispose(existing: List>>, - hints: HintsBuffer?, - placement: Inlay.Placement, - factory: InlayPresentationFactory, - editor: Editor + private fun updateOrDispose( + existing: List>>, + 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>, factory: InlayPresentationFactory, placement: Inlay.Placement, - editor: Editor + editor: Editor, ) { if (!isAcceptablePlacement(placement)) { throw IllegalArgumentException()