Author Topic: [Code completion] Add include file automatically  (Read 7603 times)

Offline Alexis

  • Multiple posting newcomer
  • *
  • Posts: 62
[Code completion] Add include file automatically
« on: June 13, 2008, 12:24:21 pm »
There is nice feature under Eclipse (for Java) : when you insert a new class instance in your code, the package it belongs to is automatically inserted on top of the source file.

It would be nice to add such a feature in C::B. It's a pain in the neck to every time look for the include file of the class you're introducing in your code. It could be implemented this way: when a token is selected, the code completion plug-in tests whether it is a known class, then looks up the corresponding include file. If there is a match, an option is added in contextual menu: "Insert include file".

Is there any plan for this feature ? Does it require an important redesign in plug-in's code ?

Thanks

or1on

  • Guest
Re: [Code completion] Add include file automatically
« Reply #1 on: August 28, 2008, 09:58:06 pm »
Is there any developer or the like who could answer this question please? I'd like to know this too!

Thx
or1on

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: [Code completion] Add include file automatically
« Reply #2 on: August 29, 2008, 12:10:20 am »
when a token is selected, the code completion plug-in tests whether it is a known class, then looks up the corresponding include file. If there is a match, an option is added in contextual menu: "Insert include file".

What do you mean when you say "selected"?  Highlighted?  Right-clicked?  Initially typed?

It sounds like a nice idea, but I can think of many reasons why this would be much more problematic in C++ than it would be in Java.


Everybody knows that the DrewBooWidget library requires you to #include<DrewBooWidgets.h> to use any of it.

Simple!

Even if code-completion knows that the DrewBooWidget::CurlyCue you just instantiated is declared in <DrewBooWidgets/private/curlycue.h>, it won't compile with that include because you need to include other files first. Whoops #1.

And if DEBUG is defined, it should actually include <DrewBooWidgets/private/curlycue_debug.h>  Whoops #2.

And when it finds out which header is the correct one to use, where in your source file should the include be added?  At the top of the file, it could miss important #defines.  Before the first existing #include, it could clobber precompiled headers.  After the last existing #include, which happens to be inside an "#if 0" block?   Whoops #3.



I agree that it can be a pain to manage these includes in your head, but that seems to be a problem that's very deeply embedded in the C++ language itself.

This might be one of those features that would be easy to implement if you wanted it to work 90% of the time, and would be very difficult just to get close to 100% of the time.

or1on

  • Guest
Re: [Code completion] Add include file automatically
« Reply #3 on: August 29, 2008, 10:37:16 pm »
THX