Visual Studio Code: How to configure includePath for better IntelliSense results
Visual Studio Code: How to configure includePath for better IntelliSense results
so I am a complete beginner to using Visual Studio Code and I have no clue what I am doing.
I've searched around (maybe not enough), but I cant find just a simple explanation for someone like me on how to configure the c_cpp_properties.json file that I am redirected to whenever I click on the yellow lightbulb next to a line that is underlined with a green squiggle.
Lightbulb example
c_cpp_properties.json
I just want to know what to put in the .json to make IntelliSense work properly
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
2 Answers
2
From:
https://code.visualstudio.com/docs/languages/cpp
Below you can see that the MinGW C++ include path has been added to browse.path for Windows:
{
"name": "Win32",
"includePath": [
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
Hope that helps! :)
Also when I put in any code that is different from the original code it gives an error "Failed to parse "e:\.vscodec_cpp_properties.json": Unexpected token ] in JSON at position 1896"
– Niko P.
Sep 18 '17 at 1:06
From the official documentation of the C/C++ extension:
Configuring includePath for better IntelliSense results
If you're seeing the following message when opening a folder in VS Code, it means the C++ IntelliSense engine needs additional information about the paths in which your include files are located.
The include paths are defined in the "includePath"
setting in a file called c_cpp_properties.json located in the .vscode directory in the opened folder.
"includePath"
You can create or open this file by either using the "C/Cpp: Edit Configurations"
command in the command palette or by selecting "Edit "includePath" setting"
in the lightbulb menu (see the screenshot below). The quickiest way to locate a lightbulb is to scroll to the top of the source file and click on any green squiggle that shows up under a #include statement.
"C/Cpp: Edit Configurations"
"Edit "includePath" setting"
When a folder is opened, the extension attempts to locate your system headers based on your operating system, but it does not know about any other libraries that your project depends on. You can hover over the green squiggles or open the Problems window to understand which headers the IntelliSense engine is unable to open - sometimes it's the dependent headers that can't be located.
You can specify the remaining paths using one of the techniques described below.
The extension can get the information for "includePath"
and "defines"
from a compile_commands.json file, which can be auto-generated by many build systems such as CMake and Ninja. Look for the section where your current configuration is defined (by default there's one configuration per OS, such as "Win32 or "Mac"), and set the "compileCommands"
property in c_cpp_properties.json to the full path to your compile_commands.json file and the extension will use that instead of the "includes"
and "defines"
properties for IntelliSense.
"includePath"
"defines"
"compileCommands"
"includes"
"defines"
The first thing to try is to leverage the lightbulb path suggestions to auto-resolve the include paths. When you open a folder, the extension will recursively search for potential include paths that match the header files your code is using based on the paths set by the "browse.path"
setting in c_cpp_properties.json. Click on the green squiggles under #include statements and you'll see a lightbulb offering suggestions of paths that will allow IntelliSense to resolve the included file.
"browse.path"
If you don't see path suggestions in the lightbulb, try adding the root folder where the headers are likely located in to the "browse.path"
setting in c_cpp_properties.json. This allows the extension to recursively search in these folders and offer more suggestions in the lightbulb as the search process goes on.
"browse.path"
If none of the above fully resolves the paths, you could manually specify the paths to the headers that your project depends on in the c_cpp_properties.json file. Look for the section where your current configuration is defined (by default there's one configuration per OS, such as "Win32 or "Mac"), and add your paths in the "includePath"
setting and defines in the "defines"
setting. For example, the following screenshot shows a snippet of the file specifying path for the Mac configuration.
"includePath"
"defines"
Also, for MinGW, as the documentation of the extension explains you may ask gcc/g++ to list its own include files:
gcc -v -E -x c++ nul
There are two ways to verify that the include paths are correctly resolved:
This indicates that the IntelliSense engine has got the include paths resolved so you can start enjoying the full IntelliSense for your C or C++ code for the current translation unit. Note that you may still see errors on other files if they belong to a different translation unit that requires additional include paths to be configured.
Configuring MinGW
c_cpp_properties.json reference guide
you simply copy/pasted official doc, didn't you?
– Shihab Shahriar
Feb 18 at 15:39
Didn't you see the first text of my answer ?
– Sushant Chaudhary
Feb 18 at 23:17
Sorry, that was my mistake. But do you really think acknowledging the source is enough? that there's nothing wrong with this kind of copy/pasting?
– Shihab Shahriar
Feb 19 at 4:15
I myself have been contributing to the development of this C/C++ extension for VSCode, therefore, I think I deserve this right to at least copy, edit and post a part of documentation for someone who might be in need of it and doesn't have a clue about it. Plus, I've also linked the original sources in the end.
– Sushant Chaudhary
Feb 19 at 5:21
@ShihabShahriar Strictly speaking the source repo is under the MIT licence, so the documentation probably is too, which by extension might mean this answer is also under the MIT licence.
– Pharap
Jul 4 at 8:25
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I have cygwin installed, do you know what the code would be for that?
– Niko P.
Sep 18 '17 at 1:02