MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.69k stars 252 forks source link

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

Open lee-shun opened 2 years ago

lee-shun commented 2 years ago

Observed behavior

Expected behavior

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

lee-shun commented 2 years ago

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

mqcmd196 commented 2 years ago

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

Sologala commented 2 years ago

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

mqcmd196 commented 2 years ago

@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