From b1bd6df96a59b6c174f9d49edb8469b414bccff2 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Mon, 16 Oct 2017 19:04:50 +0300 Subject: [PATCH] Don't apply rainbow highlighting to stars in `*args` and `**kwargs` It leads to highlighting conflicts, try next commit without these changes. --- .../python/highlighting/PyRainbowVisitor.kt | 16 ++-------------- .../python/PyRainbowHighlightingTest.java | 18 ++---------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt b/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt index c5d56e419d10..59aba8b50a3e 100644 --- a/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt +++ b/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt @@ -52,10 +52,9 @@ class PyRainbowVisitor : RainbowVisitor() { private fun processNamedParameter(namedParameter: PyNamedParameter) { val context = getNamedParameterContext(namedParameter) ?: return val name = namedParameter.name ?: return + val element = namedParameter.nameIdentifier ?: return - getHighlightedParameterElements(namedParameter).forEach { - addInfo(context, it, name, PyHighlighter.PY_PARAMETER) - } + addInfo(context, element, name, PyHighlighter.PY_PARAMETER) } private fun getReferenceContext(referenceExpression: PyReferenceExpression, @@ -112,17 +111,6 @@ class PyRainbowVisitor : RainbowVisitor() { private fun updateNameIfGlobal(context: PsiElement, name: String?) = if (context is PyFile && name != null) "global_$name" else name - private fun getHighlightedParameterElements(namedParameter: PyNamedParameter): List { - val nameIdentifier = namedParameter.nameIdentifier - - return if (namedParameter.isPositionalContainer || namedParameter.isKeywordContainer) { - listOfNotNull(namedParameter.firstChild, nameIdentifier) - } - else { - listOfNotNull(nameIdentifier) - } - } - private fun addInfo(context: PsiElement, rainbowElement: PsiElement, name: String, key: TextAttributesKey? = DEFAULT_HIGHLIGHTING_KEY) { addInfo(getInfo(context, rainbowElement, name, key)) } diff --git a/python/testSrc/com/jetbrains/python/PyRainbowHighlightingTest.java b/python/testSrc/com/jetbrains/python/PyRainbowHighlightingTest.java index e67e051a61a2..0ce9cfeba3a2 100644 --- a/python/testSrc/com/jetbrains/python/PyRainbowHighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/PyRainbowHighlightingTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python; import com.jetbrains.python.fixtures.PyTestCase; @@ -37,7 +23,7 @@ public class PyRainbowHighlightingTest extends PyTestCase { } public void testPositionalAndKeywordParameters() { - doTest("def foo(*args, **kwargs):\n" + + doTest("def foo(*args, **kwargs):\n" + " print args\n" + " print kwargs\n"); }