Hi,
I use EasyClangComplete plugin, where, shortly, clang is used as a tool to append any kind of completions while programming with C and C++. Very useful plugin indeed, thanks to the maintainer @niosus for having somewhen started it out
The plugin uses sublime’s python API and in particular the method ‘on_query_completion’ that is called at the time ‘auto_completion’ is requested. As I have understood every listener subscribed on ‘auto_completion’ event by deriving from ‘sublime_plugin.EventListener’ and defining method ‘on_query_completions’ is called successively to append the data in the common popup-window of completion offers
Meanwhile, I have the other plugin that contributes *.sublime-completions files
There is an issue that my completions from *.sublime-completions disappear upon plugin’s EasyClangComplete appending its own
I looked into EasyClangComplete plugin and found out the algorithm of fetching the completions and spreading them:
- ‘on_query_completions’ is called
- in the handler a new job (a thread) is spawned that is doing fetching the autocompletion list with clang specific API and utilities, it doesn’t matter. Here I like to note that the work is done in a different thread that means that the result will be ready asynchronously. As just the job is created and started working to fill the completions the main thread, which is in ‘on_query_completions’ handler, exits and returns empty list of completions which adds nothing new in the common list of completions. So, I see my default completions as is and don’t see EasyClangComplete completions as they are not ready, no issues, good
- The job we created to fill the list completions provided by clang ends its labor and gets the list of completion in the correct format, no issues. Since the main thread has already exited we need to somehow update a completion list with new stuff. So, apparently, there is nothing to do but call auto_completion feature again as though it had been called by a programmer by triggering it. The plugin does it the following way
view.run_command('hide_auto_complete')
view.run_command('auto_complete', {
'disable_auto_insert': True,
'api_completions_only': False,
'next_competion_if_showing': False})
It, again, queries all the listerners to handle ‘on_query_completions’. The plugin is elaborated so that it immediately returns already formed in the previous round completions in this handler ‘on_query_completions’, not creating any jobs or doing any other stuff. And there it is, this bug. Upon this return I cannot see my default completions from *.sublime-completions files anymore, I see only offers provided by EasyClangComplete plugin and provided my snippets. This circumstance occurs only with *.sublime-completions files as though they are ignored
My questions:
- Have you seen this before and have you had any ideas how to avoid or fix that?
- Is it legal to invoke a new job in the main thread of processing the query ‘on_query_completions’, return an empty list of completion and then, in the second thread, call ‘auto_completion’ feature from API to append the completions list by this way
view.run_command('hide_auto_complete')
view.run_command('auto_complete', {
'disable_auto_insert': True,
'api_completions_only': False,
'next_competion_if_showing': False})
?
3) If it is legal does it mean that *.sublime-completions files are ignored when I call the ‘auto_completion’ from API?
My ‘*.sublime-completions’ file look like
{
"scope": "source.c++",
"completions": [
{"trigger": "cout_\tstd::cout statement", "contents": "std::cout << "},
{"trigger": "cerr_\tstd::cerr statement", "contents": "std::cerr << "},
{"trigger": "endl_\tstd::endl statement", "contents": "std::endl"},
{"trigger": "ignunused_\tboost::ignore_unused statement", "contents": "boost::ignore_unused(${1:var});"}
]
}
Thank you