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

5 comments
Comment actions Permalink

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

1
Comment actions Permalink

Thank you for you reply, Yann!

But it seems doesn't work for me. I register a defaultLiveTemplatesProvider in plugin.xml,

<extensions defaultExtensionNs="com.intellij">
<defaultLiveTemplatesProvider implementation="com.lianjia.ide.liveTemplate.MyTemplateProvider"/>
</extensions>

code fo MyTemplateProvider:

public class MyTemplateProvider implements DefaultLiveTemplatesProvider {

@Override
public String[] getDefaultLiveTemplateFiles() {
return new String[]{
"templates/flutter_template_file",
};
}

@Nullable
@Override
public String[] getHiddenLiveTemplateFiles() {
return new String[0];
}
}

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

0
Comment actions Permalink

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.

0
Comment actions Permalink

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

0

Please sign in to leave a comment.