Exemple #1
0
        /// <summary>
        /// Adds suggestions for given argument position.
        /// Returns true if any function specific suggestions are added to the list. Otherwise false.
        /// </summary>
        /// <returns></returns>
        public static bool TryAddSpecificSuggestionsForGivenArgPosition(IntellisenseData.IntellisenseData intellisenseData, CallNode callNode, int argumentIndex)
        {
            Contracts.AssertValue(intellisenseData);
            Contracts.AssertValue(callNode);
            Contracts.Assert(argumentIndex >= 0);

            CallInfo info = intellisenseData.Binding.GetInfo(callNode);

            Contracts.AssertValue(info);

            if (callNode.Args.Count < 0 ||
                info.Function == null ||
                !info.Function.HasSuggestionsForParam(argumentIndex))
            {
                return(false);
            }

            // Adding suggestions for callNode arguments from the Function's GetArgumentSuggestions method
            // Keep track of the previous suggestion counts so we can tell whether or not we have added any
            int countSuggestionsBefore          = intellisenseData.Suggestions.Count;
            int countSubstringSuggestionsBefore = intellisenseData.SubstringSuggestions.Count;

            // If the function has specific suggestions for the argument,
            // indicate it to the caller.
            var       function       = info.Function;
            var       suggestionKind = intellisenseData.GetFunctionSuggestionKind(function, argumentIndex);
            bool      requiresSuggestionEscaping;
            ErrorNode err;

            if (argumentIndex >= 0 && argumentIndex < callNode.Args.Count && ((err = callNode.Args.Children[argumentIndex].AsError()) != null) &&
                err.Token.Span.StartsWith(intellisenseData.Script, "\""))
            {
                intellisenseData.CleanupHandlers.Add(new StringSuggestionHandler(err.Token.Span.Min));
            }

            DType scopeType = ScopeTypeForArgumentSuggestions(callNode, intellisenseData);

            var argSuggestions = intellisenseData.GetArgumentSuggestions(function, scopeType, argumentIndex, callNode.Args.Children, out requiresSuggestionEscaping);

            foreach (KeyValuePair <string, DType> suggestion in argSuggestions)
            {
                AddSuggestion(intellisenseData, suggestion.Key, suggestionKind, SuggestionIconKind.Function, suggestion.Value, requiresSuggestionEscaping);
            }

            return(intellisenseData.Suggestions.Count > countSuggestionsBefore ||
                   intellisenseData.SubstringSuggestions.Count > countSubstringSuggestionsBefore);
        }