ami-iit / ami-commons

In this repository we store tools and utilities shared between our repositories.
11 stars 2 forks source link

Document how to setup VisualStudioCode for a repository #4

Open RiccardoGrieco opened 2 years ago

RiccardoGrieco commented 2 years ago

In this issue the following will be documented:

traversaro commented 1 year ago

It would be useful to also have suggestion to configure the Python part fyi @Giulero .

traversaro commented 1 year ago

This could be a good topic for the proposed SW dev AMI recurring event @RiccardoGrieco .

Giulero commented 1 year ago

I missed this! Python side, I usually use some extensions:

For C++ I use:

Misc:

traversaro commented 1 year ago

Today we experiences this difficulties with @davidegorbani, and I did not knew where to point him as we indeed do not have a simple doc on how to setup an IDE (for example Visual Studio) for C++ .

RiccardoGrieco commented 1 year ago

How to navigate through C++ code

In order to setup VS code to navigate dependencies you first need to install the C/C++ Extension Pack from the extension window accessible from the left sidebar of IDE.

Then you have a user configuration and a workspace one. The user configuration can be accessed from the command palette (press Ctrl+Shift+P) and typing "open user setting":

https://user-images.githubusercontent.com/26788384/231255693-ebc079a5-d9a8-4219-baf2-7cc97710c3b8.mp4

Edit the C_Cpp.default.includePath(or create it if it doesn't exist):

"C_Cpp.default.includePath": [
        "/home/riccardo/Code/robotology-superbuild/build/install/include/**"
    ],

In the example above, I added the include path of the superbuild. Thanks to this, you can easily navigate through the dependencies in all of your c++ projects.

If you want to use a specific includePath for a project, you can create a workspace (i.e. the folder you open with the IDE) configuration, by creating the .vscode folder with inside the file c_cpp_properties.json, which looks like this:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${default}",
                "${workspaceFolder}/src/**",
                "/usr/local/include/eigen3",
                "<path_to_repos>/robotology-superbuild/build/install/include/**",
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}

The example above was created by the extension itself from the command palette, using the entry C/C++: Edit configuration:

https://user-images.githubusercontent.com/26788384/231256970-dcae9de2-8c42-42b6-8a6a-027813d5ecff.mp4

You can then edit includePath field for your needs. Note that ${default} means the includePath from the User configuration.

In this example I used the robotology-superbuild install path, but you can add all 3rd party installed libraries the same way.

For more information concerning the workspace configuration for C/C++ extension, refer to https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference

traversaro commented 1 year ago

Thanks a lot @RiccardoGrieco !

davidegorbani commented 1 year ago

cc @gabrielenava

traversaro commented 1 year ago

cc @mleonori @pietrobalatti I think we were discussing about this last time, I forgot this discussion was open.