Wumpf / IncludeToolbox

Visual Studio extension to format, prune, and inspect include directives.
https://marketplace.visualstudio.com/items?itemName=Wumpf.IncludeToolbox
MIT License
51 stars 22 forks source link

Possibility to use fix-includes #37

Closed jcageman closed 7 years ago

jcageman commented 7 years ago

Thanks for this great extension!

Two suggestions:

It would be nice if we would be able to use https://github.com/include-what-you-use/include-what-you-use/blob/master/fix_includes.py, this script quite accurately modifies includes and takes care of placement given the include-what-you-use output.

Besides that it would be nice to use my own version of fix-includes. I am running a custom version of both in order to get the desired behavior. I am probably going to modify my local version of your plugin a bit to get it working, if i have time i try to create a pull request for those improvements

Wumpf commented 7 years ago

Including this directly into the plugin is not really an option I think since then python would be mandatory. Personally I'd rather like to make the own "apply fixes" functionality in the plugin sufficient - if you know of any concrete shortcomings please let me know (I'm not really familiar with the fix_includes.py that comes with iwyu, so please apologize me overlooking any glaring differences :))

However, it should be quite easy to forward the iwyu output to a custom command that can be set in the plugin's preference page. This you could set whatever command you like. Could look like this in the settings:

What do you think?

jcageman commented 7 years ago

Agreed that you don't want to add python as prerequisite. The advantage of using a custom script outside of visual studio is that you can also run it standalone without your extension. Your idea of using a custom command sounds fine. The only problem i see with the current approach is in case the iwyu output is very long, then it won't fit on command line? Maybe writing to a temporary file and passing that to a script would work.

I currently run iwyu like this: C:\Python27\python.exe iwyu_tool.py -p . --v -- --verbose=1 --mapping_file=mappingfile.imp 2> iwyu.log

That script (available in iwyu github) basically reads all files from a compile database and runs iwyu on all of them and outputs to iwyu.log.

Afterwards i run fix-includes.py like this: C:\Python27\python.exe fix_includes.py --nocomments --nosafe_headers --blank_lines --ignore_re=".*(?i)(PrecompiledHeaders|StdAfx).(h|cpp)" < iwyu.log

Note: fix-includes directly modifies the files named in iwyu output, it doesn't return the modified files.

Wumpf commented 7 years ago

Not sure what you mean with "won't fit the command line". The script takes the data from stdin and I'm not aware that there is any limit to the number of data you can feed in there. But it might be a bit more elegant, yes.

Besides, it sound a bit like you should probably just define your own command and not use IncludeToolbox's iwyu integeration. You can very easily define custom commands that execute external tools in Visual Studio.

jcageman commented 7 years ago

You are completely right, thanks for thinking with me. I will have a look at those commands! I just noticed though that i also need all the compile arguments for a file to run IWYU on it, which at first sight seems not to be possible with just custom commands

jcageman commented 7 years ago

I will close this issue now. I created a visual studio plugin that calls iwyu and afterwards calls fix-includes.py (it was very easy). Thanks for the suggestions!