Skip to content

Add reflection to the ActionArgs in the settings model #18915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

PankajBhojwani
Copy link
Contributor

@PankajBhojwani PankajBhojwani commented May 14, 2025

Summary of the Pull Request

Implements reflection to the various ActionArg types in the settings model, which allows these structs to provide information about themselves (i.e. what args they contain and what types they are). This is necessary as a pre-requisite for the Settings Editor to display and modify these arg values.

Detailed Description of the Pull Request / Additional comments

  • The IActionArgs interface now has additional methods:
    • Get the number of args
    • Get/Set an arg at a specific index
    • Get the arg description of an arg at a specific index; the arg description contains:
      • name of the arg
      • type of the arg
      • whether the arg is required
      • a tag, this is to cover special cases (for example the ColorScheme argument is technically of type "string", but only allows specific values)
  • All the macros in ActionArgsMagic have been updated to support the new interface
  • ActionMap has been updated to support adding/editing/deleting actions and keybindings from outside the SettingsModel
    • It now also tracks for ID changes to commands and updates accordingly
  • Command has been updated to allow setting its values from outside the SettingsModel
  • EnumMappings have been added to various ActionArg enums that weren't there before

Validation Steps Performed

Bug bashed in conjunction with #18917

PR Checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated
    • If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated (if necessary)

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 15, 2025
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 16, 2025
@@ -757,6 +838,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
AddAction(*cmd, keys);
}

void ActionMap::DeleteUserCommand(const winrt::hstring& cmdID)
{
_ActionMap.erase(cmdID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ActionMap.erase(cmdID);
_ActionMap.erase(cmdID);
_changeLog.emplace(IDKey)

This one I'm iffy on, so I want to discuss here.

Currently, there isn't a place where we're tracking if a user added an ID. In the JSON, the user would be using "id" in two cases for Action Map:

  1. create a new action in the "actions" block (i.e. {"command": "terminalChat", "id": "User.terminalChat"})
    • That's fine? We care about action arg usage and that's already being handled.
  2. create a key binding in the "keybindings"block (i.e. {"id": "User.terminalChat", "keys": "ctrl+?})
    • That's fine too. We care about "keys" usage and that's already being handled.

(related: "id" is used in the new tab menu, but we're just tracking "action" there which is sufficient)

Long-term, however, we want _changeLog to be a way for us to know if the user changed anything. So maybe we do want to apply the code suggestion and update case 1 to add "id" too? Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is tough because I imagine most users won't be actually adding their own IDs - it will just be autogenerated for them. So distinguishing between us generating an ID for them vs an ID they added or changed is... tricky

@PankajBhojwani PankajBhojwani marked this pull request as ready for review June 3, 2025 21:20
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Really just blocking over the missing SaveSnippet name in the map (the other two are a question and a suggestion). Nice work!

I'll come back and approve when that SaveSnippet comment gets resolved. I'll have to come back and approve it anyways haha.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 4, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Jun 12, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. labels Jun 13, 2025
_##name{ name##Param },

#define ARGDESC_STRINGIFY2(x) #x

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

ARGDESC is not a recognized word. (unrecognized-spelling)
_##name{ name##Param },

#define ARGDESC_STRINGIFY2(x) #x
#define ARGDESC_STRINGIFY(x) ARGDESC_STRINGIFY2(x)

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

ARGDESC is not a recognized word. (unrecognized-spelling)
_##name{ name##Param },

#define ARGDESC_STRINGIFY2(x) #x
#define ARGDESC_STRINGIFY(x) ARGDESC_STRINGIFY2(x)

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

ARGDESC is not a recognized word. (unrecognized-spelling)
_##name{ name##Param },

#define ARGDESC_STRINGIFY2(x) #x
#define ARGDESC_STRINGIFY(x) ARGDESC_STRINGIFY2(x)
#define ARGDESC_WIDEN2(x) L##x

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

ARGDESC is not a recognized word. (unrecognized-spelling)
#define ARGDESC_STRINGIFY2(x) #x
#define ARGDESC_STRINGIFY(x) ARGDESC_STRINGIFY2(x)
#define ARGDESC_WIDEN2(x) L##x
#define ARGDESC_WIDEN(x) ARGDESC_WIDEN2(x)

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

ARGDESC is not a recognized word. (unrecognized-spelling)
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

Unrecognized words (1)

ARGDESC

These words are not needed and should be removed abcd ABCDEFGHIJ abcdefghijk ABCDEFGHIJKLMNOPQRS ABCDEFGHIJKLMNOPQRST ABCDEFGHIJKLMNOPQRSTUVWXY allocs appium Argb asan autocrlf backported bytebuffer cac CLE codenav codepath commandline COMMITID componentization constness dealloc deserializers DISPATCHNOTIFY DTest entrypoints EVENTID FINDUP foob fuzzer fuzzyfinder hlocal hstring IInput Interner keyscan lstrcmpi Munged numlock offboarded oob pids positionals Productize pseudoterminal remoting renamer roadmap ruleset SELECTALL somefile Stringable tearoff TODOs touchpad TREX Unregistering USERDATA vectorize viewports wsl

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the dev/pabhoj/settings_model_reflection branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.24/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/15788667390/attempts/1'
Errors (1)

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ ignored-expect-variant 3

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants