mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-11418 Add a setting in syntax highlighting for qualified calls
So far they're called "function calls" and "method calls" respectively, though strictly speaking, these are rather "unqualified calls" and "qualified calls" because we don't distinguish between function and constructor calls, as well as method and qualified function calls to avoid costs of proper resolving in the highlighting pass.
This commit is contained in:
@@ -110,6 +110,7 @@ public class PyHighlighter extends SyntaxHighlighterBase {
|
||||
public static final TextAttributesKey PY_KEYWORD_ARGUMENT = TextAttributesKey.createTextAttributesKey("PY.KEYWORD_ARGUMENT", PARAMETER);
|
||||
|
||||
public static final TextAttributesKey PY_FUNCTION_CALL = TextAttributesKey.createTextAttributesKey("PY.FUNCTION_CALL", FUNCTION_CALL);
|
||||
public static final TextAttributesKey PY_METHOD_CALL = TextAttributesKey.createTextAttributesKey("PY.METHOD_CALL", PY_FUNCTION_CALL);
|
||||
|
||||
public static final TextAttributesKey PY_VALID_STRING_ESCAPE = TextAttributesKey.createTextAttributesKey("PY.VALID_STRING_ESCAPE", VALID_STRING_ESCAPE);
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public class PythonColorsPage implements ColorSettingsPage, InspectionColorSetti
|
||||
new AttributesDescriptor("'self' parameter", PyHighlighter.PY_SELF_PARAMETER),
|
||||
new AttributesDescriptor("Keyword argument", PyHighlighter.PY_KEYWORD_ARGUMENT),
|
||||
new AttributesDescriptor("Function call", PyHighlighter.PY_FUNCTION_CALL),
|
||||
new AttributesDescriptor("Method call", PyHighlighter.PY_METHOD_CALL),
|
||||
new AttributesDescriptor("Valid escape sequence", PyHighlighter.PY_VALID_STRING_ESCAPE),
|
||||
new AttributesDescriptor("Invalid escape sequence", PyHighlighter.PY_INVALID_STRING_ESCAPE),
|
||||
};
|
||||
@@ -78,6 +79,7 @@ public class PythonColorsPage implements ColorSettingsPage, InspectionColorSetti
|
||||
.put("param", PyHighlighter.PY_PARAMETER)
|
||||
.put("kwarg", PyHighlighter.PY_KEYWORD_ARGUMENT)
|
||||
.put("call", PyHighlighter.PY_FUNCTION_CALL)
|
||||
.put("mcall", PyHighlighter.PY_METHOD_CALL)
|
||||
.build();
|
||||
|
||||
@NotNull
|
||||
@@ -114,13 +116,13 @@ public class PythonColorsPage implements ColorSettingsPage, InspectionColorSetti
|
||||
" <docComment>\"\"\" Syntax Highlighting Demo\n" +
|
||||
" <docCommentTag>@param</docCommentTag> x Parameter\"\"\"</docComment>\n" +
|
||||
" s = (\"Test\", 2+3, {'a': 'b'}, <param>x</param>) # Comment\n" +
|
||||
" print s[0].<call>lower()</call>\n"+
|
||||
" print s[0].<mcall>lower()</mcall>\n"+
|
||||
"\n"+
|
||||
"class <classDef>Foo</classDef>:\n"+
|
||||
" def <predefined>__init__</predefined>(<self>self</self>):\n" +
|
||||
" byte_string = 'newline:\\n also newline:\\x0a'\n" +
|
||||
" text_string = u\"Cyrillic \u042f is \\u042f. Oops: \\u042g\"\n"+
|
||||
" <self>self</self>.<call>makeSense</call>(<kwarg>whatever</kwarg>=1)\n" +
|
||||
" <self>self</self>.<mcall>makeSense</mcall>(<kwarg>whatever</kwarg>=1)\n" +
|
||||
" \n" +
|
||||
" def <funcDef>makeSense</funcDef>(<self>self</self>, <param>whatever</param>):\n"+
|
||||
" <self>self</self>.sense = <param>whatever</param>\n"+
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.jetbrains.python.validation;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.highlighting.PyHighlighter;
|
||||
@@ -68,8 +70,10 @@ public class HighlightingAnnotator extends PyAnnotator {
|
||||
if (callee != null) {
|
||||
final ASTNode functionName = callee.getNameElement();
|
||||
if (functionName != null) {
|
||||
final Annotation annotation = getHolder().createInfoAnnotation(functionName, null);
|
||||
annotation.setTextAttributes(PyHighlighter.PY_FUNCTION_CALL);
|
||||
final TextAttributesKey attrKey = callee.isQualified() ? PyHighlighter.PY_METHOD_CALL : PyHighlighter.PY_FUNCTION_CALL;
|
||||
final String message = ApplicationManager.getApplication().isUnitTestMode() ? attrKey.getExternalName() : null;
|
||||
final Annotation annotation = getHolder().createInfoAnnotation(functionName, message);
|
||||
annotation.setTextAttributes(attrKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<info descr="null">func</info>()
|
||||
mod.Class.<info descr="null">method</info>()
|
||||
<info descr="null">chained</info>().<info descr="null">calls</info>()
|
||||
<info descr="PY.FUNCTION_CALL">func</info>()
|
||||
mod.Class.<info descr="PY.METHOD_CALL">method</info>()
|
||||
<info descr="PY.FUNCTION_CALL">chained</info>().<info descr="PY.METHOD_CALL">calls</info>().<info descr="PY.METHOD_CALL">sample</info>()
|
||||
(foo or bar)()
|
||||
<info descr="null"><info descr="null">len</info></info>(xs)
|
||||
<info descr="null"><info descr="PY.FUNCTION_CALL">len</info></info>(xs)
|
||||
@@ -367,8 +367,10 @@ public class PythonHighlightingTest extends PyTestCase {
|
||||
// PY-11418
|
||||
public void testFunctionCalls() {
|
||||
final EditorColorsScheme scheme = createTemporaryColorScheme();
|
||||
final TextAttributesKey callKey = TextAttributesKey.find("PY.FUNCTION_CALL");
|
||||
scheme.setAttributes(callKey, new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD));
|
||||
final TextAttributesKey funcCallKey = TextAttributesKey.find("PY.FUNCTION_CALL");
|
||||
scheme.setAttributes(funcCallKey, new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD));
|
||||
final TextAttributesKey methodCallKey = TextAttributesKey.find("PY.METHOD_CALL");
|
||||
scheme.setAttributes(methodCallKey, new TextAttributes(Color.red, Color.black, Color.white, EffectType.BOXED, Font.BOLD));
|
||||
final TextAttributesKey builtinKey = TextAttributesKey.find("PY.BUILTIN_NAME");
|
||||
scheme.setAttributes(builtinKey, new TextAttributes(Color.blue, Color.black, Color.white, EffectType.BOXED, Font.BOLD));
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user