VSC "Format Document" messes up #include order *solved*

My problem is pretty much what the title says:
When I use STRG-ALT-F to format my C++ files VSC also messes with the order of #includes.
And of cause this leads to errors that were not there before… :frowning:

For example this

#include "soc/soc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "XClk.h"
#include "DMABuffer.h"

becomes this

#include "DMABuffer.h"
#include "XClk.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "soc/soc.h"

… and subsequently fails compile.

Is there a way to forbid the formatter reordering stuff?

It lexicographically sorted the includes, hm. I’d say it’s best to ask in Issues · microsoft/vscode · GitHub for this VSCode specific issue with the ‘Format Document’ feature.

2 Likes

Alright, just did that.
Let’s see what they come up with…

Thanks!

OK, turns out the DMAbuffer.h was missing the reference to one of the former includes – moved the include into there and now the sequence of includes doesn’t matter anymore.

1 Like