xavierd / clang_complete

Vim plugin that use clang for completing C/C++ code.
http://www.vim.org/scripts/script.php?script_id=3302
1.96k stars 308 forks source link

CMake / compile_commands.json / Qt / Windows not working #572

Closed zeechs closed 4 years ago

zeechs commented 4 years ago

Hello,

This issue is about the combo CMake and Qt on Windows but this does not mean that clang_complete works for me with other configurations. This is my only setup, because this is what I work with all the time.

Software I use

Here is my simple clang_complete config, in vimrc:

let g:clang_library_path='C:\dev\tools\llvm\llvm9_32\bin'
let g:clang_use_library = 1

I created a CMake project for Qt:

#include <QApplication>
#include <QWidget>
#include <iostream>

int main (int argc, char* argv[])
{
    QApplication app(argc, argv);

    QWidget win;
    win.show();

    return app.exec();
}

and I asked CMake to export the compile commands. Here is what I get:

[
{
  "directory": "C:/dev/projects/myapp/_build",
  "command": "C:\\dev\\tools\\qt\\Tools\\mingw730_32\\bin\\g++.exe  -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB @CMakeFiles/MyApp.dir/includes_CXX.rsp   -o CMakeFiles\\MyApp.dir\\main.cpp.obj -c C:\\dev\\projects\\myapp\\main.cpp",
  "file": "C:/dev/projects/myapp/main.cpp"
}
]

Seeing the argument @CMakeFiles/MyApp.dir/includes_CXX.rsp, it seems that the includes are pulled from that file. Here is the content of the file includes_CXX.rsp:

-isystem C:/dev/tools/qt/5.13.1/mingw73_32/include -isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtCore -isystem C:/dev/tools/qt/5.13.1/mingw73_32/./mkspecs/win32-g++ -isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtWidgets -isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtGui -isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtANGLE 

It all looks straight and clean to me but I do not get any suggestion from clang_complete. For instance, typing app. or QApplication:: orstd:: triggers the display of the message-- User defined completion (^U^N^P) Pattern not found`.

:set omnifunc? returns omnifunc=ClangComplete :set completefunc? returns completefunc=ClangComplete

So question 1: Does clang_complete, or libclang understands the argument @CMakeFiles/MyApp.dir/includes_CXX.rsp in a compile_command.json g++ command? If the answer is no, I already tried to manually replace this argument with the content of the rsp file with no better result.

Question 2: Beside from trying do guess what is wrong in a setup, how do you investigate efficently?

Edit: I got it working partially by manually copying the include instructions from the rsp file to a .clang_complete file like so:

-isystem C:/dev/tools/qt/5.13.1/mingw73_32/include
-isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtCore
-isystem C:/dev/tools/qt/5.13.1/mingw73_32/./mkspecs/win32-g++
-isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtWidgets
-isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtGui
-isystem C:/dev/tools/qt/5.13.1/mingw73_32/include/QtANGLE 

It now provides suggestion for the Qt library. However this is far from being ideal due to the manual intervention required. Also it still does not work for the standard library.

zeechs commented 4 years ago

This is a Clang issue, not clang_complete, closing.