c++visual-studio-codeintellisenseinclude-path

When workspace include paths are defined, intellisense doesn't work any more on user ones


For coding with C++, I'm using the Microsoft provided C/C++ extension for Visual Studio Code.

I defined the paths from settings UI. Include paths that are common to all my project are defined in the User tab (for user settings).

When writing #include <relative path to a header in user declared include paths>, I can click on it and reach the file. Symbols defined there are correctly recognized and autocomplete is available. When writing #include <beginning of relative file> I can use autocomplete in order to search the desired file.

As soon as I add include paths in the Workspace tab, IntelliSense doesn't work anymore with respect to includes in the User tab. It works again as soon as I empty this tab.

NB the path recognition is randomly broken, sometimes it works again after a time, path autocompletion remains broken.

How can I fix it?


Solution

  • This is just how VS Code settings scoping works by default. If a setting is defined at the user scope and the workspace scope, the value defined at the workspace scope is used, and the value defined at the user scope is ignored. For more info, see the documentation on settings precedence.

    From a very cursory skim of the extension API docs, I don't think extensions could easily provide behaviour overriding this, since the function to get a setting value don't seem to allow getting from a specific scope.

    As for how best to get what you really want, it might depend more on context. Simplest answer (thought maybe context allows something better) is to just define everything in the workspace scope (assuming you're using the C_Cpp.default.* settings), or in your configs in c_cpp_properties.json, where ${default} can be used in the include paths to refer to the values defined via the default include path setting taking highest precedence.