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:
@@ -5,7 +5,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.parameterInfo.custom
|
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.editor.markup.TextAttributes
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -14,6 +17,10 @@ import com.intellij.psi.PsiManager
|
|||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
|
|
||||||
class ReturnHintLinePainter : EditorLinePainter() {
|
class ReturnHintLinePainter : EditorLinePainter() {
|
||||||
|
companion object {
|
||||||
|
val SPACE_LINE_EXTENSION_INFO = LineExtensionInfo(" ", TextAttributes())
|
||||||
|
}
|
||||||
|
|
||||||
override fun getLineExtensions(project: Project, file: VirtualFile, lineNumber: Int): List<LineExtensionInfo>? {
|
override fun getLineExtensions(project: Project, file: VirtualFile, lineNumber: Int): List<LineExtensionInfo>? {
|
||||||
val psiFile = PsiManager.getInstance(project).findFile(file) ?: return null
|
val psiFile = PsiManager.getInstance(project).findFile(file) ?: return null
|
||||||
if (psiFile.language != KotlinLanguage.INSTANCE) {
|
if (psiFile.language != KotlinLanguage.INSTANCE) {
|
||||||
@@ -23,8 +30,11 @@ class ReturnHintLinePainter : EditorLinePainter() {
|
|||||||
val hint = getLineHint(project, file, lineNumber)
|
val hint = getLineHint(project, file, lineNumber)
|
||||||
?: return null
|
?: return null
|
||||||
|
|
||||||
val hintLineInfo = LineExtensionInfo(" $hint", TextAttributes())
|
val textAttributes =
|
||||||
return listOf(hintLineInfo)
|
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? {
|
private fun getLineHint(project: Project, file: VirtualFile, lineNumber: Int): String? {
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
val actualText = run {
|
val actualText = run {
|
||||||
val tags = ArrayList<TagsTestDataUtil.TagInfo<*>>()
|
val tags = ArrayList<TagsTestDataUtil.TagInfo<*>>()
|
||||||
|
|
||||||
tags.addAll(collectActualLineExtensionsTags())
|
|
||||||
|
|
||||||
if (editor.caretModel.offset > 0) {
|
if (editor.caretModel.offset > 0) {
|
||||||
tags.add(CaretTag(editor))
|
tags.add(CaretTag(editor))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tags.addAll(collectActualLineExtensionsTags())
|
||||||
|
|
||||||
TagsTestDataUtil.insertTagsInText(tags, editor.document.text)
|
TagsTestDataUtil.insertTagsInText(tags, editor.document.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
"""
|
"""
|
||||||
val x = run {
|
val x = run {
|
||||||
println("foo")
|
println("foo")
|
||||||
1<caret><hint text=" ^run"/>
|
1<caret><hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@@ -165,7 +165,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
"""
|
"""
|
||||||
val x = run {
|
val x = run {
|
||||||
var s = "abc"
|
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 {
|
val x = run {
|
||||||
if (true) {
|
if (true) {
|
||||||
1<hint text=" ^run"/>
|
1<hint text=" "/><hint text="^run"/>
|
||||||
} else {
|
} else {
|
||||||
0<hint text=" ^run"/>
|
0<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@@ -190,7 +190,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
"""
|
"""
|
||||||
val x = run {
|
val x = run {
|
||||||
println(1)
|
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 {
|
val x = run {
|
||||||
when (true) {
|
when (true) {
|
||||||
true -> 1<hint text=" ^run"/>
|
true -> 1<hint text=" "/><hint text="^run"/>
|
||||||
false ->0<hint text=" ^run"/>
|
false -> 0<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@@ -224,7 +224,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
"""
|
"""
|
||||||
val x = run foo@{
|
val x = run foo@{
|
||||||
println("foo")
|
println("foo")
|
||||||
1<hint text=" ^foo"/>
|
1<hint text=" "/><hint text="^foo"/>
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@@ -239,10 +239,10 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
run { // Two hints here
|
run { // Two hints here
|
||||||
when (true) {
|
when (true) {
|
||||||
true -> 1<hint text=" ^run"/>
|
true -> 1<hint text=" "/><hint text="^run"/>
|
||||||
false -> 0<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() {
|
fun foo() {
|
||||||
run {
|
run {
|
||||||
val length: Int? = null
|
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
|
var test = 0
|
||||||
run {
|
run {
|
||||||
test
|
test
|
||||||
test++<hint text=" ^run"/>
|
test++<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
test
|
test
|
||||||
++test<hint text=" ^run"/>
|
++test<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@@ -290,12 +290,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
run {
|
run {
|
||||||
val files: Any? = null
|
val files: Any? = null
|
||||||
@Some
|
@Some
|
||||||
12<hint text=" ^run"/>
|
12<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val files: Any? = null
|
val files: Any? = null
|
||||||
@Some 12<hint text=" ^run"/>
|
@Some 12<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@@ -309,12 +309,12 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
run {
|
run {
|
||||||
val files: Any? = null
|
val files: Any? = null
|
||||||
run@
|
run@
|
||||||
12<hint text=" ^run"/>
|
12<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val files: Any? = null
|
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 {
|
fun test() = run {
|
||||||
val a = 1
|
val a = 1
|
||||||
{ a }<hint text=" ^run"/>
|
{ a }<hint text=" "/><hint text="^run"/>
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user