KT-11612 Highlight named arguments in the editor somehow
#KT-11612 Fixed
This commit is contained in:
+1
@@ -87,6 +87,7 @@ public class KotlinHighlightingColors {
|
||||
public static final TextAttributesKey LABEL = createTextAttributesKey("KOTLIN_LABEL");
|
||||
public static final TextAttributesKey DEBUG_INFO = createTextAttributesKey("KOTLIN_DEBUG_INFO");
|
||||
public static final TextAttributesKey RESOLVED_TO_ERROR = createTextAttributesKey("KOTLIN_RESOLVED_TO_ERROR");
|
||||
public static final TextAttributesKey NAMED_ARGUMENT = createTextAttributesKey("KOTLIN_NAMED_ARGUMENT");
|
||||
|
||||
private KotlinHighlightingColors() {
|
||||
}
|
||||
|
||||
+12
@@ -18,10 +18,14 @@ package org.jetbrains.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtLambdaExpression
|
||||
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
internal class SoftKeywordsHighlightingVisitor(private val holder: AnnotationHolder) : KtVisitorVoid() {
|
||||
|
||||
@@ -59,4 +63,12 @@ internal class SoftKeywordsHighlightingVisitor(private val holder: AnnotationHol
|
||||
holder.createInfoAnnotation(arrow, null).textAttributes = KotlinHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitArgument(argument: KtValueArgument) {
|
||||
super.visitArgument(argument)
|
||||
|
||||
val argumentName = argument.getArgumentName() ?: return
|
||||
val eq = argument.equalsToken ?: return
|
||||
holder.createInfoAnnotation(TextRange(argumentName.startOffset, eq.endOffset), null).textAttributes = KotlinHighlightingColors.NAMED_ARGUMENT
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -51,7 +51,10 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
highlightVariable(expression, target);
|
||||
if (!(expression.getParent() instanceof KtValueArgumentName)) { // highlighted separately
|
||||
highlightVariable(expression, target);
|
||||
}
|
||||
|
||||
super.visitSimpleNameExpression(expression);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
<option name="FOREGROUND" value="467cda" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_NAMED_ARGUMENT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="467cda" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_DYNAMIC_FUNCTION_CALL">
|
||||
<value>
|
||||
<option name="FONT_TYPE" value="3" />
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
<option name="FOREGROUND" value="4a86e8" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_NAMED_ARGUMENT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="4a86e8" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_DYNAMIC_FUNCTION_CALL">
|
||||
<value>
|
||||
<option name="FONT_TYPE" value="3" />
|
||||
|
||||
@@ -65,7 +65,7 @@ class KotlinColorSettingsPage : ColorSettingsPage {
|
||||
|
||||
fun Int?.bar() {
|
||||
if (this != null) {
|
||||
println(<SMART_CAST_RECEIVER>toString</SMART_CAST_RECEIVER>())
|
||||
println(<NAMED_ARGUMENT>message =</NAMED_ARGUMENT> <SMART_CAST_RECEIVER>toString</SMART_CAST_RECEIVER>())
|
||||
}
|
||||
else {
|
||||
println(<SMART_CONSTANT>this</SMART_CONSTANT>.toString())
|
||||
@@ -157,7 +157,8 @@ var <PACKAGE_PROPERTY><MUTABLE_VARIABLE><PROPERTY_WITH_BACKING_FIELD>globalCount
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast") to KotlinHighlightingColors.SMART_CAST_VALUE,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.smart.constant") to KotlinHighlightingColors.SMART_CONSTANT,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast.receiver") to KotlinHighlightingColors.SMART_CAST_RECEIVER,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.label") to KotlinHighlightingColors.LABEL)
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.label") to KotlinHighlightingColors.LABEL,
|
||||
"Named argument" to KotlinHighlightingColors.NAMED_ARGUMENT)
|
||||
}
|
||||
|
||||
override fun getColorDescriptors(): Array<ColorDescriptor> = ColorDescriptor.EMPTY_ARRAY
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ fun inline() {
|
||||
run ({ x1 })
|
||||
|
||||
val x2 = 1
|
||||
run (f = { x2 })
|
||||
run (<info descr="null">f =</info> { x2 })
|
||||
|
||||
val x3 = 1
|
||||
run {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>(<info textAttributesKey="KOTLIN_PARAMETER">p1</info>: <info textAttributesKey="KOTLIN_CLASS">Int</info>, <info textAttributesKey="KOTLIN_PARAMETER">p2</info>: <info textAttributesKey="KOTLIN_CLASS">String</info>): <info textAttributesKey="KOTLIN_CLASS">String</info> {
|
||||
return <info textAttributesKey="KOTLIN_PARAMETER">p2</info> + <info textAttributesKey="KOTLIN_PARAMETER">p1</info>
|
||||
}
|
||||
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">bar</info>() {
|
||||
<info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL"><info textAttributesKey="KOTLIN_FUNCTION_CALL">foo</info></info>(1, <info textAttributesKey="KOTLIN_NAMED_ARGUMENT">p2 =</info> "")
|
||||
}
|
||||
@@ -83,6 +83,12 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NamedArguments.kt")
|
||||
public void testNamedArguments() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/NamedArguments.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Object.kt")
|
||||
public void testObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/Object.kt");
|
||||
|
||||
Reference in New Issue
Block a user