linux-vscode include generator
Posted: Fri Apr 13, 2018 1:44 am
I just moved my environment to Linux and decided to go with VSCode since Eclipse has all of the aesthetic and user experience of Craig's List. Task #1 is of course to get rid of squiggly lines under includes, since I am highly allergic to them.
The C/C++ extension SAYS that it is supposed to work with compile_commands.json, which you get from something like bear, but that seems to be broken and I don't want it repeatedly parsing a massive json anyways.
So here's a little bash script to tidy up includes. Needs bear, jq, and grep to run.
It's not perfect by any means, but it gets the job done and avoids having to use an epipen for the squigglies.
Edit it to your environment, dump it in a .sh at the project root and chmod u+x. Run whenever you add/subtract components.
Let me know if it's of any use.
The C/C++ extension SAYS that it is supposed to work with compile_commands.json, which you get from something like bear, but that seems to be broken and I don't want it repeatedly parsing a massive json anyways.
So here's a little bash script to tidy up includes. Needs bear, jq, and grep to run.
Code: Select all
#!/bin/bash
# don't forget to install bear and jq.
# for debian-style releases:
# sudo apt-get install bear
# sudo apt-get install jq
VSPROPERTIES=./.vscode/c_cpp_properties.json
make app-clean
bear make app
echo -e "\t\t{\"inc\" : [" > inc.json
grep -A1 '"-I",' compile_commands.json | grep "\"${HOME}/.*" | sort --unique >> inc.json
echo -e "\t\t\t\"${IDF_PATH}/xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/5.2.0/include\"," >> inc.json
echo -e "\t\t\t\"${IDF_PATH}/xtensa-esp32-elf/xtensa-esp32-elf/include\"," >> inc.json
echo -e "\t\t\t\"${IDF_PATH}/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0\"," >> inc.json
echo -e "\t\t\t\"${IDF_PATH}/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/xtensa-esp32-elf\"" >> inc.json
echo -e "\t\t]}" >> inc.json
cp "$VSPROPERTIES" "$VSPROPERTIES.old"
jq --argfile inc inc.json '.configurations[].includePath = $inc.inc | .configurations[].browse.path = $inc.inc' "$VSPROPERTIES.old" > $VSPROPERTIES
#rm compile_commands.json
#rm inc.json
Edit it to your environment, dump it in a .sh at the project root and chmod u+x. Run whenever you add/subtract components.
Let me know if it's of any use.