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
This commit is contained in:
Nikolay Krasko
2019-03-01 16:21:21 +03:00
parent 0e990ae01b
commit 606a7766af
2 changed files with 34 additions and 24 deletions
@@ -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<LineExtensionInfo>? {
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? {
@@ -83,12 +83,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
val actualText = run {
val tags = ArrayList<TagsTestDataUtil.TagInfo<*>>()
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<caret><hint text=" ^run"/>
1<caret><hint text=" "/><hint text="^run"/>
}
"""
)
@@ -165,7 +165,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
"""
val x = run {
var s = "abc"
s.length<caret><hint text=" ^run"/>
s.length<caret><hint text=" "/><hint text="^run"/>
}
"""
)
@@ -176,9 +176,9 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
"""
val x = run {
if (true) {
1<hint text=" ^run"/>
1<hint text=" "/><hint text="^run"/>
} else {
0<hint text=" ^run"/>
0<hint text=" "/><hint text="^run"/>
}
}
"""
@@ -190,7 +190,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
"""
val x = run {
println(1)
if (true) 1 else { 0 }<caret><hint text=" ^run"/>
if (true) 1 else { 0 }<caret><hint text=" "/><hint text="^run"/>
}
"""
)
@@ -201,8 +201,8 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
"""
val x = run {
when (true) {
true -> 1<hint text=" ^run"/>
false ->0<hint text=" ^run"/>
true -> 1<hint text=" "/><hint text="^run"/>
false -> 0<hint text=" "/><hint text="^run"/>
}
}
"""
@@ -224,7 +224,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
"""
val x = run foo@{
println("foo")
1<hint text=" ^foo"/>
1<hint text=" "/><hint text="^foo"/>
}
"""
)
@@ -239,10 +239,10 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
run { // Two hints here
when (true) {
true -> 1<hint text=" ^run"/>
false -> 0<hint text=" ^run"/>
true -> 1<hint text=" "/><hint text="^run"/>
false -> 0<hint text=" "/><hint text="^run"/>
}
}<hint text=" ^hello"/>
}<hint text=" "/><hint text="^hello"/>
}
"""
)
@@ -254,7 +254,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
fun foo() {
run {
val length: Int? = null
length ?: 0<hint text=" ^run"/>
length ?: 0<hint text=" "/><hint text="^run"/>
}
}
"""
@@ -268,12 +268,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
var test = 0
run {
test
test++<hint text=" ^run"/>
test++<hint text=" "/><hint text="^run"/>
}
run {
test
++test<hint text=" ^run"/>
++test<hint text=" "/><hint text="^run"/>
}
}
"""
@@ -290,12 +290,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
run {
val files: Any? = null
@Some
12<hint text=" ^run"/>
12<hint text=" "/><hint text="^run"/>
}
run {
val files: Any? = null
@Some 12<hint text=" ^run"/>
@Some 12<hint text=" "/><hint text="^run"/>
}
}
"""
@@ -309,12 +309,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
run {
val files: Any? = null
run@
12<hint text=" ^run"/>
12<hint text=" "/><hint text="^run"/>
}
run {
val files: Any? = null
run@12<hint text=" ^run"/>
run@12<hint text=" "/><hint text="^run"/>
}
}
"""
@@ -326,7 +326,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
"""
fun test() = run {
val a = 1
{ a }<hint text=" ^run"/>
{ a }<hint text=" "/><hint text="^run"/>
}
"""
)