microsoft / VSExtensibility

A repo for upcoming changes to extensibility in Visual Studio, the new extensibility model, and language server protocol.
MIT License
370 stars 48 forks source link

Unable to Show Shortcut/KeyBinding of Command in Menu #414

Open joshdavidson613 opened 2 months ago

joshdavidson613 commented 2 months ago

Hi all, really like what you are trying to do here. Quick question. I was able to get CommandConfiguration object working with KeyBinding/Shortcut:

public override CommandConfiguration CommandConfiguration => new("MyExtension.Command1.DisplayName")
  {
      // Use this object initializer to set optional parameters for the command. The required parameter,
      // displayName, is set above. DisplayName is localized and references an entry in .vsextension\string-resources.json.
      //Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu],
      Icon = new (ImageMoniker.KnownValues.FieldInternal, IconSettings.IconAndText),
      Shortcuts = new[]
      {
          new CommandShortcutConfiguration(ModifierKey.LeftAlt, Key.C, ModifierKey.LeftAlt,  Key.VK_OEM_COMMA) 
      }
  };

My question is there doesn't seem to be a way to show the Keybindings/Shortcut in the menu, either in the MenuConfiguration that has the command or the ComandConfiguration of the command.

Am I missing something, or is this just not yet implemented?

joshdavidson613 commented 2 months ago

Ok, I can now report a bug. As you can see in the above comment, the Placements property is commented out. That is because I set the Command as a sub-menu item in ExetnsionsEntrypoint.cs:

[VisualStudioContribution]
public static MenuConfiguration CommentScribeExtensionMenu => new MenuConfiguration("MyCommands")
{
    Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
    Children = new MenuChild[]
    {
        MenuChild.Command<Command1>(),
        MenuChild.Command<Command2>()
    },
};

In this configuration, no Shortcuts/Keybindings are shown.

However, if I remove the Commands from this config, and use the Placements property on the command itself, the individual menu item shows up with Shortcuts/Keybindings.

Thuse the bug is this:

Commands that have direct placement show the shortcuts/keybindings. Commands are are Children in other MenuConfiguration items do not show shortcuts/keybindings.

Expected behavior:

Commands in menu items, no matter how placed, will always show shortcuts/keybindings.