PY-20401 Rehighlight None, True and False to keep their color inside annotations

Otherwise, they have the same color as enclosing annotation that is
different from the way we treat builtin symbols like 'str' and 'int'
there.
This commit is contained in:
Mikhail Golubev
2017-10-09 14:56:50 +03:00
parent 05b24abf3c
commit f6fe43223b
3 changed files with 14 additions and 1 deletions
@@ -169,6 +169,7 @@ public class PyTokenTypes {
public static final TokenSet NUMERIC_LITERALS = TokenSet.create(FLOAT_LITERAL, INTEGER_LITERAL, IMAGINARY_LITERAL);
public static final TokenSet BOOL_LITERALS = TokenSet.create(TRUE_KEYWORD, FALSE_KEYWORD);
public static final TokenSet SCALAR_LITERALS = TokenSet.orSet(BOOL_LITERALS, NUMERIC_LITERALS, TokenSet.create(NONE_KEYWORD));
public static final TokenSet EXPRESSION_KEYWORDS = TokenSet.create(TRUE_KEYWORD, FALSE_KEYWORD, NONE_KEYWORD);
public static final TokenSet AUG_ASSIGN_OPERATIONS = TokenSet.create(PLUSEQ, MINUSEQ, MULTEQ, ATEQ, DIVEQ,
PERCEQ, EXPEQ, GTGTEQ, LTLTEQ, ANDEQ, OREQ, XOREQ, FLOORDIVEQ);
@@ -17,7 +17,9 @@ package com.jetbrains.python.validation;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.highlighting.PyHighlighter;
import com.jetbrains.python.psi.*;
@@ -78,4 +80,14 @@ public class HighlightingAnnotator extends PyAnnotator {
addHighlightingAnnotation(value, PyHighlighter.PY_ANNOTATION);
}
}
@Override
public void visitElement(PsiElement element) {
// Highlight None, True and False as keywords once again inside annotations after PyHighlighter
// to keep their original color
if (PyTokenTypes.EXPRESSION_KEYWORDS.contains(element.getNode().getElementType()) &&
PsiTreeUtil.getParentOfType(element, PyAnnotation.class) != null) {
addHighlightingAnnotation(element, PyHighlighter.PY_KEYWORD);
}
}
}
+1 -1
View File
@@ -2,5 +2,5 @@ TOP_LEVEL: <info descr="PY.ANNOTATION"><info descr="PY.BUILTIN_NAME">str</info><
class <info descr="PY.CLASS_DEFINITION">C</info>:
attr: <info descr="PY.ANNOTATION">Optional[Any]</info> = None
def <info descr="PY.FUNC_DEFINITION">method</info>(<info descr="PY.SELF_PARAMETER">self</info>, <info descr="PY.PARAMETER">xs</info>: <info descr="PY.ANNOTATION">List[<info descr="PY.BUILTIN_NAME">int</info>]</info>) -> <info descr="PY.ANNOTATION">None</info>:
def <info descr="PY.FUNC_DEFINITION">method</info>(<info descr="PY.SELF_PARAMETER">self</info>, <info descr="PY.PARAMETER">xs</info>: <info descr="PY.ANNOTATION">List[<info descr="PY.BUILTIN_NAME">int</info>]</info>) -> <info descr="PY.ANNOTATION"><info descr="PY.KEYWORD">None</info></info>:
pass