KT-11612 Highlight named arguments in the editor somehow

#KT-11612 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-03-28 14:51:48 +03:00
parent b9865c7225
commit 93e170325e
9 changed files with 44 additions and 4 deletions
@@ -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() {
}
@@ -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
}
}
@@ -51,7 +51,10 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
}
}
highlightVariable(expression, target);
if (!(expression.getParent() instanceof KtValueArgumentName)) { // highlighted separately
highlightVariable(expression, target);
}
super.visitSimpleNameExpression(expression);
}