Bug 325092 - JJ: Use rainbow-coloring for top-level variables in some cases
Summary: JJ: Use rainbow-coloring for top-level variables in some cases
Status: RESOLVED FIXED
Alias: None
Product: kdev-python
Classification: Developer tools
Component: Language support (show other bugs)
Version: git master
Platform: unspecified Linux
: NOR normal
Target Milestone: 1.6.0
Assignee: Sven Brauch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-19 13:37 UTC by Sven Brauch
Modified: 2013-11-26 16:33 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Brauch 2013-09-19 13:37:23 UTC
Currently all variables in the top-level 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 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) have "isFunctionDeclaration()" set as false.
Otherwise, just return the default.

Since this function will be called quite often, the result of b) should be cached in a class member.

Reproducible: Always
Comment 1 Sven Brauch 2013-09-19 13:38:21 UTC
Correction: instead of looking at isFunctionDeclaration(), it'd be better to look if the declarations' internalContext() is 0 or not, since that'll also catch class declarations.
Comment 2 Sven Brauch 2013-11-26 16:33:27 UTC
Git commit 6cc8c6bdfd3692f05d0fa0c4808efdda7efc53a9 by Sven Brauch, on behalf of Benjamin Kaiser.
Committed on 26/11/2013 at 16:31.
Pushed by brauch into branch 'master'.

Rainbow color-highlighting for top-level variables

Enable rainbow-color highlighting for top-level variables if there are
no class or function declarations.
Currently it's also disabled if there are imports, although more by
accident than intentionally.
REVIEW:114138
GCI-TASK:5846685427171328

M  +23   -1    pythonhighlighting.cpp
M  +4    -0    pythonhighlighting.h

http://commits.kde.org/kdev-python/6cc8c6bdfd3692f05d0fa0c4808efdda7efc53a9