Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs (C#)

Code before:
    /// </summary>
    internal static class CompletionHelpers
    {
        private static readonly SearchValues<char> s_defaultCharsToCheck = SearchValues.Create("$`");

        /// <summary>
        /// Get matching completions from word to complete.
        /// This makes it easier to handle different variations of completions with consideration of quotes.
        /// </summary>
        /// <param name="wordToComplete">The word to complete.</param>
        /// <param name="possibleCompletionValues">The possible completion values to iterate.</param>
        /// <param name="toolTipMapping">The optional tool tip mapping delegate.</param>
        /// <param name="listItemTextMapping">The optional list item text mapping delegate.</param>
        /// <param name="resultType">The optional completion result type. Default is Text.</param>
        /// <param name="matchStrategy">The optional match strategy delegate.</param>
        /// <returns>List of matching completion results.</returns>
        internal static IEnumerable<CompletionResult> GetMatchingResults(
            string wordToComplete,
            IEnumerable<string> possibleCompletionValues,
            Func<string, string> toolTipMapping = null,
            Func<string, string> listItemTextMapping = null,
            CompletionResultType resultType = CompletionResultType.Text,
            MatchStrategy matchStrategy = null)
        {
            string quote = HandleDoubleAndSingleQuote(ref wordToComplete);

            matchStrategy ??= DefaultMatch;

            foreach (string value in possibleCompletionValues)
            {
                if (matchStrategy(value, wordToComplete))
                {
                    string completionText = QuoteCompletionText(value, quote);
                    string toolTip = toolTipMapping?.Invoke(value) ?? value;
                    string listItemText = listItemTextMapping?.Invoke(value) ?? value;

                    yield return new CompletionResult(completionText, listItemText, resultType, toolTip);
                }
            }
        }

        internal delegate bool MatchStrategy(string value, string wordToComplete);

        internal static readonly MatchStrategy LiteralMatch = (value, wordToComplete)
            => value.StartsWith(
                WildcardPattern.Unescape(wordToComplete.ReplaceLineEndings("`")),
                StringComparison.OrdinalIgnoreCase);

        internal static readonly MatchStrategy WildcardPatternMatch = (value, wordToComplete)
            => WildcardPattern
                .Get(wordToComplete + "*", WildcardOptions.IgnoreCase)

Review comment (suggestion):
Maybe assign default here?
```suggestion
            MatchStrategy matchStrategy = DefaultMatch)
```

Code after:
    /// </summary>
    internal static class CompletionHelpers
    {
        private static readonly SearchValues<char> s_defaultCharsToCheck = SearchValues.Create("$`");

        private const string SingleQuote = "'";
        private const string DoubleQuote = "\"";

        /// <summary>
        /// Get matching completions from word to complete.
        /// This makes it easier to handle different variations of completions with consideration of quotes.
        /// </summary>
        /// <param name="wordToComplete">The word to complete.</param>
        /// <param name="possibleCompletionValues">The possible completion values to iterate.</param>
        /// <param name="toolTipMapping">The optional tool tip mapping delegate.</param>
        /// <param name="listItemTextMapping">The optional list item text mapping delegate.</param>
        /// <param name="resultType">The optional completion result type. Default is Text.</param>
        /// <param name="matchStrategy">The optional match strategy delegate.</param>
        /// <returns>List of matching completion results.</returns>
        internal static IEnumerable<CompletionResult> GetMatchingResults(
            string wordToComplete,
            IEnumerable<string> possibleCompletionValues,
            Func<string, string> toolTipMapping = null,
            Func<string, string> listItemTextMapping = null,
            CompletionResultType resultType = CompletionResultType.Text,
            MatchStrategy matchStrategy = null)
        {
            matchStrategy ??= DefaultMatch;

            string quote = HandleDoubleAndSingleQuote(ref wordToComplete);
            if (quote != SingleQuote)
            {
                wordToComplete = NormalizeToExpandableString(wordToComplete);
            }

            foreach (string value in possibleCompletionValues)
            {
                if (matchStrategy(value, wordToComplete))
                {
                    string completionText = QuoteCompletionText(value, quote);
                    string toolTip = toolTipMapping?.Invoke(value) ?? value;
                    string listItemText = listItemTextMapping?.Invoke(value) ?? value;

                    yield return new CompletionResult(completionText, listItemText, resultType, toolTip);
                }
            }
        }

        /// <summary>
        /// Normalizes the input string to an expandable string format for PowerShell.
        /// </summary>