PY-71549 Move None, True and False rehighlighting from PyHighlightingAnnotatorVisitor to PyKeywordHighlightingAnnotator

GitOrigin-RevId: 4ca534b964d02236ad688fd8446cd963d647e350
This commit is contained in:
Petr
2025-07-15 11:17:13 +00:00
committed by intellij-monorepo-bot
parent 3e1cf2afd5
commit efc364c13f
2 changed files with 11 additions and 10 deletions
@@ -21,6 +21,7 @@ import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.PySyntaxCoreBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonLanguage;
@@ -108,6 +109,16 @@ public final class PyKeywordHighlightingAnnotator extends PyAnnotatorBase implem
highlightKeyword(node, PyTokenTypes.TYPE_KEYWORD);
}
@Override
public void visitElement(@NotNull 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, PyAstAnnotation.class) != null) {
myHolder.addHighlightingAnnotation(element, PyHighlighter.PY_KEYWORD);
}
}
private void highlightKeyword(@NotNull PsiElement node, @NotNull PyElementType elementType) {
highlightAsKeyword(node.getNode().findChildByType(elementType));
}