Refine highlighting of '@'
- Do not highlight '@' as separate token. - Highlight '@' the same way as element where it's located: annotation, label or modifier. - Extend text range when positioning unresolved reference in annotation with '@'. Note that currently '@' is collapsed with modifiers tokens
This commit is contained in:
@@ -52,7 +52,6 @@ public class JetHighlighter extends SyntaxHighlighterBase {
|
||||
fillMap(keys1, JetTokens.KEYWORDS, JetHighlightingColors.KEYWORD);
|
||||
|
||||
keys1.put(JetTokens.AS_SAFE, JetHighlightingColors.KEYWORD);
|
||||
keys1.put(JetTokens.AT, JetHighlightingColors.LABEL);
|
||||
keys1.put(JetTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER);
|
||||
keys1.put(JetTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.MultiRangeReference
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
@@ -236,6 +237,12 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
|
||||
}
|
||||
}
|
||||
|
||||
platformStatic fun highlightName(holder: AnnotationHolder, textRange: TextRange, attributesKey: TextAttributesKey) {
|
||||
if (namesHighlightingEnabled) {
|
||||
holder.createInfoAnnotation(textRange, null).setTextAttributes(attributesKey)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBeforeAnalysisVisitors(holder: AnnotationHolder) = array(
|
||||
SoftKeywordsHighlightingVisitor(holder),
|
||||
LabelsHighlightingVisitor(holder),
|
||||
|
||||
+14
-1
@@ -18,11 +18,13 @@ package org.jetbrains.kotlin.idea.highlighter;
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
|
||||
class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
@@ -41,7 +43,13 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
if (referenceTarget instanceof ClassDescriptor) {
|
||||
highlightName(expression, textAttributesKeyForClass((ClassDescriptor) referenceTarget));
|
||||
TextAttributesKey textAttributesKey = textAttributesKeyForClass((ClassDescriptor) referenceTarget);
|
||||
if (textAttributesKey == JetHighlightingColors.ANNOTATION) {
|
||||
highlightAnnotation(expression);
|
||||
}
|
||||
else {
|
||||
highlightName(expression, textAttributesKey);
|
||||
}
|
||||
}
|
||||
else if (referenceTarget instanceof TypeParameterDescriptor) {
|
||||
highlightName(expression, JetHighlightingColors.TYPE_PARAMETER);
|
||||
@@ -49,6 +57,11 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void highlightAnnotation(@NotNull JetSimpleNameExpression expression) {
|
||||
TextRange toHighlight = PsiUtilPackage.getCalleeHighlightingRange(expression);
|
||||
JetPsiChecker.highlightName(holder, toHighlight, JetHighlightingColors.ANNOTATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitObjectDeclarationName(@NotNull JetObjectDeclarationName declaration) {
|
||||
PsiElement nameIdentifier = declaration.getNameIdentifier();
|
||||
|
||||
Reference in New Issue
Block a user