PY-74339 [Jupyter] Do not report not cell produced inlays in offset check

GitOrigin-RevId: 4c85483e4410f1b7aa6ec5c2f1e88fc881ab6697
This commit is contained in:
Anton Efimchuk
2024-08-01 11:16:35 +02:00
committed by intellij-monorepo-bot
parent f1fa70f3ec
commit 05d99a3f9e
5 changed files with 28 additions and 1 deletions

View File

@@ -323,8 +323,12 @@ class NotebookCellInlayManager private constructor(
add(editor.document.getLineEndOffset(cell.interval.lines.last))
}
}
val wronglyPlacedInlays = editor.inlayModel.getBlockElementsInRange(0, editor.document.textLength)
val wronglyPlacedInlays = _cells.asSequence()
.mapNotNull { it.view }
.flatMap { it.getInlays() }
.filter { it.offset !in inlaysOffsets }
.toSet()
if (wronglyPlacedInlays.isNotEmpty()) {
thisLogger().error("Expected offsets: $inlaysOffsets. Wrongly placed offsets: ${wronglyPlacedInlays.map { it.offset }} of inlays $wronglyPlacedInlays, for file = '${editor.virtualFile?.name}'")
}

View File

@@ -3,6 +3,7 @@ package org.jetbrains.plugins.notebooks.visualization.ui
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.FoldRegion
import com.intellij.openapi.editor.Inlay
import com.intellij.openapi.editor.ex.FoldingModelEx
import com.intellij.openapi.util.Disposer
import org.jetbrains.plugins.notebooks.visualization.NotebookCellInlayController
@@ -66,4 +67,8 @@ class ControllerEditorCellViewComponent(
private fun createFoldRegion(foldingModel: FoldingModelEx, regionToFold: IntRange): FoldRegion? =
foldingModel.createFoldRegion(regionToFold.first, regionToFold.last, "", null, true)
override fun doGetInlays(): Sequence<Inlay<*>> {
return sequenceOf(controller.inlay)
}
}

View File

@@ -288,6 +288,10 @@ class EditorCellOutputs(
}
}
}
override fun doGetInlays(): Sequence<Inlay<*>> {
return inlay?.let { sequenceOf(it) } ?: emptySequence()
}
}
private var JComponent.outputComponentFactory: NotebookOutputComponentFactory<*, *>? by SwingClientProperty("outputComponentFactory")

View File

@@ -10,6 +10,7 @@ import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorKind
import com.intellij.openapi.editor.FoldRegion
import com.intellij.openapi.editor.Inlay
import com.intellij.openapi.editor.VisualPosition
import com.intellij.openapi.editor.ex.RangeHighlighterEx
import com.intellij.openapi.editor.impl.EditorImpl
@@ -456,6 +457,10 @@ class EditorCellView(
}
}
override fun doGetInlays(): Sequence<Inlay<*>> {
return controllers.map { it.inlay }.asSequence()
}
companion object {
val WAS_FOLDED_IN_RENDERED_STATE_KEY = Key<Boolean>("jupyter.markdown.folding.was.rendered")
}

View File

@@ -1,5 +1,6 @@
package org.jetbrains.plugins.notebooks.visualization.ui
import com.intellij.openapi.editor.Inlay
import org.jetbrains.plugins.notebooks.visualization.UpdateContext
import java.awt.Rectangle
@@ -39,4 +40,12 @@ abstract class EditorCellViewComponent {
it.updateCellFolding(updateContext)
}
}
fun getInlays(): Sequence<Inlay<*>> {
return doGetInlays() + children.asSequence().flatMap { it.getInlays() }
}
open fun doGetInlays(): Sequence<Inlay<*>> {
return emptySequence()
}
}