From 606a7766afc5a7c4cdfd43e744e8fa1e206ca7d5 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 1 Mar 2019 16:21:21 +0300 Subject: [PATCH] Make colours for lambda return hints similar to other hints (KT-30203) Works for IntlliJ and Darcula themes but doesn't work with High Contrast --- .../custom/ReturnHintLinePainter.kt | 16 +++++-- .../LambdaReturnValueHintsTest.kt | 42 +++++++++---------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/custom/ReturnHintLinePainter.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/custom/ReturnHintLinePainter.kt index f03329b298c..6a0d4904792 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/custom/ReturnHintLinePainter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/custom/ReturnHintLinePainter.kt @@ -5,7 +5,10 @@ package org.jetbrains.kotlin.idea.parameterInfo.custom -import com.intellij.openapi.editor.* +import com.intellij.openapi.editor.DefaultLanguageHighlighterColors +import com.intellij.openapi.editor.EditorLinePainter +import com.intellij.openapi.editor.LineExtensionInfo +import com.intellij.openapi.editor.colors.EditorColorsManager import com.intellij.openapi.editor.markup.TextAttributes import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.project.Project @@ -14,6 +17,10 @@ import com.intellij.psi.PsiManager import org.jetbrains.kotlin.idea.KotlinLanguage class ReturnHintLinePainter : EditorLinePainter() { + companion object { + val SPACE_LINE_EXTENSION_INFO = LineExtensionInfo(" ", TextAttributes()) + } + override fun getLineExtensions(project: Project, file: VirtualFile, lineNumber: Int): List? { val psiFile = PsiManager.getInstance(project).findFile(file) ?: return null if (psiFile.language != KotlinLanguage.INSTANCE) { @@ -23,8 +30,11 @@ class ReturnHintLinePainter : EditorLinePainter() { val hint = getLineHint(project, file, lineNumber) ?: return null - val hintLineInfo = LineExtensionInfo(" $hint", TextAttributes()) - return listOf(hintLineInfo) + val textAttributes = + EditorColorsManager.getInstance().globalScheme.getAttributes(DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT) + val hintLineInfo = LineExtensionInfo(hint, textAttributes) + + return listOf(SPACE_LINE_EXTENSION_INFO, hintLineInfo) } private fun getLineHint(project: Project, file: VirtualFile, lineNumber: Int): String? { diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt index 9b66f3c5fd2..7f9bdd21d51 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt @@ -83,12 +83,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { val actualText = run { val tags = ArrayList>() - tags.addAll(collectActualLineExtensionsTags()) - if (editor.caretModel.offset > 0) { tags.add(CaretTag(editor)) } + tags.addAll(collectActualLineExtensionsTags()) + TagsTestDataUtil.insertTagsInText(tags, editor.document.text) } @@ -154,7 +154,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ val x = run { println("foo") - 1 + 1 } """ ) @@ -165,7 +165,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ val x = run { var s = "abc" - s.length + s.length } """ ) @@ -176,9 +176,9 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ val x = run { if (true) { - 1 + 1 } else { - 0 + 0 } } """ @@ -190,7 +190,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ val x = run { println(1) - if (true) 1 else { 0 } + if (true) 1 else { 0 } } """ ) @@ -201,8 +201,8 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ val x = run { when (true) { - true -> 1 - false ->0 + true -> 1 + false -> 0 } } """ @@ -224,7 +224,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ val x = run foo@{ println("foo") - 1 + 1 } """ ) @@ -239,10 +239,10 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { run { // Two hints here when (true) { - true -> 1 - false -> 0 + true -> 1 + false -> 0 } - } + } } """ ) @@ -254,7 +254,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { fun foo() { run { val length: Int? = null - length ?: 0 + length ?: 0 } } """ @@ -268,12 +268,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { var test = 0 run { test - test++ + test++ } run { test - ++test + ++test } } """ @@ -290,12 +290,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { run { val files: Any? = null @Some - 12 + 12 } run { val files: Any? = null - @Some 12 + @Some 12 } } """ @@ -309,12 +309,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { run { val files: Any? = null run@ - 12 + 12 } run { val files: Any? = null - run@12 + run@12 } } """ @@ -326,7 +326,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ fun test() = run { val a = 1 - { a } + { a } } """ )