Background
I am using VSCode with the C/C++ extension to edit ARM mbedOS files. The compiler am I using to build is from IAR.
Issue
The extension is doing a pretty good job of finding the definitions of objects but occasionally it will jump to a definition found in C:\PROGRAM FILES (X86)\WINDOWS KITS. How do I prevent the extension from indexing folders like C:/PROGRAM FILES (X86)/WINDOWS KITS/ and C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/?
Expected behavior
With the settings I have in my .json files only C/CPP/H files that should only be indexed should be from the workspace sub-directories and IAR's compiler sub-directories. I would expect to either not find the correct definition or find nothing at all (which would mean the include path is not be indexed properly).
Versioning info:
c_cpp_properties.json
{
"configurations": [
{
"name": "IAR",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compilerPath": "C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.1/arm/bin/iccarm.exe",
"includePath": [
"${workspaceFolder}/",
//lots of paths, only in the workspace and the C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.1/ subdirectories
],
"defines": [
//lots of defines
]
}
],
"version": 4
}
Debug output
workspace/didChangeConfiguration
IntelliSense Engine = Default.
Autocomplete is enabled.
Error squiggles are enabled.
File exclude: **/.git
File exclude: **/.svn
File exclude: **/.hg
File exclude: **/CVS
File exclude: **/.DS_Store
File exclude: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/**
File exclude: C:/PROGRAM FILES (X86)/WINDOWS KITS/**
File exclude: **/.vscode
Search exclude: **/node_modules
Search exclude: **/bower_components
Search exclude: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/**
Search exclude: C:/PROGRAM FILES (X86)/WINDOWS KITS/**
Search exclude: **/.vscode
cpptools/queryCompilerDefaults
Attempting to get defaults from compiler found on the machine: 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx64/x64/cl.exe'
cpptools/didChangeFolderSettings
Attempting to get defaults from compiler in "compilerPath" property: 'C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.1/arm/bin/iccarm.exe'
Command line error: Unexpected command line arguments:
-Wp,-v
-E
-xc
-dD
-x
Attempting to get defaults from compiler found on the machine: C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\arm\bin\iccarm.exe
Command line error: Unexpected command line arguments:
-Wp,-v
-E
-xc
-dD
-x
Code browsing service initialized
Attempting to get defaults from compiler in "compilerPath" property: 'C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.1/arm/bin/iccarm.exe'
Command line error: Unexpected command line arguments:
-Wp,-v
-E
-xc
-dD
-x
Attempting to get defaults from compiler found on the machine: C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\arm\bin\iccarm.exe
Command line error: Unexpected command line arguments:
-Wp,-v
-E
-xc
-dD
-x
Folder: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2017/COMMUNITY/VC/TOOLS/MSVC/14.11.25503/INCLUDE/* will be indexed
Folder: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2017/COMMUNITY/VC/TOOLS/MSVC/14.11.25503/ATLMFC/INCLUDE/* will be indexed
Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.15063.0/UM/ will be indexed
Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.15063.0/UCRT/ will be indexed
Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.15063.0/SHARED/ will be indexed
Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.15063.0/WINRT/ will be indexed
MY WORKSPACE FOLDER PATH IS HERE
Folder: C:/PROGRAM FILES (X86)/IAR SYSTEMS/EMBEDDED WORKBENCH 8.1/ARM/INC// will be indexed
etc etc etc indexing files 7000+ lines blah blah
Please let me know how I can help you help me!
Did some more searching in the Issues and found 2192. Looks similar to my issue, however how can you exclude whole folders?
Issue 1976 is similar as well. However, I have
"C_Cpp.default.compilerPath": "C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.1/arm/bin/iccarm.exe",
in my settings.json file. This doesn't seem to resolve my issue.
It looks like the extension not able to handle the output from the compiler and then falling back to clang?
The trouble is that your compiler isn't queryable in the same way that GCC-related compilers are, so the extension is unable to determine your system include path. Instead, the extension is finding cl.exe and using the system includes from your Visual Studio/Windows SDK installation instead.
Does your compiler support querying the system includes path and defines?
Unfortunately, I don't think so. I have sent a question to IAR for help. If there was a way to query, can I force the extension to use arguments and take in paths it suggests? I could create a wrapper .exe and fake the output to be more like gcc.
Otherwise, is there any way to prevent the indexing of those paths (other than removing them)?
If you set "compilerPath": "", the extension will not try to guess system include paths. You can then add the relevant system include paths to "includePath".
If you set "compilerPath": "", the extension will not try to guess system include paths. You can then add the relevant system include paths to "includePath".
Woot! Leaving "compilerPath" empty did the trick! It seems Go To Definition is now going to the correct file and the index paths from the Debug output are only indexing stuff from my "includePath".
I'm good now, thank you for the help! Was/is/should there be to documentation about what might be automatically included and how to prevent adding paths with the blank "compilerPath"? That might help me and others in the future. Thanks again!
Yes, there should be documentation on this, but there wasn't. I updated: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/c_cpp_properties.json.md
@jbuckAI @bobbrow
I have the similar issue, I already set the "compilerPath": "" , but Go To Definition still finds 5 definitions, the last one in IAR complier directory is what I need, but the others header files are located in cygwin64 folder. How to exclude cygwin64 folder?

"configurations": [
{
"name": "IAR",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../Config/exec/arm/inc/c",
"${workspaceFolder}/../Config/exec/arm/inc/cpp"
],
"defines": [
"CPU_S32K146",
"__ICCARM__"
],
"compilerPath": "",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
The extension should be removing those paths after you set the compilerPath to "". If you run the "Reset IntelliSense Database" command, does it fix the problem? If not, can you please open a new issue for this?
The extension should be removing those paths after you set the
compilerPathto "". If you run the "Reset IntelliSense Database" command, does it fix the problem? If not, can you please open a new issue for this?
"Reset IntelliSense Database" command can fix the problem, thank you for the help.
Most helpful comment
If you set
"compilerPath": "", the extension will not try to guess system include paths. You can then add the relevant system include paths to"includePath".