mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-28313 Highlighting updated to treat *args/**kwargs as a single item
This commit is contained in:
@@ -19,6 +19,8 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.highlighting.PyHighlighter;
|
||||
@@ -39,10 +41,24 @@ public class HighlightingAnnotator extends PyAnnotator {
|
||||
final PyFunction function = PsiTreeUtil.getParentOfType(node, PyFunction.class);
|
||||
if (function != null) {
|
||||
final TextAttributesKey attrKey = node.isSelf() ? PyHighlighter.PY_SELF_PARAMETER : PyHighlighter.PY_PARAMETER;
|
||||
addHighlightingAnnotation(node.getFirstChild(), attrKey);
|
||||
if (isArgOrKwargParameter(node)) {
|
||||
addHighlightingAnnotation(node, attrKey);
|
||||
}
|
||||
else {
|
||||
addHighlightingAnnotation(node.getFirstChild(), attrKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isArgOrKwargParameter(PyParameter parameter) {
|
||||
if (parameter instanceof PyNamedParameter) {
|
||||
final PyNamedParameter namedParameter = (PyNamedParameter)parameter;
|
||||
return namedParameter.isPositionalContainer() ||
|
||||
namedParameter.isKeywordContainer();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyReferenceExpression(PyReferenceExpression node) {
|
||||
final String referencedName = node.getReferencedName();
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def <info descr="PY.FUNC_DEFINITION">f</info>(<info descr="PY.PARAMETER">**kwargs</info>):
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
def <info descr="PY.FUNC_DEFINITION">f</info>(<info descr="PY.PARAMETER">*args</info>):
|
||||
pass
|
||||
@@ -396,6 +396,16 @@ public class PythonHighlightingTest extends PyTestCase {
|
||||
doTest(LanguageLevel.PYTHON37, false, true);
|
||||
}
|
||||
|
||||
// PY-28313
|
||||
public void testVarargs() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-28313
|
||||
public void testKwargs() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static EditorColorsScheme createTemporaryColorScheme() {
|
||||
EditorColorsManager manager = EditorColorsManager.getInstance();
|
||||
|
||||
Reference in New Issue
Block a user