Recently I am using clang_complete
to do C++ code completion. It is good and fast for small program but too slow for my case (I am working on large code base and usually one file takes several seconds to compile), even if I used libclang, which can cache some parsed results to speedup later parsing, if I understand correctly.
Currently clang_complete
will block in ClangComplete
until libclang
finishes parsing. Even though it starts a worker thread, main thread still repeatedly checks if user pressed CTRLC or the worker thread completes successfully. During this period, vim becomes irresponsive and thus makes this plugin hard to use.
I want to make some improvement to this behavior, for example, ClangComplete
will not block, but return empty results if it takes longer than 0.2 seconds, while the thread is still running. When libclang finishes its parsing, and it detects that I am still typing the same completion word, it will popup a completion menu.
The difficulties for this is:
- how to popup a menu at that time, without causing some subtle race conditions between different threads,
- how does it know whether I am still typing the same completion word? I think vim itself keep track of this, because when I type something wrong, for example,
std::strang
instead ofstd::string
, then I type backspace to delete the wrongang
, the completion menu will show up again. So how do I access to this internal flag?