Skip to content

Template architecture design #4549

Open
@bclothier

Description

@bclothier

Task list (see below for discussion):

  • Migrate all hard-coded code templates to template system (e.g. test module/test method)
  • Create a setting pane for viewing/customizing templates
  • Provide a versioning system for built-in templates to aid in graceful update of the built-in templates without losing users' customizations
  • Create a macro system for template (simple text substitution)
  • Provide validation of template with macros (?)
  • Provide preview dialog (?)

With PR #4225 we introduced the foundation for the template subsystem. Only the minimal work was done to get in for the PR, but the next release should make it a more systematic approach for how we should handle all kinds of code templates.

For example, right now, the test modules and methods are just hard-coded inside the codebase, which kinds of hampers the ability to customize the method. The template subsystem is meant to enable this. However, there are few items to consider in the architecture so comments or ideas are welcome.

First of all, the template subsystem is designed to handle both built-in and user-defined templates. The difference is based on whether the templates has a corresponding entry in its dedicated Template.resx resource file. The built-in templates exist primarily to ensure that Rubberduck won't blow up if the template go missing; it'll just use the default ones stored inside the resource file. But the users would be able to customize the built-in templates if they choose to which brings me to the next point.

The templates are stored as a .rdt (Rubberduck Template) files stored in %APPDATA%\Rubberduck\Templates. In principle, users can edit those -- they're just plain text file fit for direct import into VB* codebase. Currently there is no macro system, and it's very likely that one will be if users would be able to parameterize the template at runtime. The test methods will likely need one anyway in order to provide a placeholder for the procedure name.

But macros are not as useful if there's no decent UI for creating/editing/deleting templates. The settings dialog most likely needs a new section dedicated to templates. That way, users can preview the template and if they customize it, we can help with validating the template.

The Template class likely will need a new property bool HasDedicatedCommand or something similar to ensure that built-in templates do not get exposed via the Template submenu, since the test module/test method has their own dedicated commands, avoiding duplicating the templates in the Template submenu.

For VB6, I understand that it's very common to have a bunch of templates. Some research will be needed in seeing how to leverage the template system and thus provide a easy way of exposing those templates when using RD inside VB6. I also understand that normally those have their popup form. It's not clear if those involve additional inputs from the users beside the selection of a template but in case it does, we might need to consider a popup dialog to support that. That would also allow for previewing with marcos resolved.

I also did not like that we had to use submenu. I originally wanted it on a flat menu (with separators) but unfortunately, XAML did not make it easy to provide appropriate styling for static parts and dynamic parts separately. If anyone can do this, they're more than welcome to make a PR.

If there's something else missing, share it here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty-02-duckyResolving these involves the internal API, but with relatively easy problems to solve.discussionfeature-settingsfeature-templatesup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-duckyvb6-supportwork-itemUsed for features not implemented to document requirements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions