Can I get the event for code completion?
Answered
Hello,
I have a question for code completion.
I have some live templates using DefaultLiveTemplatesProvider and templateSet xml files, and I want to post a http request when templates code completion. But I can't find a way to do this http request.
Is there a way to get the event when code completion?
Sincerely,
Lianjia Ide
Please sign in to leave a comment.
Template invoked: com.intellij.codeInsight.template.TemplateManager#TEMPLATE_STARTED_TOPIC
Lookup invoked: com.intellij.codeInsight.lookup.LookupManagerListener#TOPIC
also com.intellij.codeInsight.template.TemplateManager#startTemplate(com.intellij.openapi.editor.Editor, com.intellij.codeInsight.template.Template, com.intellij.codeInsight.template.TemplateEditingListener) allows TemplateEditingListener with more detailed callbacks
Thank you for you reply, Yann!
But it seems doesn't work for me. I register a defaultLiveTemplatesProvider in plugin.xml,
code fo MyTemplateProvider:
I can't get instance of TemplateManager in my code because no project found.
So ,what can I do now? Is there any way to replace defaultLiveTemplatesProvider by using TemplateManager?
Sincerely,
Lianjia Ide
Did you try registering listeners for either of these?
Template invoked: com.intellij.codeInsight.template.TemplateManager#TEMPLATE_STARTED_TOPIC
Lookup invoked: com.intellij.codeInsight.lookup.LookupManagerListener#TOPIC
---
You could also check variant com.intellij.codeInsight.template.CustomLiveTemplate. Or use plain com.intellij.codeInsight.completion.CompletionContributor to produce variants in template and then use com.intellij.codeInsight.completion.InsertHandler for post-completion action.
Thank you for you reply, Yann!
I'm new to plugin development, and I've tried hard but really don't know how to register those listeners in my code.
My code is showed on previous comments, code completion is done by defaultLiveTemplatesProvider.
Only two functions are used in defaultLiveTemplatesProvider, how can I register listeners?
---
CustomLiveTemplate seems to be a little hard for me, is there any example to load xml templates by CustomLiveTemplate?
(I have hundreds of live templates and do not want to create it in java code one by one).
Sincerely,
Lianjia Ide
Listeners are registered in plugin.xml https://plugins.jetbrains.com/docs/intellij/plugin-listeners.html