Repository: microsoft/terminal
File: src/cascadia/TerminalApp/SuggestionsControl.cpp (C++)

Code before:
                    // to pick from.
                    _nestedActionStack.Append(filteredCommand);
                    ParentCommandName(actionPaletteItem.Command().Name());
                    _updateCurrentNestedCommands(actionPaletteItem.Command());

                    _updateUIForStackChange();
                }
                else
                {
                    // First stash the search text length, because _close will clear this.
                    const auto searchTextLength = _searchBox().Text().size();

                    // An action from the root command list has depth=0
                    const auto nestedCommandDepth = _nestedActionStack.Size();

                    // Close before we dispatch so that actions that open the command
                    // palette like the Tab Switcher will be able to have the last laugh.
                    _close();

                    // A note: the command palette ignores
                    // "ToggleCommandPalette" actions. We may want to do the
                    // same with "Suggestions" actions in the future, should we
                    // ever allow non-sendInput actions.
                    DispatchCommandRequested.raise(*this, actionPaletteItem.Command());

                    if (til::starts_with(actionPaletteItem.Command().ActionAndArgs().Args().as<SendInputArgs>().Input(), L"winget"))
                    {
                        TraceLoggingWrite(
                            g_hTerminalAppProvider,
                            "QuickFixSuggestionUsed",
                            TraceLoggingDescription("Event emitted when a winget suggestion from is used"),
                            TraceLoggingValue("SuggestionsUI", "Source"),
                            TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                            TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
                    }

                    TraceLoggingWrite(
                        g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider
                        "SuggestionsControlDispatchedAction",
                        TraceLoggingDescription("Event emitted when the user selects an action in the Command Palette"),
                        TraceLoggingUInt32(searchTextLength, "SearchTextLength", "Number of characters in the search string"),
                        TraceLoggingUInt32(nestedCommandDepth, "NestedCommandDepth", "the depth in the tree of commands for the dispatched action"),
                        TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                        TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
                }
            }
        }
    }
    // Method Description:
    // - Get all the input text in _searchBox that follows any leading spaces.
    // Arguments:

Review comment (bug):
Do we need nullptr or `try_as` checks here?
`actionPaletteItem.Command()` is also called above. Should we assign it to a variable?

Code after:
                    // to pick from.
                    _nestedActionStack.Append(filteredCommand);
                    ParentCommandName(actionPaletteItem.Command().Name());
                    _updateCurrentNestedCommands(actionPaletteItem.Command());

                    _updateUIForStackChange();
                }
                else
                {
                    // First stash the search text length, because _close will clear this.
                    const auto searchTextLength = _searchBox().Text().size();

                    // An action from the root command list has depth=0
                    const auto nestedCommandDepth = _nestedActionStack.Size();

                    // Close before we dispatch so that actions that open the command
                    // palette like the Tab Switcher will be able to have the last laugh.
                    _close();

                    // A note: the command palette ignores
                    // "ToggleCommandPalette" actions. We may want to do the
                    // same with "Suggestions" actions in the future, should we
                    // ever allow non-sendInput actions.
                    DispatchCommandRequested.raise(*this, actionPaletteItem.Command());

                    if (const auto& sendInputCmd = actionPaletteItem.Command().ActionAndArgs().Args().try_as<SendInputArgs>())
                    {
                        if (til::starts_with(sendInputCmd.Input(), L"winget"))
                        {
                            TraceLoggingWrite(
                                g_hTerminalAppProvider,
                                "QuickFixSuggestionUsed",
                                TraceLoggingDescription("Event emitted when a winget suggestion from is used"),
                                TraceLoggingValue("SuggestionsUI", "Source"),
                                TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                                TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
                        }
                    }

                    TraceLoggingWrite(
                        g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider
                        "SuggestionsControlDispatchedAction",
                        TraceLoggingDescription("Event emitted when the user selects an action in the Command Palette"),
                        TraceLoggingUInt32(searchTextLength, "SearchTextLength", "Number of characters in the search string"),
                        TraceLoggingUInt32(nestedCommandDepth, "NestedCommandDepth", "the depth in the tree of commands for the dispatched action"),
                        TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                        TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
                }
            }
        }
    }