Don't apply rainbow highlighting to stars in *args and **kwargs

It leads to highlighting conflicts, try next commit without these changes.
This commit is contained in:
Semyon Proshev
2017-11-20 17:11:05 +03:00
parent 27a94c6055
commit b1bd6df96a
2 changed files with 4 additions and 30 deletions
@@ -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<PsiElement> {
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))
}
@@ -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(<rainbow color='ff000003'>*</rainbow><rainbow color='ff000003'>args</rainbow>, <rainbow color='ff000004'>**</rainbow><rainbow color='ff000004'>kwargs</rainbow>):\n" +
doTest("def foo(*<rainbow color='ff000003'>args</rainbow>, **<rainbow color='ff000004'>kwargs</rainbow>):\n" +
" print <rainbow color='ff000003'>args</rainbow>\n" +
" print <rainbow color='ff000004'>kwargs</rainbow>\n");
}