As you may know, quite a long time ago I was working on templates DSL documentation available now in Foreman under
/templates_doc. Although one can find this useful, when it comes to wrtiting a template it’s not so pleasant to check macros in the docs everytime one forgets which arguments they have or other small stuff. To help with this I’ve implemented  autocompletion for template editor, which uses the same docs to show tooltips and autofills. I’ve recorded how looks writing
Host Statuses report template with enabled autocompletion:
- Basic autocompletion. After initial review only macros and properties are supported.
/templates_docto get macros/properties as snippets.
- Shows related information about macro, – signature, short description, examples, return value, – as a tooltip.
- Snippets also have default values set as per documentation.
- This is more editor with autocompletion than IDE, so there is no
object.suggestionspattern that would show what methods can be called on what objects, i.e. you cannot type
@host.and get only the host methods. Current workaround is that properties are shown with prefixes, so one need to type
prefix#propertyto get the snippet, e.g.
- Doesn’t check if passed value type is valid.
- Sometimes the related info is not being shown fully; probably the issue is in
acethat doesn’t consider user’s
ApipieDSL.docsis used as a documentation to get the macros from. This means: the latest changes in code/docs, english (or default lang) only, default version. We can also use stored cache or or combinations.
- Should we implement IDE-like behaviour based on return values?
NOTE: probably will require lots of js code on client side.
- How we can enhance visuals for autocompletion?
NOTE: the question is more about
whatinstead of actual
- Should we restrict snippets and show only related ones for each kind of template, i.e. in
report templateeditor show only macros from
NOTE: This can obviously reduce unrelated macros, but this needs review of all sections to ensure everything is properly scoped; probably will require some restructurations in the documentation.
All reviews, thoughts and suggestions are more than welcome to push the progress with it.
Please, feel free to write down them here or in the PR.
 - [DRAFT] Fixes #32035 - Add DSL autocompletion in templates by ofedoren · Pull Request #8385 · theforeman/foreman · GitHub