Sublime Forum

on_query_completions asynchronous ideas

#1

Hi all,

I made a semantic autocompletion plugin with the clang C++ API for ST3. However, ViewEventListener.on_query_completions can be extrmely slow sometimes, which is to be expected because it may parse a dozen header files.

How would one go about implementing this in an asynchronous way? There is ViewEventListener.on_selection_modified_async, I could perhaps use that as a starting point. However I fear that completions may not arrive “on time” for on_query_completions.

Any suggestions, pointers, or past experience would be appreciated.

0 Likes

#2

Doing time expensive stuff in on_selection_modified_async would slow ST down and won’t solve this problem. You could create the completions in a separate thread, store them, and reopen the popup.
Something similar is done at LaTeXTools cwl completions.

1 Like

#3

Could also check EasyClangComplete. It does what you are making so might look into it rather than making a new package. :slight_smile:

0 Likes

#4

@rchl I checked out EasyClangComplete; it works by making python bindings to the clang C api. The difference is that my plugin has a compiled component linked with the C++ api, and then exposing that via boost.python. I’m not sure how I would distribute that, but we’ll see. I have now put so much time into this project that I feel that I should continue now :wink:

@r-stein From the link you gave I managed to write something similar, which works “okay” for now. Thanks a lot!

0 Likes

#5

Does that mean that your plugin is platform dependent? And also needs to be recompiled for each new clang version?

By any means, continue. You are probably learning a lot during that. But it’s worth knowing of other approaches and see the upsides and downsides of each. :slight_smile:

EasyClangComplete is compatible with all platforms and uses clang’s python bindings which are created by clang developers. So supporting all platforms is easy and adding support for new clang version is a matter of bundling new bindings with the plugin. It also has second mode which executes clang binary directly.

1 Like