aemide / issue-tracker

0 stars 0 forks source link

Completion for template files is not working #8

Open NicolasCW opened 1 month ago

NicolasCW commented 1 month ago

It is not possible to use completion for template files. This is a disadvantage when using a lot of templates in the html of components.

Approval.java

String getDateApproval() {
  return "12-12-2012";
}

approval.html

<sly data-sly-use.model="com.aem.ide.test.Approval"
     data-sly-use.commonTemplate="templates/commonTemplate.html"
>
<sly  data-sly-call="${commonTemplate.itemtemplate @ item = model}"></sly>

commonTemplate.html

<template data-sly-template.itemtemplate="${@ item = 'item'}">
  ${item.dateApproval}
</template>

In the file commonTemplate.html, the completion is not working.

karollewandowski commented 1 month ago

Thank you for reporting the issue.

Unfortunately, this is not a trivial problem. In theory, we could check the template calls and determine the param type by values passed to these calls. However, templates are usually implemented first, and there are no calls at this moment, so we wouldn't be able to determine the type.

A better, IMHO, solution would be to add information about the type in the parameter hint, for example:

<template data-sly-template.itemtemplate="${@ item='com.example.Approval'}">
  ${item.dateApproval}
</template>

The problem is that this custom solution ties the code with the plugin, and some programmers may be against it. Also, there must be a way to make it compatible with usual hints, for example:

<template data-sly-template.itemtemplate="${@ item='Approval item'}">
  ${item.dateApproval}
</template>

A solution to this would be to parse any non-simple (with package) class name and assume the first found class name is the required type, for example:

<template data-sly-template.itemtemplate="${@ item='Approval item. Must be of com.example.Approval type.'}">
  ${item.dateApproval}
</template>

The problem would appear if there were two class names and the second would be the param class name, for example:

<template data-sly-template.itemtemplate="${@ item='Approval item returned from com.example.Project.getApproval(). Must be of com.example.Approval type.'}">
  ${item.dateApproval}
</template>

To solve this, it should be possible to point the type explicitly, for example, by wrapping it into brackets:

<template data-sly-template.itemtemplate="${@ item='Approval item returned from com.example.Project.getApproval(). Must be of [com.example.Approval] type.'}">
  ${item.dateApproval}
</template>

What do you think? I also encourage others to comment.

NicolasCW commented 1 month ago

The first solution seems to be ok for me. The plugin will try to bind the template with the class in comment and not if it's impossible to find the class, and so in that last cast, it will be the same as now.

karollewandowski commented 4 weeks ago

I think that we should go with mixing two solutions:

garthbongers commented 4 weeks ago

This would be great, and is a feature I would use constantly! I think the mixing of these two solutions would provide great flexibility.