PY-11418 Don't highlight builtin function calls as calls additionally

This commit is contained in:
Mikhail Golubev
2017-10-09 14:56:50 +03:00
parent f6fe43223b
commit 47144c3dfe
5 changed files with 9 additions and 5 deletions
@@ -118,7 +118,7 @@ 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].<mcall>lower()</mcall>\n"+
" <call>f</call>(s[0].<mcall>lower()</mcall>)\n"+
"\n"+
"class <classDef>Foo</classDef>:\n"+
" tags: <annotation>List[<builtin>str</builtin>]</annotation>\n" +
@@ -130,7 +130,7 @@ public class PythonColorsPage implements ColorSettingsPage, InspectionColorSetti
" def <funcDef>makeSense</funcDef>(<self>self</self>, <param>whatever</param>):\n"+
" <self>self</self>.sense = <param>whatever</param>\n"+
"\n"+
"x = <builtin><call>len</call></builtin>('abc')\n"+
"x = <builtin>len</builtin>('abc')\n"+
"print(f.<predefinedUsage>__doc__</predefinedUsage>)"
;
}
@@ -22,6 +22,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.highlighting.PyHighlighter;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.PyBuiltinCache;
import static com.jetbrains.python.psi.PyUtil.as;
@@ -65,6 +66,9 @@ public class HighlightingAnnotator extends PyAnnotator {
public void visitPyCallExpression(PyCallExpression node) {
final PyReferenceExpression callee = as(node.getCallee(), PyReferenceExpression.class);
if (callee != null) {
if (!callee.isQualified() && PyBuiltinCache.isInBuiltins(callee)) {
return;
}
final ASTNode functionName = callee.getNameElement();
if (functionName != null) {
final TextAttributesKey attrKey = callee.isQualified() ? PyHighlighter.PY_METHOD_CALL : PyHighlighter.PY_FUNCTION_CALL;
+1 -1
View File
@@ -5,7 +5,7 @@
# predefined decl: green bold
# predefined usage: yellow bold
<info descr="PY.BUILTIN_NAME" type="INFORMATION" foreground="0x00ff00" background="0x000000" effectcolor="0xffffff" effecttype="BOXED" fonttype="1"><info descr="PY.FUNCTION_CALL">len</info></info>("")
<info descr="PY.BUILTIN_NAME" type="INFORMATION" foreground="0x00ff00" background="0x000000" effectcolor="0xffffff" effecttype="BOXED" fonttype="1">len</info>("")
len = [] # redefine
len # no highlight
@@ -2,4 +2,4 @@
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="PY.BUILTIN_NAME"><info descr="PY.FUNCTION_CALL">len</info></info>(xs)
<info descr="PY.BUILTIN_NAME">len</info>(xs)
@@ -1,2 +1,2 @@
def <info descr="PY.FUNC_DEFINITION">f</info>(<info descr="PY.PARAMETER">p1</info>: <info descr="PY.ANNOTATION"><info descr="PY.BUILTIN_NAME">int</info></info>, <info descr="PY.PARAMETER">p2</info>: <info descr="PY.ANNOTATION"><info descr="PY.BUILTIN_NAME">int</info></info> = 42):
<info descr="PY.BUILTIN_NAME"><info descr="PY.FUNCTION_CALL">print</info></info>(<info descr="PY.PARAMETER">p1</info>, <info descr="PY.PARAMETER">p2</info>)
<info descr="PY.BUILTIN_NAME">print</info>(<info descr="PY.PARAMETER">p1</info>, <info descr="PY.PARAMETER">p2</info>)