diff --git a/pythonhighlighting.cpp b/pythonhighlighting.cpp index 970e59cd..3ccb33e3 100644 --- a/pythonhighlighting.cpp +++ b/pythonhighlighting.cpp @@ -1,79 +1,83 @@ /***************************************************************************** * Copyright (c) 2007 Piyush verma * * Copyright (c) 2007 Andreas Pakulat * * Copyright (c) 2011 Sven Brauch * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************** */ #include "pythonhighlighting.h" #include #include #include using namespace KDevelop; namespace Python { Highlighting::Highlighting( QObject * parent ) : KDevelop::CodeHighlighting(parent) { } void CodeHighlightingInstance::highlightUse(KDevelop::DUContext* context, int index, const QColor& color) { KDevelop::CodeHighlightingInstance::highlightUse(context, index, color); } CodeHighlightingInstance::CodeHighlightingInstance(const Highlighting* highlighting) : KDevelop::CodeHighlightingInstance(highlighting), checked_blocks(false), has_blocks(false) { } bool CodeHighlightingInstance::useRainbowColor(KDevelop::Declaration* dec) const { + if (dec->context()->type() == DUContext::Other) { + // Normal non-toplevel variable, comprehension variable or lambda parameter. + return true; + } if ( ! checked_blocks ) { checkHasBlocks(dec->topContext()); } // no functions/classes in file and it's a normal variable and in the top level if ( ! has_blocks && ! dec->internalContext() && dec->context() == dec->topContext() ) { return true; } return KDevelop::CodeHighlightingInstance::useRainbowColor(dec); } void CodeHighlightingInstance::checkHasBlocks(TopDUContext* top) const { QVector declarations = top->localDeclarations(); for ( int i = 0; i < declarations.size(); i++ ) { if ( declarations.at(i)->internalContext() ) { has_blocks = true; break; } } checked_blocks = true; } CodeHighlightingInstance* Highlighting::createInstance() const { return new CodeHighlightingInstance(this); } }