ccls icon indicating copy to clipboard operation
ccls copied to clipboard

How to config ros catkin_ws when using the ccls with coc.nvim?

Open lee-shun opened this issue 3 years ago • 4 comments


Observed behavior

  • I already have the compile_commands.json generated by catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1 under the ~/catkin_ws/build path. I copy the compile_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 and dji_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

  1. install ros melodic
  2. 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.
  3. cd ~/catkin_ws and catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1. copy the compile_commands.json into the Onborad-SDK-ROS. Then config the nvim with coc.nvim like the config below.
  4. 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/"
                    ]
                }
            }
        }
    }

lee-shun avatar Sep 18 '21 13:09 lee-shun

And, I have already checked the issue #239 , but I do think that could help me .....

lee-shun avatar Sep 18 '21 14:09 lee-shun

@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).

mqcmd196 avatar Oct 11 '21 10:10 mqcmd196

Is there some env variables or marcos can be set to spcify the ccls-root and the relative path of compile_commands.json?

Sologala avatar Jun 18 '22 06:06 Sologala

@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

mqcmd196 avatar Jun 18 '22 06:06 mqcmd196