Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 #include and using directives management.

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
GennadiyKorol Posted - Feb 26 2010 : 5:10:56 PM
Good day Whole Tomato developers and VAX users!

More than year and half ago I started a thread about an automatic addition of #include statements. http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=8009.
And a year later you have pulled this feature off beautifully.

This time I would like to suggest something even more awesome that could really make C++ development more like it is in Java, C# or Python (eclipse + Pydev).

I want VAX to manage my #include and using statements automatically.
I want to use a simple function, let's codename it "Organize includes" which when executed over a C++ file (for starters) will do the following:

* Find all undefined symbols in a file and add a minimal set of #include statements that define them.
* Find all includes that are not necessary for the file to compile and remove them.
* Group includes using the longest common prefix and <> or "" types.
For instance:

#include "library/vector.h"
#include <gl/gl.h>

#include "library/matrix.h"
#include <set>
#include <algorithm>


will be transformed into:

#include "library/vector.h"
#include "library/matrix.h"

#include <gl/gl.h>
#include <set>
#include <algorithm>


* It is not enough to just #include most of the symbols, in big software projects they are defined in different namespaces. So I want VAX to add the using directive for either namespace or its symbol automatically.

For instance:

vector<int> v;

After "Organize includes":

#include "library/vector.h"
using library::vector;

vector<int> v;


We would have user preferences for adding "using namespace" over adding "using namespace::specific_symbol", so that the user will have his includes managed the way his team does.

Later it should be extended to work on .h files as well.
To show you my dream vision example, this is how it'd work:

Initial file:

Shake makeMeShake()
{
	Banana banana;
	Knife  cutter;
	Mixer  mixer;
	Milk   milk;

	vector<Mixable> bananaSlices = cutter.cut(banana);
	mixer.add(bananaSlices);
	mixer.add(milk);

	FoodMix tastiness = mixer.mix(10);
	return Shake(tastiness);
}

After "Organize includes"

#include "groceries/Banana.h"
#include "groceries/Milk.h"

#include "kitchenStuff/Knife.h"
#include "kitchenStuff/Mixer.h"

#include "food/Mixable.h"
#include "food/FoodMix.h"
#include "food/Shake.h"

#include <vector>

using namespace groceries;
using namespace kitchenStuff;
using namespace food;

using std::vector;

Shake makeMeShake()
{
	Banana banana;
	Knife  cutter;
	Mixer  mixer;
	Milk   milk;

	vector<Mixable> bananaSlices = cutter.cut(banana);
	mixer.add(bananaSlices);
	mixer.add(milk);

	FoodMix tastiness = mixer.mix(10);
	return Shake(tastiness);
}


Think about it, why do we need to manage our includes, really? In 95% of the cases, I can trust software to do that.
It works in Pydev, it works in C# and it works in Java. Why do we have to suffer as C++ programmers?

This could have a tremendous value for big projects because if you can optimize includes in the .h and .cpp files, it will *dramatically* reduce the compilation time.

I don't even care for this feature to run fast, as long as it does the job.

I think as long as this feature is well customizable (so you could define your include and using directive stytle) it will truly be a dream coming true and a super worthy upgrade.


Thanks for your attention and thoughts,
Gennadiy
4   L A T E S T    R E P L I E S    (Newest First)
GennadiyKorol Posted - Mar 01 2010 : 2:30:33 PM
Good to hear you are considering all those features, accord.

Given you implement the "get unused includes" how hard will it be to combine all the features together and make the include management truly automatic?

After all you already store where the symbol is defined or for each file what symbols it defines. From there on it shouldn't be hard to figure out which includes could be safely removed.

You also paint the unknown symbols in red, so you are able to figure out what symbols are already defined and what are not and you do have the "add include feature" nailed for the most part.

So all together it looks like the next step that will really change many peoples lives. You guys just have to make sure that I can customize the style for my includes, which shouldn't be hard.

I know that C++ is a hard language to parse, but once you nail it in VAX it will only bear good fruit as so many more things will be possible when this is done. Also good parsing engine is essential for even more basic and existing features of VAX, such as find references.


With great appreciation for the work you do for us C++ developers,
Gennadiy
accord Posted - Feb 28 2010 : 6:34:26 PM
Lio: yes, typically this is the standard and unpleasant method of finding unnecessary include files. But it is not obvious to implement this without using the compiler. However, it is possible to do this by writing a Visual Studio script file, I have seen working example of doing this. You may find this helpful:

http://www.wholetomato.com/forum/forum.asp?FORUM_ID=35

I have added your vote to the case
Lio Posted - Feb 28 2010 : 5:49:34 PM
quote:
Originally posted by accord
There is a feature request to show unnecessary includes which is a good start:

case=32032
-> Tools -> Sort Selected Lines



+1 please, that feature would be awesome.

Currently in older files with lots of includes I comment out all the #include lines and then compile and comment back in line by line until it compiles! Having visual assist tell me which are not necessary would be absolutely awesome.

Lio
accord Posted - Feb 28 2010 : 4:08:32 PM
Wow. Long and detailed post!

We don't have to suffer as C++ programmers since Visual Assist is here to help us However it is true that C++ is much more complex than other languages. The language is complex on its own (templates, backward compatibility with old versions from 197x years) and additionally there is a preprocessor so you can create recursive macros and complex include hiearchies which is very slow to parse. Doing include removal requires exact parsing like compiler does.

There is a feature request to show unnecessary includes which is a good start:

case=32032

I also added your comments to this case.

Add using refactoring request is

case=32045

About grouping: you can achieve similar result with the sort lines feature:

VAssistX -> Tools -> Sort Selected Lines

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000