GSoC/GCI Archive
Google Code-in 2013 KDE

KDevelop: Python support: rainbow color highlighting for top-level variables

completed by: Benjamin Kaiser

mentors: Sven Brauch

The task is described in this bug report: https://bugs.kde.org/show_bug.cgi?id=325092

Below is a copy of its description.

 

Currently all variables in the top-level context are boring green. That's fine for larger files but if you just type a short script, you'd rather have them highlighted. A nice way to solve this would be to always use rainbow colors if there are no functions or classes defined in the file, and the default otherwise. To achieve this, you'd want to look at pythonhighlighting.cpp:useRainbowColor, and return true from that function if the declaration's context() is a) the same as declaration's topContext(), so the declaration is a top-level declaration, and b) all declarations in the declaration's topContext() (use searchInParents=false for the allDeclarations() method call) do not have an internal context (use ->internalContext()). Otherwise, just return the default. Since this function will be called quite often, the result of b) should be cached in a class member.