Code completion problem in header files

Maciej Cencora m.cencora at gmail.com
Tue Jan 29 15:32:39 UTC 2013


Hi Milian,

thanks for fixing the completion for namespaces, but that's not specifically 
what my patch is about.
The completion is broken for everything not just namespaces, and only in 
header files.
Try this piece of code:
struct CCC
{
    static const unsigned int someConst = 124;
    static const unsigned int otherConst = 125;
};

namespace NNN
{
int fun();
int fun2();
}

class DDD
{
    DDD()
    {
        NNN::fun();
        CCC::someConst;
    }
};

If you manually trigger completion after NNN:: or CCC:: it will correctly 
suggest fun(), fun2() and someConst,otherConst accordingly.
But if you enclose the code above with header guards, none of the above 
suggestions will be given.

Regards,
Maciej

Dnia wtorek 29 stycznia 2013 01:14:30 Milian Wolff pisze:
> On Sunday 27 January 2013 12:46:20 Maciej Cencora wrote:
> > Hi,
> > 
> > code completion in header files is somewhat broken.
> > For file header.hpp like this:
> > #ifndef HEADER_HPP
> > #define HEADER_HPP
> > 
> > #include <vector>
> > namespace a{{invoke manual code completion here}}
> > {
> > }
> > 
> > #endif
> > 
> > code completion suggests everything that was declared in included vector
> > file. That's not really what we want (and that's not what is suggested
> > when
> > in cpp file - i.e. no header guards).
> 
> I've fixed that now by only showing namespaces in such cases.
> 
> > The problem seems to be in Cpp::preprocess which imports all macros
> > defined
> > in the passed file. Since in this case the file is header.hpp, parsing its
> > text with the macros defined in it (esp. header guard) results in empty
> > string. CodeCompletion will not be able to find the context code lines and
> > it will report unuseful data.
> 
> To me it more looks like the issue was no existing code to handle this
> special case? See patch 12686bac5382838dfd0ddeb96b26952a83271798 to see how
> I did it.
> > Attached patch fixes the problem, but I'm not sure that this is the right
> > approach since the Cpp::preprocess function is used also in other places
> > besides CodeCompletionContext::preprocess.
> > 
> > Could someone more familiar with cpp plugin take a look at this?
> 
> In the future please report bugs on bugs.kde.org and put patches up for
> review on reviewboard.kde.org.
> 
> Thanks


More information about the KDevelop-devel mailing list