ccls
ccls copied to clipboard
How to config ros catkin_ws when using the ccls with coc.nvim?
Observed behavior
- I already have the
compile_commands.json
generated bycatkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1
under the~/catkin_ws/build
path. I copy thecompile_commands.json
into the `src/Onborad-SDK-ROS', which is basically a ros package. - But as far as I know, ccls can not find the
ros/ros.h
anddji_osdk_ros/commom_type.h
- I could make sure that the project is no errors because the
coc-clang
works well.(But, I like ccls more!)
Expected behavior
- The
ros::...
namespace should be properly found.
Steps to reproduce
- install ros melodic
- creat the
catkin_ws
and cd into the~catkin_ws/src
, clone the[
Onborad-SDK-ROS'](https://github.com/dji-sdk/Onboard-SDK-ROS)` in src. -
cd ~/catkin_ws
andcatkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1
. copy thecompile_commands.json
into theOnborad-SDK-ROS
. Then config the nvim with coc.nvim like the config below. - Open the
Onborad-SDK-ROS/src/dji_osdk_ros/flight_control_node.cpp
you will see something llike this:
the ros::
namespace are defined in the #include <ros/ros.h>
, and the namespace dji_osdk_ros
is defined in the #include <dji_osdk_ros/commom_type.h>
like the arrows in the upper picture.
System information
- ccls version (
git describe --tags --long
): 0.20210330 - clang version: clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
- OS: ubuntu18.04
- Editor: neovim 0.5
- Language client (and version):
"languageserver": {
"ccls": {
"command": "ccls",
"filetypes": [
"c",
"cc",
"cpp",
"c++",
"objc",
"objcpp"
],
"rootPatterns": [
".ccls",
"compile_commands.json",
".git/",
".hg/"
],
"initializationOptions": {
"cache": {
"directory": "/tmp/ccls"
},
"highlight": {
"lsRanges": true
},
"clang": {
"extraArgs": [
"-I",
"/opt/ros/melodic/include/ /home/ls/catkin_ws/devel/include/dji_osdk_ros/"
]
}
}
}
}
And, I have already checked the issue #239 , but I do think that could help me .....
@lee-shun
You can put the generated compile_commands.json
at ~/catkin_ws
(means ~/catkin_ws/compile_commands.json
) and, put .ccls-root
file ~/catkin_ws/.ccls-root
(means execute touch ~/catkin_ws/.ccls-root
).
Is there some env variables or marcos can be set to spcify the ccls-root
and the relative path of compile_commands.json
?
@Sologala after you execute source <your_workspace>/devel/setup.bash
execute the function below
catkin_generate_compile_commands_json(){
echo Generating workspace compile_commands.json...
local catkin_ws=$(echo $CMAKE_PREFIX_PATH | cut -d: -f1)/..
local old_dir=$(pwd)
cd ${catkin_ws}
if [ -e compile_commands.json ]; then
rm compile_commands.json
fi
concatenated="compile_commands.json"
echo "[" > $concatenated
first=1
for d in build/*
do
f="$d/compile_commands.json"
if test -f "$f"; then
if [ $first -eq 0 ]; then
echo "," >> $concatenated
fi
cat $f | sed '1d;$d' >> $concatenated
fi
first=0
done
echo "]" >> $concatenated
cd $old_dir
}
then execute touch <your_workspace>/.ccls-root