11

I'm currently using Conan on a C++ project using sqlite_orm as a dependency.

When using my personal include (like myClass.hpp for example) Visual Studio Code is able to provide auto-completion but with Conan's include, no auto-completion is possible.

I'm looking for a way to link the include path of Conan to my VSCode, any idea?

Kevin
  • 16,549
  • 8
  • 60
  • 74
Bibas
  • 498
  • 1
  • 4
  • 17

6 Answers6

25

Add the following line in your project's .vscode/c_cpp_properties.json file

"includePath": ["${workspaceFolder}/**", "~/.conan/data/**"]

CodingMedalist
  • 366
  • 3
  • 4
13

Add set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to your CMakeLists.txt (or add to cmake: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..) so a build/compile_commands.json will be generated.

VS Code (clion, etc) can utilize this file to support auto complete:

$ cat .vscode/c_cpp_properties.json
{
    "configurations": [
    {
        "name": "Linux",
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "clang-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
    }
    ],
    "version": 4
}
dvorak4tzx
  • 493
  • 7
  • 8
3

Conan doesn't provide an extension for vscode yet, but you can try:

https://github.com/FIREFOXCYBER/conan-tools-vs-code

It's available on marketplace.

Otherwise, you can add manually the package folder path (e.g. ~/.conan/data/package/version/package/package_id/include) in your settings.

Kevin
  • 16,549
  • 8
  • 60
  • 74
uilianries
  • 3,363
  • 15
  • 28
3

A combination of dvorak4tzx's and spanishgum's answers, combined with VS Code's option for Customizing default settings is the following option:

Generate a build/compile_commands.json eiter by adding to CMakeLists.txt:

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

or on the command line:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

And then insert into .vscode/settings.json:

"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",

Note: I experienced trouble if

"configurationProvider": "ms-vscode.cmake-tools"

was part of the c_cpp_properties.json. Without it, the IntelliSense works as expected.

I would argue that "includePath": ["${workspaceFolder}/**", "~/.conan/data/**"] is not desired, as you may have many versions of each library beneath ~/.conan/data.


Sources:

solosuper
  • 81
  • 4
2

After searching in the settings of VSCode, I found that you can change the path of your include in c_cpp_properties.json file that you can find in your .vscode folder

Adding the path you want in the includePath field allow you to choose your own include path

Bibas
  • 498
  • 1
  • 4
  • 17
2

I want to add that you can also use the .vscode/settings.json file as an alternative to .vscode/c_cpp_properties.json.

For example, I just set up a project with this:

{
  "C_Cpp.clang_format_path": "/usr/lib/llvm-10/bin/clang-format",
  "C_Cpp.default.includePath": [
    "~/.conan/data/**"
  ],
}
spanishgum
  • 1,030
  • 1
  • 14
  • 29