Exemple #1
0
        public static IEnumerable <string> GetSuggestions(
            this ParseResult parseResult,
            int?position = null)
        {
            var textToMatch         = parseResult.TextToMatch(position);
            var currentSymbolResult = parseResult.SymbolToComplete(position);
            var currentSymbol       = currentSymbolResult.Symbol;

            var currentSymbolSuggestions =
                currentSymbol is ISuggestionSource currentSuggestionSource
                    ? currentSuggestionSource.GetSuggestions(textToMatch)
                    : Array.Empty <string>();

            IEnumerable <string> siblingSuggestions;
            var parentSymbol = currentSymbolResult.Parent?.Symbol;

            if (parentSymbol == null ||
                !currentSymbolResult.IsArgumentLimitReached)
            {
                siblingSuggestions = Array.Empty <string>();
            }
            else
            {
                siblingSuggestions = parentSymbol
                                     .GetSuggestions(textToMatch)
                                     .Except(parentSymbol
                                             .Children
                                             .OfType <ICommand>()
                                             .Select(c => c.Name));
            }

            if (currentSymbolResult is CommandResult commandResult)
            {
                currentSymbolSuggestions = currentSymbolSuggestions
                                           .Except(OptionsWithArgumentLimitReached(currentSymbolResult));

                if (currentSymbolResult.Parent is CommandResult parent)
                {
                    siblingSuggestions = siblingSuggestions.Except(OptionsWithArgumentLimitReached(parent));
                }
            }

            return(currentSymbolSuggestions.Concat(siblingSuggestions));

            string[] OptionsWithArgumentLimitReached(SymbolResult symbolResult)
            {
                var optionsWithArgLimitReached =
                    symbolResult
                    .Children
                    .Where(c => c.IsArgumentLimitReached);

                var exclude = optionsWithArgLimitReached
                              .SelectMany(c => c.Symbol.RawAliases)
                              .Concat(commandResult.Symbol.RawAliases)
                              .ToArray();

                return(exclude);
            }
        }
Exemple #2
0
        public static IEnumerable <string?> GetSuggestions(
            this ParseResult parseResult,
            int?position = null)
        {
            var textToMatch         = parseResult.TextToMatch(position);
            var currentSymbolResult = parseResult.SymbolToComplete(position);
            var currentSymbol       = currentSymbolResult.Symbol;

            var currentSymbolSuggestions =
                currentSymbol is ISuggestionSource currentSuggestionSource
                    ? currentSuggestionSource.GetSuggestions(textToMatch)
                    : Array.Empty <string>();

            IEnumerable <string?> siblingSuggestions;
            var parentSymbol = currentSymbolResult.Parent?.Symbol;

            if (parentSymbol is null ||
                !currentSymbolResult.IsArgumentLimitReached)
            {
                siblingSuggestions = Array.Empty <string?>();
            }