c++visual-studio-codeautocompleteintellisenseros

VScode setup with ROS and auto complete


I am struggling to configure VSCode with ROS to have the auto-complete function. I am used to using VSCode with Qt and OpenCV and everything worked fine. For example, for OpenCV, I just edited c_cpp_properties.json like this:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/opencv4/opencv2"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

The auto-complete for OpenCV works fine then (I have the C++ IntelliSense extension). But then, as soon as I try to specify the include folder from ROS in the c_cpp_properties.json, nothing works anymore, not even the OpenCV auto-completion:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/opencv4/opencv2",
                "/opt/ros/melodic/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

It's like ROS is blocking everything. What am I doing wrong? I specify that I click on "Open Folder" in VSCode and browse for the ROS package to load it. I am working on Ubuntu 18.04 LTS.


Solution

  • I had a problem when using the IntelliSense with ROS. It would simply not search the ros namespace, no matter what I did. So I thought of changing the cppStandard (in file c_cpp_properties.json) to gnu++11 (it's only for IntelliSense anyways). It immediately started working.

    Here are the results with cppStandard set to gnu++14 enter image description here

    Here are the results with cppStandard set to gnu++11 enter image description here

    I have even tried gnu++17, but that too gave limited success. Looks like gnu++11 worked best.

    I also tried what Richard had to say in his answer. It works without having to change anything else.