How to provide description to enum's items in Live Template?
Answered
Hello, this is my first question in intelliJ community!
I am developing a plugin which provides custom Live Template.
Is it possible for each item of a enum variable in Live Template to show a TailText or Quick Definition, like LookupElements of CompletionProvider offers?
If there is any functionality similar to the above picture in Live Template,
please let me know.
I hope the user can check the keyword's description or definition.
Thank you.
Please sign in to leave a comment.
Hi,
Please provide more information. How do you invoke your live templates? Do you want to use it in the commit message window? Is completion invoked for live template placeholders? If yes, did you try adding tail text to lookup items? Regarding quick definition, did you see https://plugins.jetbrains.com/docs/intellij/documentation.html?
Thank you Karol
for letting me know what information was absent before!
1. I am invoking my live template from .xml, refering to https://github.com/JetBrains/intellij-sdk-code-samples/tree/main/live_templates/src/main/java/org/intellij/sdk/liveTemplates
2. Yes, I want to provide my live template to the users of my plugin in the commit message window.
3. The completion in the first picture is just for reference. I want to make the user fill the placeholder with enum variable. And I hope for the user to get the information or hint while hovering or selecting items.
4. I have read the documentation you mentioned. Also I have implemented auto-completion and tailText for LookupElements. But I don't know these features are applicable to the items of “enum” in Live Template.
I want to offer these functionalities.
1. Editing commit message with my Live Template, the user should choose one among pre-defined items.
2. The user can get the information about each of items.
Regarding these two requirements, what approach will be available?
Hi,
Thank you for clarifications.
It seems like you want to implement something similar to https://github.com/lppedd/idea-conventional-commit. I suggest checking the project implementation. At first sight, you will need to implement a language for your commit format and implement completion and documentation provider for this language's elements.
Oh! I'll refer to the project you mentioned.
This is my last question.
Is there no way to provide any kind of hint or description to an user, while the user is selecting an item from the dropdown which contains multiple items of an enum variable in Live Template?
I missed the “enum” meaning before. I didn't know there is “enum” expression for live template variables.
Completion values for enum() are created by this extension: https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/codeInsight/template/macro/EnumMacro.java. I don't see any possibility of changing the presentation.
You can write your own macro which will complete enum values with your custom presentation and use it instead of enum() in the template definition.