One more thing needs to be done though: the clang_completer.py file needs to not
trigger at all when YCM has been compiled without cpp support. FIX THAT!
This was intended to show the full clang output for a given diagnostic,
including notes. But it appears that libclang does not provide this
functionality...
The vim-notes plugin adds 'longest' to completeopt in its filetype plugin. This
breaks ycm. The result is that the user can't type at all after a notes file has
been visited.
We work around this by setting our completeopt settings on every buffer visit
and CursorHold event.
If the user had code like "foo.bar" and then entered insert mode after the 'r'
in "bar", YCM would cause vim to hang.
The problem happened because a sorting task was created that would try to sort
on the latest clang result but none would be created because a clang task was
not created in this occasion. clang_data_ready_ would remain false and would
never be set to true, thus causing an infinite loop in SortingThreadMain since
the thread would forever wait on the mutex.
This was rectified with better handling of the clang results cache. Now the
cache is a full class and it also stores the line & column number of the
location for which the results were computed. Better logic is in place for the
cache invalidation.
The problem was caused by a race condition of all things. ClangCompleter would
set possibly_completions_ready when starting the first parse pass for the file
and then would try to extract diagnostics for the file before the diagnostics
were done. Technically this was not a problem because only an empty diagnostics
vector would be returned, but this triggered Syntastic because hey, we have some
diagnostics to show (even though we don't).
And then Syntastic would try to close the location list window during startup
when this operation is not available. Technically it's Syntastic's fault, but a
more principled way to check for done diagnostics is to return and use a future
for file parsing operations and this solution also works around the Syntastic
issue.
On rare occasions a bug can occur where the user is trying to type text but the
completion system is erasing it as he types. I believe this new approach should
fix that problem. It also replaces the old system for preventing an infinite
loop to occur when there are no completions to show to the user.
This change should fix the random hangs and segfaults when using the clang
completer. Also, assertion errors printed to the console on vim exit should go
away too, same thing with segfaults on vim exit. These "on exit" errors were
caused by not cleanly shutting down the background threads; both the identifier
completer and the clang one now join the threads on destruction. This results in
a clean shutdown.
The new clang completer architecture now uses only one clang thread (again)
instead of a completion and parsing thread. Since the parsing task needs to wait
on the completion task if it was started first (and vice-versa) there's no point
to using two threads. The desired "simplicity" of using two threads for these
two tasks actually created needless complexity (and bugs). Sigh. Such is life.
A TranslationUnit abstraction was also created and this in turn also reduces the
complexity of the clang completer.
The clang completer now also has some (very) basic tests.
The user can opt-out of this, but we set it by default since most people don't
know that the option exists. Those that are annoyed by it can just toggle an
option in their vimrc.