Dynamic registration of (version-based) live templates groups

Answered

I am trying to build a live template plugin for our framework's SDK. The thing is, these templates can differ between SDK versions, e.g. v1.0 can have different API for a button than v2.0. I managed to create a settings so that user can pick the version he likes:

The question is, how to accomplish dynamic live template registration based on the value provided. One way to do this would be using DefaultLiveTemplatesProvider and deal with registration logic there, but unfortunately, it is deprecated as of today in favor of

 <defaultLiveTemplates file="path/to/liveTemplate"/>

which is static and does not provide enough flexibility.

One possible solution I could come up with would be to make a custom TemplateContextType for each version and activate it based on current settings. This should work, but does not seem ideal. Any ideas on how to dynamically register live templates?

 

4 comments
Comment actions Permalink

DefaultLiveTemplatesProvider would still provide a static list of templates, regardless of current project/environment.

AFAIU solution with TemplateContextType per version is probably the best indeed.

0
Comment actions Permalink

Thanks Yann.

> DefaultLiveTemplatesProvider would still provide a static list of templates, regardless of current project/environment.

Correct, however, I got it working more or less how I want with required IDE restart.

> AFAIU solution with TemplateContextType per version is probably the best indeed.
Thanks, will move with that one then.

0
Comment actions Permalink

Is it possible to add a custom string (in my case version) to the value attribute and access it later in my template?

<template ....>
<variable .../>
<context>
<option name="MyContext" value="true"/>
</context>
</template>

By looking at the exported templates, it seems like "true" is always used.

Sub-question: Can I somehow access currently processed LiveTemplate metadata from within isInContext in my TemplateContextType?

I am trying to avoid having multiple TemplateContextTypes (per each version) and have just a single one instead.

0
Comment actions Permalink

That seems not possible. This just stores applicable Context Types (one <option> tag for each)

0

Please sign in to leave a comment.