Hello,
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 [1] 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:
Current additions:
- Basic autocompletion. After initial review only macros and properties are supported.
- Parses
/templates_doc
to 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.
Current issues:
- This is more editor with autocompletion than IDE, so there is no
object.suggestions
pattern 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 typeprefix#property
to get the snippet, e.g.Managed#name
. - Doesn’t check if passed value type is valid.
- Sometimes the related info is not being shown fully; probably the issue is in
brace
/ace
that doesn’t consider user’sviewport
fordocTooltip
. - Internal
ApipieDSL.docs
is 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.
RFCs:
- 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 aboutwhat
instead of actualhow
. - Should we restrict snippets and show only related ones for each kind of template, i.e. in
report template
editor show only macros fromReports
section?
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.