2

I was programming c++ in Visual studio 2017 and I suddenly noticed that visual studio had changed my includes to be ordered alphabetically. I'm not sure what triggered this reordering.

I don't mind some of the other formatting that happens but I don't want my include order to be changed.

There is one include in our header files ..._precompiled.h that always needs to be first or compilation can give problems. Is there anyway to disable this?

It might also be visual assist behavior but I don't think so since I didn't have this problem in vs2013.

Update:
My colleague suspects "Options->Text editor->C/C++->Formatting->Enable ClangFormat Support" lies at the root of the problem. Enable ClangFormat support We don't yet knows what triggers the formatting so I'm not sure this is the problem.

Does anyone based on this information have an idea what could trigger the formatting and reorder of the includes?

turoni
  • 1,345
  • 1
  • 18
  • 37
  • Codemaid & Resharper have the functionality do you use any of those? – vfle Sep 04 '18 at 13:50
  • Definitely related to VAX or some other plugin. VS doesn't have such a feature out of the box. – babu646 Sep 04 '18 at 13:50
  • Visual assist is the biggest, other than only one that colors my output. I used the same plugins in vs 2013 and there I never had it for a year. One week of vs 2017 and both I and a colleague of me got it. – turoni Sep 04 '18 at 13:50
  • VAX re-orders include ? – Max Sep 04 '18 at 14:01
  • @vfle no I have never heard of them. – turoni Sep 04 '18 at 14:11
  • Any reason for the downvote, I'm still investigating the problem myself. – turoni Sep 05 '18 at 08:34
  • @turoni Usually the re-order would trigger in those actions: Save file with changes, save all, format document or clean up action. None of those worked? – vfle Sep 05 '18 at 13:45
  • @Vfle Format document triggered the reorder, if I disable the ClangFormat support format document doesn't trigger the reorder. Thanks for helping me locate the problem with certainty. Will you update your answer so I can mark it as the accepted? I also want add another answer or suggest an edit to your answer. – turoni Sep 05 '18 at 13:58
  • I think that's the final edit from me, if something is missing feel free to edit! – vfle Sep 05 '18 at 14:26

2 Answers2

1
  1. Find the trigger of the sorting.Common triggers are save,save all, format document & code clean up.

  2. Disable all plugins and activate the trigger you found. If it triggers it is Visual Studio else a Plugin.

Visual Studio cause:

Tools => Options => Text Editor => Your language => Advanced => Using directives

other possible paths for settings that could cause:

Tools => Options => Text Editor => Your language => Code Style => Formatting => Sort Usings

or

Tools => Options => Text Editor => Your language => Code Style => Formatting => ClangFormat support (disable it)

Plugin cause:

  • Known plugin with that functionality (Resharper, CodeMaid)
  • Enable plugins one by one to find the specific plugin.
  • Google about it and update that list :)
turoni
  • 1,345
  • 1
  • 18
  • 37
vfle
  • 1,355
  • 7
  • 18
  • I will try this approach and report back if I find anything. – turoni Sep 05 '18 at 08:34
  • @turoni Found something related to VS which may cause you the trouble. – vfle Sep 05 '18 at 08:47
  • thanks for the continued search, I'm now trying to find the trigger, I set a header second that would be sorted first in the file I'm working on. Now I'm hoping I do the trigger sometime during the day and then when I notice it undo my changes to find the trigger. – turoni Sep 05 '18 at 09:28
0

Its been a while but for anyone who stumbles upon this problem like myself
I think that i found the solution because I happened to have the same problem or at least similar.
In vscode go to File -> Preferences -> Settings and paste C_Cpp.clang_format_sortIncludes and turn it to false then try formatting your code
In my case that did change the order of includes