Is there any lightweight method or VsCode extension to merge all compile_command.json
files in different build folders in the whole workspace? If possible, I think it would be a convenient way for Clangd
to configure intellisense.
Update:
Here is a hypothetical workspace
├── build
│ └── compile_command.json
├── compile_command.json
└── src
├── project_A
│ └── build
│ └── compile_command.json
└── project_B
└── build
└── compile_command.json
, and usually workspaces aren't constructed in such a chaotic way. I want to merge all compile_command.json
files, no matter the hierarchy, and output the combined file at the top directory in a simple way.
Referring to this answer and the comment by @starball,
can search all
.json
files in the current and below paths and combine the output tomerged.json
, where-s
: The entire input is passed to the filter as a single long string;add
: The filteradd
takes as input an array, and produces as output the elements of the array added together;**/*.json
: The pattern**/*.json
will therefore expand to the pathname of any file that has a filename suffix of.json
anywhere in or below the current directory.Finally, this command can be configured as a task for convenience in VsCode with
References:
https://jqlang.github.io/jq/manual/#invoking-jq
https://unix.stackexchange.com/a/457404