Skip to content

Add support to generate compilation database#51

Open
neilweidinger wants to merge 4 commits intodevelopfrom
gen-compilation-database
Open

Add support to generate compilation database#51
neilweidinger wants to merge 4 commits intodevelopfrom
gen-compilation-database

Conversation

@neilweidinger
Copy link
Copy Markdown
Member

@neilweidinger neilweidinger commented Apr 21, 2020

Description

Generates a compile_commands.json compilation database, used for semantic auto-complete in text editors using the clangd language server. Can be used for text editors that support the language server protocol, like VSCode and Vim :))

https://sarcasm.github.io/notes/dev/compilation-database.html

@neilweidinger
Copy link
Copy Markdown
Member Author

f, travis is failing because -MJ is only supported by clang, fixing now

@neilweidinger neilweidinger force-pushed the gen-compilation-database branch from 7987a26 to 2d54e6c Compare April 21, 2020 11:55
@mkristien
Copy link
Copy Markdown
Collaborator

I do not have any major issues with this. Thanks for keeping the change set small.

A small suggestion:
Language server indexing is unrelated to the compilation cycle. Your implementation, on the other hand, only generates the indexing database compile_commands.json when you compile the code base. Until then, your editor would not make use of this. Furthermore, the database is destroyed when you clean the object files. Note, clean does not even remove the linter cache.

You could instead have a separate target (e.g. compiledb) that would create compile_commands.json if it does not already exist. You can run this once, independently from the edit->compile->decipher_error_log cycle. I use ccls for this. This has a simpler syntax that applies globally for all cpp files, which is an advantage, as the compilation database does not need to be recreated when adding new files.

Copy link
Copy Markdown
Collaborator

@mkristien mkristien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you not interested in extending this functionality to test files as well?

# Only works with gnu sed, couldn't get newlines to work with bsd sed
# On mac use homebrew to install gnu sed
# Double $ signs are so Make interprets it as a single regex $, on command line use a single $ sign
$(Verb) find bin -name '*.json' -exec sed -e '1s/^/[\n/' -e '$$s/,$$/\n]/' {} + > compile_commands.json
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clean the temporary .json files once you do not need them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this should be possible, but I'm not quite sure why this would be beneficial? The .json files are in bin anyways, would there be a difference?

@neilweidinger
Copy link
Copy Markdown
Member Author

Thanks for taking a look Martin! That's definitely a good point that language server indexing is unrelated to the compilation cycle.

My original rationale for putting it together during compilation was because it was just easy to pass the -MJ flag in our makefile where it handles compiling the files, and now that you point it out, I'm actually not sure why I made it so that the database gets deleted after running clean haha. I totally forgot about the test files, I'll make sure to include them.

Having the database as a separate target seems like a much better idea, I'll give it a shot at implementing it this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants