Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
A
compile_command.json
enables your LSP to use appropriate compile flags for the C/C++/Objective-C files you're compiling in your project.In a mixed Nim and C/C++/Objective-C project you have two options to integrate your C/C++/ObjC sources into your project:
{.compile.}
pragmas in your nim files directly, i.e. use Nim as a frontend to your C compiler (clang/GCC/etc.)If you opt to choose (2): then you miss out on the generation of
compile_commands.json
- unless you do it yourself in NimScript. If you choose option (1) then you're probably going to use CMake (or an alternative) to generate acompile_commands.json
.The
compile_commands.json
can be generated from NimScript by post-processing the build JSON for the Nim project/root file, but with a catch: this JSON file's"compile"
field (which is what is required to generate thecompile_commands.json
) produced by the compiler is dependent on what files are in or out of the build cache - thus you need to handle this (by merging files you generate). In Nim/NimScript this looks something like this: https://gist.github.com/miguelmartin75/298a8b39664a89a69abd8b23a5a805a8 (this is taken from my codebase). Doing this task in NimScript is error-prone and buggy, e.g. if you remove a C file: it stays in your cache & there's a lot of LOC for something so simple.To summarize, there are two motivating points stemming from the use-case of having LSP support (via a
compile_commands.json
) for mixed Nim & C/C++/ObjC projects:Implementation
To add support, I've added the following compiler flags:
--compileCmdsJson:<bool>
(default off)compile_commands.json
file<nimcache>/compile_commands.json
--projectCompileCmdJson:<bool>
(default off)<nimcache>/compile_commands_<projectname>.json
--rootCompileCmdsJson:<bool>
(default off)compile_commands.json
file for simpler projects (one binary file produced). Naming convention is respected byprojectCompileCmdJson
flag.Testing
TODO