Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuration provider for cpptools / IntelliSense #22

Open
SirLemyDanger opened this issue Jan 14, 2021 · 5 comments
Open

configuration provider for cpptools / IntelliSense #22

SirLemyDanger opened this issue Jan 14, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@SirLemyDanger
Copy link

Hi,

it would be awesome if this extension would serve as a configuration provider for cpptools / IntelliSense.
Most importanly provide the include paths for all the consumed conan packages dynamically.

Docu: https://github.com/Microsoft/vscode-cpptools-api#readme
Example: https://github.com/microsoft/vscode-cmake-tools/blob/develop/src/cpptools.ts

Cheers

@mymichu
Copy link
Collaborator

mymichu commented Jan 17, 2021

Thank you for this input. We will have a look into it and it would be a great addon to our Plugin.

@chausner
Copy link

chausner commented Feb 6, 2021

I'd say this is currently the biggest productivity blocker for me when using VS Code and Conan together. Do you know any workaround that's possible today that let's you use IntelliSense correctly with headers from Conan dependencies?

I tried a few things a while ago, also with this (no longer maintained) alternative plugin. If I remember correctly, I could partially get it to work but some manual configuration of include paths was needed and it wasn't easy to set up.

If this plugin could make that process automated and works stable for both Conan packages in the cache and editable packages, that would be a big step forward in improving the Conan experience in VS Code!

@chausner
Copy link

chausner commented Feb 6, 2021

Here is one way that seems to work to get IntelliSense for Conan dependencies. It is assumed that you build manually using conan source, conan install, conan build inside a folder called build in your workspace folder. It is also assumed that you use CMake to build your project.

  1. In conanfile.py, adapt your build() function to enable the CMake option CMAKE_EXPORT_COMPILE_COMMANDS. E.g.:
    def build(self):
        cmake = CMake(self)
        cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = "ON"
        cmake.configure()
        cmake.build()
        cmake.test()
  2. Build your project. E.g.:
    mkdir build
    cd build
    conan install ..
    conan build ..
    
    The file build/compile_commands.json should have been generated now.
  3. In VS Code, press Ctrl+Shift+P and run command C/C++: Edit Configurations (JSON). Add a new property compileCommands to the default configuration that points to the generated compile_commands.json file:
    {
        "configurations": [
            {
                "name": "Win32",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "windowsSdkVersion": "10.0.18362.0",
                "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe",
                "cStandard": "c17",
                "cppStandard": "c++17",
                "intelliSenseMode": "windows-msvc-x64",
                "compileCommands": "${workspaceFolder}/build/compile_commands.json"
            }
        ],
        "version": 4
    }
    You may also want to check and adapt the other attributes in the configuration, in particular includePath. IntelliSense will fall back to the search paths specified there when you e.g. create a new source file that is not listed in compile_commands.json.
  4. Save the C/C++ configuration.

You should now be able to get IntelliSense for functions/types defined in Conan dependencies.

When you create new source files or add/change Conan dependencies, make sure to rebuild your project so that compile_commands.json gets updated. However, I haven't found an easy way to make IntelliSense reload the compile_commands.json apart from e.g. closing and reopening the folder in VS Code.

@mymichu
Copy link
Collaborator

mymichu commented Feb 8, 2021

@chausner. Currently I am using the same approach as you mention, with exporting compile_commands.json from CMake. But I agree it would be a great help to integrate cpptools into the conan plugin. It will be my next task.

@mymichu mymichu moved this from ToDo to In Progress in Conan Plugin Feb 8, 2021
@chausner
Copy link

CMAKE_EXPORT_COMPILE_COMMANDS is not supported by the default Visual Studio generator on Windows. A workaround that I have found is to change the generator to Ninja which ships with Visual Studio. See https://docs.conan.io/en/latest/integrations/build_system/ninja.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Conan Plugin
In Progress
Development

No branches or pull requests

3 participants