linux-vscode include generator

User avatar
ninjaneer
Posts: 5
Joined: Mon Apr 02, 2018 5:15 pm

linux-vscode include generator

Postby ninjaneer » 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.

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
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.

mikemoy
Posts: 599
Joined: Fri Jan 12, 2018 9:10 pm

Re: linux-vscode include generator

Postby mikemoy » Sun Apr 15, 2018 1:39 pm

Thanks for sharing. Very useful.

Who is online

Users browsing this forum: No registered users and 25 guests