'Setting up VSCode to include/exclude folders for C++ intellisense
I often have a project with CMake to manage my build system. So you can imagine I would have a load of third-party headers, and my own headers within my install folder.
This is extremely troublesome when I have 2 copy of the same header: one in my install folder (old one) and the one I'm modifying right now (new one). When that happens, sometimes intellisense won't know which is the correct one and might think that my function signature is wrong (because it is looking at the older version).
Same problem when you trying to Ctrl + Left click into a class/function in order to quickly navigate to its definition. It might direct me to the wrong file (in install folder) and thus modify that file won't have an effect in the project (since the "real" file will quickly modify the old one).
An example of what my include folder structure in my install folder:
- boost
|- fake_boost_header.h
- eigen
|- not_reap_eigen_header.h
- abseil
|- real_fake_abseil_header.h
- my_header.h
- my_other_header.h
I have tried the following solution, but seems like it is not working:
Have includePath in c_cpp_properties.json to be install/include/<all_third_party_folder>.
Any idea is welcome. I'm more than open to use third-party plugin...
Solution 1:[1]
It seems to me your install/include/<...> solution does the opposite of what you want, in that it will guarantee VS Code finds the headers in your install folder first. You probably want include/** so that it searches all subdirectories in your include folder, assuming that's where the headers are that need editing.
I'm not sure why you'd want VS Code to know about your install folder, as that's the output of your build / code generation process. If you need versions of third-party code in your install folder, have your build process copy them in from somewhere in your source tree, so that you're not mixing (external) source code and generated code in the same directory. That is, treat the third party code as source code in itself, even if the only thing you do with it is copy it into your install folder. Then you can add the install folder to the list of excluded folders in .vscode/settings.json to avoid VS Code searching those directories:
{
...
"C_Cpp.files.exclude": {
"install/**": true,
...
},
"files.watcherExclude": {
"install/**": true,
...
},
"search.exclude": {
"install/**": true,
...
},
"files.exclude": {
"install/**": true,
...
},
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gino Mempin |
