Beispiel #1
0
 internal override OverloadResult WithNewParameters(ParameterResult[] newParameters)
 {
     return(new BuiltinFunctionOverloadResult(
                _projectState,
                Name,
                _overload,
                _overload.GetParameters()?.Length ?? 0,
                _fallbackDoc,
                newParameters
                ));
 }
Beispiel #2
0
        private static IEnumerable <KeyValuePair <string, string> > GetParameterString(IPythonFunctionOverload overload)
        {
            var parameters = overload.GetParameters();

            for (int i = 0; i < parameters.Length; i++)
            {
                if (i != 0)
                {
                    yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Comma, ", "));
                }
                var p = parameters[i];

                var name = p.Name;
                if (p.IsKeywordDict)
                {
                    name = "**" + name;
                }
                else if (p.IsParamArray)
                {
                    name = "*" + name;
                }

                yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Parameter, name));

                if (!string.IsNullOrWhiteSpace(p.DefaultValue))
                {
                    yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, " = "));

                    yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, p.DefaultValue));
                }
            }
        }
        private string CalculatePrototype()
        {
            var proto = new StringBuilder("(");

            foreach (var arg in _overload.GetParameters())
            {
                if (arg.IsParamArray)
                {
                    proto.Append("*");
                }
                else if (arg.IsKeywordDict)
                {
                    proto.Append("**");
                }
                proto.Append(arg.Name);
                proto.Append("=");

                var types = arg.ParameterTypes == null ?
                            new string[0] :
                            arg.ParameterTypes.Select(p => p.Name).Distinct().OrderBy(p => p).ToArray();
                if (types.Length == 1)
                {
                    proto.Append(types[0]);
                }
                else
                {
                    proto.AppendFormat("{{{0}}}", string.Join(", ", types));
                }

                if (!string.IsNullOrEmpty(arg.DefaultValue))
                {
                    proto.AppendFormat(" [{0}]", arg.DefaultValue);
                }

                proto.Append(", ");
            }

            if (proto.Length > 2)
            {
                proto.Length -= 2;
            }
            proto.Append(")");

            return(proto.ToString());
        }
Beispiel #4
0
        private void DocCalculator()
        {
            StringBuilder doc = new StringBuilder();

            if (!String.IsNullOrEmpty(_overload.Documentation))
            {
                doc.AppendLine(_overload.Documentation);
            }

            foreach (var param in _overload.GetParameters())
            {
                if (!String.IsNullOrEmpty(param.Documentation))
                {
                    doc.AppendLine();
                    doc.Append(param.Name);
                    doc.Append(": ");
                    doc.Append(param.Documentation);
                }
            }

            if (!String.IsNullOrEmpty(_overload.ReturnDocumentation))
            {
                doc.AppendLine();
                doc.AppendLine();
                doc.Append("Returns: ");
                doc.Append(_overload.ReturnDocumentation);
            }

            if (doc.Length == 0 && _fallbackDoc != null)
            {
                _doc = _fallbackDoc();
            }
            else
            {
                _doc = doc.ToString();
            }
            _docTask = null;
        }
Beispiel #5
0
        private void CalculateDocumentation()
        {
            // initially fill in w/ a string saying we don't yet have the documentation
            _doc = _calculating;

            // and then asynchronously calculate the documentation
            ThreadPool.QueueUserWorkItem(
                x => {
                //var overloadDoc = _projectState.DocProvider.GetOverloads(_overload).First();
                StringBuilder doc = new StringBuilder();
                if (!String.IsNullOrEmpty(_overload.Documentation))
                {
                    doc.AppendLine(_overload.Documentation);
                }

                foreach (var param in _overload.GetParameters())
                {
                    if (!String.IsNullOrEmpty(param.Documentation))
                    {
                        doc.AppendLine();
                        doc.Append(param.Name);
                        doc.Append(": ");
                        doc.Append(param.Documentation);
                    }
                }

                if (!String.IsNullOrEmpty(_overload.ReturnDocumentation))
                {
                    doc.AppendLine();
                    doc.AppendLine();
                    doc.Append("Returns: ");
                    doc.Append(_overload.ReturnDocumentation);
                }
                _doc = doc.ToString();
            }
                );
        }