GSoC 2015: Final status report

Hi, here is the final GSoC 2015 status report for the “Further Clang integration in KDevelop” project.

1) Fixed highlighting of type aliases:

1 type_alias
2) Added macros highlighting:

2 macros
3) Enabled rainbow highlighting (also added more colors for highlighting):

3 highlighting

4) Added members from base classes to code completion:

6 code-completion

5) Added protected members into code-completion:

13 protected members

6) Fixed code-completion items priority. Now we have items with the highest priority at the top of code-completion list.

9 completion priority

7) Cleaned up the best matches completion group. Now it contains only the items with the exact type match.

8) Added support for the goto statement:

7 goto

9) Properly parse functions with calling conventions specified:

4 calling convention

10) Tried to handle Clang’s ElaboratedType. This only works in simplest cases. To make it work properly LibClang must be fixed. See also my patch to LibClang: [libclang] Expose the ElaboratedType

5 elaborated type

11) Improved variadic functions support:

8 variadic
12) Now we extract TODO’s for imports too
13) Added clang setting pages (one page for per-project settings – parser command line arguments, another one for per-session settings:

12.1 project settings12.2 session settings

14) Added look-ahead matching code completion (thought it’s far from being perfect, in most cases it works reasonably well).

14 look ahead 114 look ahead 2

15) Fixed class template specialization type.

15 class_tempalte_specialization
16) Automatically change member access operator. (currently it only replaces ‘->’ to ‘.’)
17) Fixed auto types deduction. This still awaits a review though: [libclang] Return deduced type for auto type, not the one written in the source.

auto 1auto 2

There are actually much more improvements on the kdev-clang side that I forgot to mention here, see for yourself:


GSoC15: Further Clang integration in KDevelop


This year I’ve been accepted as a GSoC student to work on the “Further Clang integration in KDevelop” project for KDE.
Here is what I’m planning to do (copy-pasted from my proposal):

Abstract: Finish (well, at least fix as many bugs and implement as many missing features, as possible) the kdev-clang plugin to make it an usable replacement for the existing C++ plugin.

Motivation for Proposal / Goal:
The last year tremendous amount of work was done to integrate Clang in KDevelop:

Still, even nowadays the kdev-clang has a lot of bugs/missing features (especially in code-completion area), that prevent it from becoming a viable replacement to the oldcpp. So, I’ll try to improve the current situation.


Implementation Details:
Here is the list of features that currently missing/not working properly.

1. Code highlighting:

  •  typedef’s not highlighted
  •  Macros not highlighted
  •  Rainbow colors not used for local variables, but used for function arguments only

2. Code-completion:

  • Currently code-completion is very slow (at least when invoked in local/global scope), sometimes it takes about 2-3 seconds for completion widget to show up. I’ve investigated it a bit, turns out it’s a problem in the kdev-clang not in Clang itself. findDeclarations(…) is the culprit here, because we call too it often. So it should be optimized somehow.
  • Add argument-hint completion items
    E.g. “function1(function2(”
    When completion invoked at the end of the expression, all functions named function2 should be shown as argument-hints.
  • Fix completion of parent class variables.
  • Add “Enum values” completion group to offer enum values as completion items when a function takes an argument of an enum type.
  • Don’t offer unrelated completion results.
    E.g.: class Abc; int f(Abc); Ab|
    When completion invoked at |, Abc and f(Abc) offered as completion items, instead of just  Abc.
  • Currently “Detailed completion” option doesn’t work. We always show the detailed completion.
  • Add/port lookahead completion.
  • Improve priority of completion items.
    E.g. : class A;class B; void f(A); A c; B b; f(|
    when completion invoked at |, “b” is at the top of the completion list which is completely wrong, it should be “a” instead
  • Fix in-class completion of class variables/functions, e.g.:
    class Class{
    //Here m_var is not shown as completion item.
    int m_var;};
  • Request code-completion on document opening.
    Clang caches code-completion results, so the first call can be very slow (1-5 seconds), but consequent ones are pretty fast. So we should invoke code-completion on document opening to pre-cache completion results.
  • Replace . to -> when needed and vice-versa (This is probably difficult as at code-completion time the document isn’t reparsed yet and even if it’s Clang provides cursors like CXCursor_FirstInvalid, so in most cases we can’t use the clang API to determine whether replacement is needed or not – as it won’t provide any information on just inputed text and we have to manually parse the code).
  • Other:
    place a semicolon when calling a function which returns void.
    put :: after completing a namespace item
    don’t insert parentheses if the parentheses are already there

3. (TU)DUChain:

  • Currently we highlight variables within macro definitions at macro expansion locations. This is wrong, as those variables not visible at that point. So we need to set null ranges for it, but we have to make sure that their uses still can be found. (I’m not sure yet how to achieve it, as clang provides the same range for all declarations inside macro definition.)
  • Macro definition widget shows an empty macro body after restoring from item repository.
  • Some functions have an “invalid type” in a context browser popup.
  • We shouldn’t create declarations for anonymous parameters (or at least there should be null ranges for it). E.g.: int f(bool); currently highlights “)” as function parameter.
  • Improve variadic functions support. (show ellipsis as the last function parameter in the navigation widget)
  • Uses of operator[] have invalid ranges.
  • Fix uses of “operator bool()” (smart pointers)

4. Various bug fixes/features:

  • Fix “implement function” helper that offers to implement functions from system headers.
  • Fix “Override Function” helper that offers to implement a function even though it’s already implemented.
  • Fix include path completion, currently it’s unbearably slow, as clang reparses the document without using PCH internally when editing file’s preamble.
  • Some problems have no ranges (invalid ranges) associated with them.

5. Clang settings page

  • I’ve recently added an ability to configure language standard. I think (and that was also mentioned in the review) that we should have a separate settings page for that, where one could select language standard, configure what flags/options he needs to pass to the Clang parser and another options like: whether “Implement assistant” should be enabled or whether to show macros in code-completion, e.t.c.


Tentative Timeline:

It’s worth mentioning that during May-June I won’t be having much free time, so during that period I’m planning to work on not very time-consuming features.

May 1 – May 6

  • typedef’s not highlighted – 1 day
  • Macros not highlighted – 3 days
  • Rainbow colors not used for local variables, but used for function arguments only – 1 day

May 7 – May 16

  • Improve code-completion responsiveness – 2 days
  • Fix functions with “invalid type” – 2 days
  • Don’t highlight variables within macro definitions at macro expansion locations – 5 days

May 17 – May 23

  • Fix uses of “operator bool()” (Smart pointers) – 5 days
  • Fix definition widget – 1 day

May 24 – June 1

  • Fix completion of parent class variables – 1 day
  • Fix “implement function” helper – 1 day
  • Improve priority of completion items – 1 day
  • Don’t offer unrelated completion results – 2 days
  • Don’t create declarations for anonymous parameters – 1 day
  • Improve variadic functions support – 1 day

June 2 – June 9

  • Fix “Detailed completion” option – 1 day
  • Fix in-class completion of class variables/functions – 1 day
  • Fix “Override Function” helper  – 2 days
  • Fix invalid ranges for some problems – 1 day
  • Fix ranges of operator[] – 1 day

June 10 – June 18

  • Request code-completion on document opening – 2 days
  • Fix include path completion – 3 days
  • Other – 2 days

June 19 – June  26

  • Add Clang settings page: 1 week

June 27 – July 10

  • replace . to -> when needed and vice-versa – 1-2 week

July 11 – July 27

  • Add argument-hint completion items – 2-3 weeks

July 28 – August 15

  • Add/port lookahead completion – 2-3 weeks


If I finish all tasks ahead of the schedule the remaining time can be spend on fixing another not mentioned above bugs.