Atom IDE for a Catkin C++ Workspace
Update July 2019: Cquery seems to be no longer maintained, but there is a follow-up project called ccls.
One of my favorite editors for coding is Atom, which has recently received support to work as a full-fledged IDE by utilizing the language server protocol. This is a short guide on how to setup the Atom IDE for ROS developers.
Requirements
- Up to date version of Atom editor
- Packages for Atom: atom-ide-ui, ide-cquery
- Cquery
- compdb
Setup
First, get Atom and Cquery up and running
- Build and install cquery according to the instructions on its Github Wiki.
- Install the Atom packages atom-ide-ui and ide-cquery
- In the ide-cquery settings of Atom, make sure the correct Cquery path is set (according to your installation)
Now in your own code base, do the following:
- Compile your catkin packages with
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
. This will create acompile_commands.json
file for each package in its respective build folder. - Then collect all
compile_commands.json
files into a single file by executing in the catkin workspacecat ./build/**/compile_commands.json > compile_commands.json && sed -i -e ':a;N;$!ba;s/\]\n*\[/,/g' compile_commands.json
Since each
compile_commands.json
file must be delimited by a pair of square brackets, the second part of this command is supposed to remove pairs of brackets that we no longer need after concatenating multiple files. - So far so good, but this does not work for header-only libraries, because no compile commands were generated for them, since there is nothing to compile.
To include also the headers into the json file, run
compdb -p . list > compile_commands.json.extended
- Finally, create a symlink in your project root of the Atom workspace
ln -s /path/to/compile_commands.json.extended compile_commands.json
After restarting Atom, Cquery should now be able to find this file and start building the database.
Result
On startup, cquery will take some time to load the index into memory. Expect high CPU usage during this time. Afterwards, you should be able to hover over variables and functions and jump around in your code.
Hope it helps, happy coding!