Skip to content

Automatically generate ShortcutAction code from ~JSON Schema~ X-Macros #3475

Closed
@zadjii-msft

Description

@zadjii-msft

While working on #3391, I felt like there was a ton of boilerplate that was needed for each and every keybindings. The thought crossed my mind that we could do better, but I wasn't sure how. In my mind, I imagined a single file that described each of the ShortcutActions and their possible args, and a small script that just automatically generated all the necessary code to parse them, their args, and hook them up to the TerminalApp.

Now that I've thought on it more, here are some of the steps that'll be needed:

  • Take code from my command palette branch for ShortcutActionDispatch. This is a class that just handles the dispatching of actions. In that branch, I needed it because both keybindings and commands needed to be able to dispatch ShortcutActions, but only AppKeyBindings needed to do a KeyChord lookup. This code being encapsulated will be necessary for a future step.
  • Add more _templated_ JsonUtils #2550 Add more templated json utils. We'll need this to be able to automagically generate the code to parse a given type from a Json::Value
  • Move the code around so that anything having to do with the entirety of the list of ShortcutActions is in single files by themselves:
    • AppKeybindingSerialization should only deal with parsing keychords. Lets put the ShortcutActions and their keys in another file
    • Add a IShortcutActionHandler interface, with _Handle{{SomeShortcutAction}}(auto&& sender, ActionArgs args) methods for each ShortcutAction. It should declare all the event handlers, but not the definitions.
    • Make TerminalPage extend IShortcutActionHandler. This will be necessary to make sure TerminalPage implements each of them.
    • That one method that hooks up the TerminalPage to the ShortcutActionDispatch. Pull that into it's own file as well.
  • Write a script that parses profiles.schema.json for each of the "*ShortcutAction" definitions, and turns them into code in all the necessary files
    • ShortcutActionKeys.h
    • ActionAndArgs.idl/.h/.cpp
    • ShortcutActionDispatch.idl/.h/.cpp
    • IShortcutActionHandler.h
    • For actions that are listed in ShortcutActions but don't have a proper Args type, then make sure that they're still dispatched correctly
    • When the number of args changes, write the above files, and display a message that the developer needs to update AppActionHandlers.cpp to add implementations for the new types.
    • Validate that all "*ShortcutAction"s listed in the schema actually show up in the onOf schema for Keybinding

Each top-level box could be it's own task here.

In the end, the developer should be able to modify the schema for add their new argument or ShortcutAction, and run a script, and the script should automatically write all the modifications necessary.

I'll probably need to do this in powershell. cmd would be impossible, and as much as I love python, I don't think that's really a part of our toolchain at all currently.

Metadata

Metadata

Assignees

Labels

Area-CodeHealthIssues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc.Issue-TaskIt's a feature request, but it doesn't really need a major design.Product-TerminalThe new Windows Terminal.Resolution-Fix-CommittedFix is checked in, but it might be 3-4 weeks until a release.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions