> For example if user adds the source file -
it needs to be added to json as well,
This is the part I don't understand - at the moment the
compile_commands.json file is written by non UI tools. The UI
tools may be involved in creating things like cmake files,
etc. Any new tool that comes along also needs to be able to
translate a human readable file into a compile_commands.json,
but that tool needs to operate at the command line
(headlessly) to be useful.*
The question is complex enough to be described shortly. And you are
right, it is very important who and how can access the cc.json.
But I never suggested to restrict the scenario with UI only. I'm
talking about headless API to be triggered on "translation unit
added", and this is very different from handling LSP
"textDocument/didOpen", because where was no "open in UI" request
yet and it may not happen at all. If the plan is to run the full
loop with cmake to re-generate the cc.json on every structural
change - it will never scale.
Again, this is just an example that appears during IDE work and may
be useless during batch build.