Skip to content

Commit

Permalink
Set relatesToPrecedingText flag when adding hints
Browse files Browse the repository at this point in the history
Fixes #KTIJ-3768

(cherry picked from commit a02e88cc51b43bd03214f5ee713fb67fb992fc6a)

IJ-MR-7775

GitOrigin-RevId: 569b0e1909d2ad4b0f86055be1f21dd9f326b2e2
  • Loading branch information
citizenmatt authored and intellij-monorepo-bot committed Mar 30, 2021
1 parent 6cde9d5 commit 5a17701
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ class InlayHintsPass(
val renderer = InlineInlayRenderer(entry.value)

val toBePlacedAtTheEndOfLine = entry.value.any { it.constraints?.placedAtTheEndOfLine ?: false }
val isRelatedToPrecedingText = entry.value.all { it.constraints?.relatesToPrecedingText ?: false }
val inlay = if (toBePlacedAtTheEndOfLine) {
inlayModel.addAfterLineEndElement(entry.intKey, true, renderer)
} else {
inlayModel.addInlineElement(entry.intKey, renderer) ?: break
inlayModel.addInlineElement(entry.intKey, isRelatedToPrecedingText, renderer) ?: break
}

inlay?.let { postprocessInlay(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,40 @@ class InlayPassTest : BasePlatformTestCase() {
assertEquals(2, extractContent(inlays, 1))
}

fun testInlaysRespectHorizontalConstraints() {
createPass(listOf(createOneOffCollector {
it.addInlineElement(1, true, TestRootPresentation(1), true)
it.addInlineElement(2, true, TestRootPresentation(2), false)
it.addInlineElement(3, false, TestRootPresentation(3), false)
})).collectAndApply()
var inlays = inlineElements
assertEquals(2, inlays.size)
assertTrue(inlays[0].isRelatedToPrecedingText)
assertFalse(inlays[1].isRelatedToPrecedingText)
inlays = afterLineEndElements
assertEquals(1, inlays.size)
}

fun testInlaysAtSameOffsetWithMatchingRelatesToPrecedingText() {
createPass(listOf(createOneOffCollector {
it.addInlineElement(1, true, TestRootPresentation(1), false)
it.addInlineElement(1, true, TestRootPresentation(2), false)
})).collectAndApply()
val inlays = inlineElements
assertEquals(1, inlays.size)
assertTrue(inlays[0].isRelatedToPrecedingText)
}

fun testInlaysAtSameOffsetWithDifferentRelatesToPrecedingTextDefaultToFalse() {
createPass(listOf(createOneOffCollector {
it.addInlineElement(1, true, TestRootPresentation(1), false)
it.addInlineElement(1, false, TestRootPresentation(2), false)
})).collectAndApply()
val inlays = inlineElements
assertEquals(1, inlays.size)
assertFalse(inlays[0].isRelatedToPrecedingText)
}

fun testPresentationUpdated() {
createPass(listOf(
createOneOffCollector {
Expand Down Expand Up @@ -161,6 +195,9 @@ class InlayPassTest : BasePlatformTestCase() {
private val inlineElements: List<Inlay<*>>
get() = inlayModel.getInlineElementsInRange(0, myFixture.file.textRange.endOffset)

private val afterLineEndElements: List<Inlay<*>>
get() = inlayModel.getAfterLineEndElementsInRange(0, myFixture.file.textRange.endOffset)

private val allHintsCount: Int
get() = inlineElements.size + blockElements.size
}

0 comments on commit 5a17701

Please sign in to comment.