예제 #1
0
        // This method returns the suggestions for latter arguments of the If function based on the second argument (the true result)
        private static IEnumerable <KeyValuePair <string, DType> > IfSuggestions(TryGetEnumSymbol tryGetEnumSymbol, bool suggestUnqualifedEnums, DType scopeType, int argumentIndex, out bool requiresSuggestionEscaping)
        {
            Contracts.Assert(scopeType.IsValid);
            Contracts.Assert(0 <= argumentIndex);

            requiresSuggestionEscaping = false;

            if (argumentIndex <= 1)
            {
                return(EnumerableUtils.Yield <KeyValuePair <string, DType> >());
            }

            return(scopeType
                   .GetNames(DPath.Root)
                   .Select(name => new KeyValuePair <string, DType>(TexlLexer.EscapeName(name.Name.Value), name.Type)));
        }
예제 #2
0
        /// <summary>
        /// This method returns the suggestions for second and third arguments of the Text function.
        /// </summary>
        /// <param name="tryGetEnumSymbol">
        /// Getter for enum symbols intended for the suggestions
        /// </param>
        /// <param name="suggestUnescapedEnums">
        /// Whether to suggest unescaped enums
        /// </param>
        /// <param name="scopeType">
        /// Type of the enclosing scope from where intellisense is run
        /// </param>
        /// <param name="argumentIndex">
        /// The current index of the argument from where intellisense is run
        /// </param>
        /// <param name="requiresSuggestionEscaping">
        /// Set to whether the argument needs to be string escaped
        /// </param>
        /// <returns>
        /// Enumerable of suggestions wherein the key is the suggestion text and the value is its type
        /// </returns>
        private static IEnumerable <KeyValuePair <string, DType> > TextSuggestions(TryGetEnumSymbol tryGetEnumSymbol, bool suggestUnescapedEnums, DType scopeType, int argumentIndex, out bool requiresSuggestionEscaping)
        {
            Contracts.Assert(scopeType.IsValid);
            Contracts.Assert(0 <= argumentIndex);

            requiresSuggestionEscaping = true;

            if (argumentIndex != 1 && argumentIndex != 2)
            {
                return(EnumerableUtils.Yield <KeyValuePair <string, DType> >());
            }

            if (argumentIndex == 1)
            {
                if (!DType.DateTime.Accepts(scopeType) || !tryGetEnumSymbol(EnumConstants.DateTimeFormatEnumString, out var enumInfo))
                {
                    return(EnumerableUtils.Yield <KeyValuePair <string, DType> >());
                }

                var retVal = new List <KeyValuePair <string, DType> >();
                Contracts.AssertValue(enumInfo);

                requiresSuggestionEscaping = false;
                foreach (var name in enumInfo.EnumType.GetNames(DPath.Root))
                {
                    string locName;
                    enumInfo.TryGetLocValueName(name.Name.Value, out locName).Verify();
                    retVal.Add(new KeyValuePair <string, DType>(TexlLexer.EscapeName(enumInfo.Name) + TexlLexer.PunctuatorDot + TexlLexer.EscapeName(locName), name.Type));
                }

                return(retVal);
            }
            else
            {
                Contracts.Assert(argumentIndex == 2);

                requiresSuggestionEscaping = false;
                return(GetLanguageCodeSuggestions());
            }
        }
예제 #3
0
        public static IEnumerable <KeyValuePair <string, DType> > GetArgumentSuggestions(TryGetEnumSymbol tryGetEnumSymbol, bool suggestUnqualifiedEnums, TexlFunction function, DType scopeType, int argumentIndex, out bool requiresSuggestionEscaping)
        {
            if (CustomFunctionSuggestionProviders.Value.TryGetValue(function.GetType(), out var suggestor))
            {
                return(suggestor(tryGetEnumSymbol, suggestUnqualifiedEnums, scopeType, argumentIndex, out requiresSuggestionEscaping));
            }

            requiresSuggestionEscaping = false;
            return(Enumerable.Empty <KeyValuePair <string, DType> >());
        }
예제 #4
0
        private static IEnumerable <KeyValuePair <string, DType> > LanguageCodeSuggestion(TryGetEnumSymbol tryGetEnumSymbol, bool suggestUnqualifedEnums, DType scopeType, int argumentIndex, out bool requiresSuggestionEscaping)
        {
            Contracts.Assert(scopeType.IsValid);
            Contracts.Assert(0 <= argumentIndex);

            requiresSuggestionEscaping = false;
            return(argumentIndex == 1 ? GetLanguageCodeSuggestions() : EnumerableUtils.Yield <KeyValuePair <string, DType> >());
        }
예제 #5
0
        private static IEnumerable <KeyValuePair <string, DType> > TimeUnitSuggestions(TryGetEnumSymbol tryGetEnumSymbol, bool suggestUnqualifedEnums, DType scopeType, int argumentIndex, out bool requiresSuggestionEscaping)
        {
            Contracts.Assert(scopeType.IsValid);
            Contracts.Assert(2 == argumentIndex);

            requiresSuggestionEscaping = false;
            var retVal = new List <KeyValuePair <string, DType> >();

            if (argumentIndex == 2 && tryGetEnumSymbol(EnumConstants.TimeUnitEnumString, out var enumInfo))
            {
                Contracts.AssertValue(enumInfo);
                foreach (var name in enumInfo.EnumType.GetNames(DPath.Root))
                {
                    string locName;
                    enumInfo.TryGetLocValueName(name.Name.Value, out locName).Verify();
                    if (suggestUnqualifedEnums)
                    {
                        retVal.Add(new KeyValuePair <string, DType>(TexlLexer.EscapeName(locName), name.Type));
                    }
                    else
                    {
                        retVal.Add(new KeyValuePair <string, DType>(TexlLexer.EscapeName(enumInfo.Name) + TexlLexer.PunctuatorDot + TexlLexer.EscapeName(locName), name.Type));
                    }
                }
            }

            return(retVal);
        }