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

Code before:
    {
        /// <summary>
        /// Returns completion results for experimental feature names used as arguments to experimental feature cmdlets.
        /// </summary>
        /// <param name="commandName">The command name.</param>
        /// <param name="parameterName">The parameter name.</param>
        /// <param name="wordToComplete">The word to complete.</param>
        /// <param name="commandAst">The command AST.</param>
        /// <param name="fakeBoundParameters">The fake bound parameters.</param>
        /// <returns>List of Completion Results.</returns>
        public IEnumerable<CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
        {
            if (fakeBoundParameters == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(fakeBoundParameters));
            }

            var commandInfo = new CmdletInfo("Get-ExperimentalFeature", typeof(GetExperimentalFeatureCommand));
            var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace)
                .AddCommand(commandInfo)
                .AddParameter("Name", wordToComplete + "*");

            HashSet<string> names = new HashSet<string>();
            var results = ps.Invoke<ExperimentalFeature>();
            foreach (var result in results)
            {
                names.Add(result.Name);
            }

            return names.Order().Select(static name => new CompletionResult(name, name, CompletionResultType.Text, name));
        }
    }
}


Review comment (refactor):
@iSazonov Do you think `GetMatchingResults` should eventually be in a base class? Seems like not ideal design to keep calling static method in `CompletionCompleters` for matching results, seems much better placed in a base class since this now is used in a lot of argument completers in this repo.

I think CompletionCompleters is getting too big and probably need to start abstracting common code for argument completers. 

Let me know your thoughts. 🙂. 

Code after:
    public class ExperimentalFeatureNameCompleter : IArgumentCompleter
    {
        /// <summary>
        /// Returns completion results for experimental feature names used as arguments to experimental feature cmdlets.
        /// </summary>
        /// <param name="commandName">The command name.</param>
        /// <param name="parameterName">The parameter name.</param>
        /// <param name="wordToComplete">The word to complete.</param>
        /// <param name="commandAst">The command AST.</param>
        /// <param name="fakeBoundParameters">The fake bound parameters.</param>
        /// <returns>List of Completion Results.</returns>
        public IEnumerable<CompletionResult> CompleteArgument(
            string commandName,
            string parameterName,
            string wordToComplete,
            CommandAst commandAst,
            IDictionary fakeBoundParameters)
        {
            SortedSet<string> expirmentalFeatures = new(StringComparer.OrdinalIgnoreCase);

            foreach (ExperimentalFeature feature in GetExperimentalFeatures())
            {
                expirmentalFeatures.Add(feature.Name);
            }

            return CompletionCompleters.GetMatchingResults(wordToComplete, expirmentalFeatures);
        }

        private static Collection<ExperimentalFeature> GetExperimentalFeatures()
        {
            using var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
            ps.AddCommand("Get-ExperimentalFeature");
            return ps.Invoke<ExperimentalFeature>();
        }
    }
}