Asynchronous code completion for clang_complete

I recently use clang_complete to complete C ++ code. This is good and fast for a small program, but too slow for my case (I work on a large code base, and usually one file takes a few seconds to compile), even if I used libclang, which can cache some of the analyzed results to speed up the subsequent parsing, if I understood correctly.

Currently, clang_complete will block in ClangComplete until libclang has finished parsing. Although it starts the workflow, the main thread still checks if the user pressed CTRL C or the workflow completed successfully. During this period, vim becomes irresponsible and thus makes this plugin difficult to use.

I want to improve this behavior a bit, for example, ClangComplete will not block, but return empty results if it takes more than 0.2 seconds while the thread is still running. When libclang finishes disassembling it, and it discovers that I am still typing the same termination word, it will display the termination menu.

Difficulties for this:

  • how to pop up a menu at that time without causing any subtle race conditions between different streams,
  • how does he know if i am all typing the same word of completion? I think vim itself tracks this, because when I print something wrong, for example, std::strang instead of std::string , then I type backspace to remove the wrong ang , the completion menu will appear again. So how do I access this inner flag?
+6
source share
1 answer
  • Vimscript is single threaded; You don’t have to worry about racing.

  • Vim will pass the base (i.e. the part of the termination word already entered / completed) to your function. Check out :help complete-functions for more details and an example.

In general, your approach (assuming you are using an embedded language such as Python or Perl for multithreading) should be feasible; however, I have not seen anything like it yet.

0
source

Source: https://habr.com/ru/post/907151/


All Articles