1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
SPDX-FileCopyrightText: 2007 Piyush verma <piyush.verma@gmail.com>
SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
SPDX-FileCopyrightText: 2011 Sven Brauch <svenbrauch@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "pythonhighlighting.h"
#include <language/duchain/declaration.h>
#include <language/duchain/types/abstracttype.h>
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<Declaration*> 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);
}
}
#include "moc_pythonhighlighting.cpp"
|