Add support for -iframework in compile_commands.json (Intellisense stopped working for Qt libraries on Mac only)
Type: LanguageService
Describe the bug
- OS and Version: Mac 10.15 Catalina
- VS Code Version: 1.41
- C/C++ Extension Version: All recent versions (tried multiple)
- Other extensions you installed (and if the issue persists after disabling them): Cmake Tools - persists on disabling
- A clear and concise description of what the bug is.
It seems cpptools intellisense engine has stopped working for Qt types (at least for me). It works fine with the same config on Linux. The problem seems concentrated around finding Qt includes...
To Reproduce
Install Qt open source library under Mac - placed in ~/Qt. Configure CMakeLists.txt to correctly include required libraries and headers (see simple GUI project here). I added the Qt include directories with include_directories (Qt5Core_INCLUDE_DIRS, Qt5Widgets_INCLUDE_DIRS, etc). Point c_cpp_properties to the correct clang compiler and compile_commands.json file (make sure generating compile_commands to specified location). Here is mine:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
Basically any header include which has a Qt type somewhere gets a red squiggle, and all Qt types receive no autocomplete suggestions. When I first installed vscode and the extension on Mac, it was working to complete Qt types fine with the above config. Then something happened and it stopped working - unfortunately I don't know what exactly as this is a new iMac and I have been installing software and updates continually. I do know that the OS was updated to Catalina, but it seems it was working after that update and restart.
Things I have tried
Adding Qt include directories under includePath - both individually and adding all of them as a top level glob ** (I am confused on the necessity of includePath when compile_commands is included in general - is it used in this case?)
Completely reinstalling vscode (deleting all config files in global .vscode) and starting from scratch with the extension.
Installing different versions of cpptools with auto update extensions turned off.
Moving compile commands around to different locations and updating the location in c_cpp_properties.
Using clang compiler included with XCode (turns out it is same exact one as installed by homebrew anyways)
Setting intellisense include backup behavior to use tags - this causes the red squiggles to change to blue, and most Qt types then have auto-completion available however the context for the completion is not correct
Expected behavior
I would expect intellisense actions to work correctly with Qt. The project compiles with cmake_tools and clang 11 with no problems.
I will also note that as a backup I have cquery installed (brew install cquery), and if I disable the language server in settings, enable the cquery extension and reload vscode, cquery has no trouble finding any of the types, includes, or type completions based on my compile_commands.json. This tells me either I have something configured incorrectly for cpptools, or there is a bug somewhere.
Thanks
For the 1st issue, it looks like we would obtain the frameworks from querying the compilerPath/compilerArgs from CMake Tools and they don't send us that info directly, but the compiler may not be labeling the -iframework with "(framework directory)" like it does with the MacOSX.sdk framework (but it looks like gcc might be outputing the framework with that text, unlike clang, because we correctly recognize it as a framework in that case, from your logs). So it looks like another bug.
For the 2nd issue, it sounds like setting the CMake.configureOnOpen setting would fix that.
@bobbrow Can you think of any workaround? (Maybe switch to using -framework or -F someone in the compile commands) Any idea why we haven't gotten other reports like this yet?
UPDATE: Looks like we handle -iframework as an arg correctly (it does output "framework directory"), maybe CMake Tools isn't passing that as a compilerArg when the clang kit is used for some reason.
Also, fixing https://github.com/microsoft/vscode-cpptools/issues/1755 would fix this as well, since we correctly respond to "-iframework" when it's a compilerArg -- so a potential workaround is to set your compilerPath to something like "/usr/bin/clang++ -iframework /Users/dprandle/Qt/5.12.6/clang_64/lib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fPIC". If that doesn't work, there could be additional issues.
Success! The only compiler arg that's necessary for IntelliSense to work correctly (I tried including/not including all shown above) to include is the -iframework pointing to the Qt lib. I'm guessing this would be true of any other 3rd part framework one would want to use in VSCode. As you mentioned earlier - I think IntelliSense is not recognizing the -iframework arg in compile_commands.json, but when you expressly list it as an arg it correctly handles it. Here is my log diagnostics with IntelliSense working correctly
-------- Diagnostics - 1/11/2020, 3:07:10 PM
Version: 0.26.3-insiders3
Current Configuration:
{
"name": "Mac",
"compilerPath": "/usr/bin/clang++",
"compilerArgs": [
"-iframework",
"/Users/dprandle/Qt/5.12.6/clang_64/lib"
],
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"browse": {
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[ /Users/dprandle/Documents/Code/Uber_Mail/src/dialog_create_payroll.cpp ]:
/Users/dprandle/Documents/Code/Uber_Mail/src/dialog_create_payroll.cpp
Translation Unit Configurations:
[ /Users/dprandle/Documents/Code/Uber_Mail/src/dialog_create_payroll.cpp ]:
Process ID: 1662
Memory Usage: 207 MB
Compiler Path: /usr/bin/clang++
Includes:
/Users/dprandle/Documents/Code/Uber_Mail/build/Debug
/Users/dprandle/Documents/Code/Uber_Mail
/Users/dprandle/Documents/Code/Uber_Mail/include
/Users/dprandle/Documents/Code/Uber_Mail/build/Debug/include
/usr/local/Cellar/[email protected]/1.1.1d/include
/Users/dprandle/Qt/5.12.6/clang_64/lib/QtCore.framework/Versions/5/Headers
/Users/dprandle/Qt/5.12.6/clang_64/mkspecs/macx-clang
/Users/dprandle/Qt/5.12.6/clang_64/lib/QtWidgets.framework/Versions/5/Headers
/Users/dprandle/Qt/5.12.6/clang_64/lib/QtGui.framework/Versions/5/Headers
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers
/Users/dprandle/Qt/5.12.6/clang_64/lib/QtNetwork.framework/Versions/5/Headers
/Users/dprandle/Qt/5.12.6/clang_64/lib/QtPrintSupport.framework/Versions/5/Headers
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
Frameworks:
/Users/dprandle/Qt/5.12.6/clang_64/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
Defines:
DEBUG_VERSION
QT_CORE_LIB
QT_GUI_LIB
QT_NETWORK_LIB
QT_PRINTSUPPORT_LIB
QT_WIDGETS_LIB
Standard Version: c++17
IntelliSense Mode: clang-x64
Other Flags:
--clang
--clang_version=110000
Total Memory Usage: 207 MB
You can see here that the Qt lib is included under frameworks where it previously was not.
Thanks for the help!
Thank you for posting such a kind review of the extension. We really appreciate it.
Our latest Insiders released added support for -iframework in compile_commands.json: https://github.com/microsoft/vscode-cpptools/releases/tag/0.27.0-insiders
Thank you! removed the above work around and seems to be working great!!!