Exemple #1
0
        public PythonSignature(ITrackingSpan span, IOverloadResult overload, int paramIndex)
        {
            _span     = span;
            _overload = overload;

            var content = new StringBuilder(overload.Name);

            content.Append('(');
            int start      = content.Length;
            var parameters = new IParameter[overload.Parameters.Length];

            for (int i = 0; i < overload.Parameters.Length; i++)
            {
                var param = overload.Parameters[i];
                if (param.IsOptional)
                {
                    content.Append("[");
                }
                if (i > 0)
                {
                    content.Append(", ");
                    start = content.Length;
                }

                content.Append(param.Name);
                if (param.Type != null && param.Type != "object")
                {
                    content.Append(": ");
                    content.Append(param.Type);
                }

                var paramSpan = new Span(start, content.Length - start);

                if (param.IsOptional)
                {
                    content.Append("]");
                }

                parameters[i] = new PythonParameter(this, param, paramSpan);
            }
            content.Append(')');
            _content = content.ToString();

            _parameters = new ReadOnlyCollection <IParameter>(parameters);
            if (paramIndex < parameters.Length)
            {
                _currentParameter = parameters[paramIndex];
            }
            else
            {
                _currentParameter = null;
            }
        }
Exemple #2
0
        public PythonSignature(ITrackingSpan span, IOverloadResult overload, int paramIndex, string lastKeywordArg = null) {
            _span = span;
            _overload = overload;
            if (lastKeywordArg != null) {
                paramIndex = Int32.MaxValue;
            }

            var content = new StringBuilder(overload.Name);
            var ppContent = new StringBuilder(overload.Name);
            content.Append('(');
            ppContent.AppendLine("(");
            int start = content.Length, ppStart = ppContent.Length;
            var parameters = new IParameter[overload.Parameters.Length];
            for (int i = 0; i < overload.Parameters.Length; i++) {
                ppContent.Append("    ");
                ppStart = ppContent.Length;
                
                var param = overload.Parameters[i];
                if (param.IsOptional) {
                    content.Append('[');
                    ppContent.Append('[');
                }
                if (i > 0) {
                    content.Append(", ");
                    start = content.Length;
                }

                content.Append(param.Name);
                ppContent.Append(param.Name);
                if (!string.IsNullOrEmpty(param.Type) && param.Type != "object") {
                    content.Append(": ");
                    content.Append(param.Type);
                    ppContent.Append(": ");
                    ppContent.Append(param.Type);
                }
                
                if (!String.IsNullOrWhiteSpace(param.DefaultValue)) {
                    content.Append(" = ");
                    content.Append(param.DefaultValue);
                    ppContent.Append(" = ");
                    ppContent.Append(param.DefaultValue);
                }

                var paramSpan = new Span(start, content.Length - start);
                var ppParamSpan = new Span(ppStart, ppContent.Length - ppStart);

                if (param.IsOptional) {
                    content.Append(']');
                    ppContent.Append(']');
                }

                ppContent.AppendLine(",");

                if (lastKeywordArg != null && param.Name == lastKeywordArg) {
                    paramIndex = i;
                }

                parameters[i] = new PythonParameter(this, param, paramSpan, ppParamSpan);
            }
            content.Append(')');
            ppContent.Append(')');

            _content = content.ToString();
            _ppContent = ppContent.ToString();
            _documentation = overload.Documentation.LimitLines(15, stopAtFirstBlankLine: true);

            _parameters = new ReadOnlyCollection<IParameter>(parameters);
            if (lastKeywordArg == null) {
                for (int i = 0; i < parameters.Length; ++i) {
                    if (i == paramIndex || IsParamArray(parameters[i].Name)) {
                        _currentParameter = parameters[i];
                        break;
                    }
                }
            } else if (paramIndex < parameters.Length) {
                _currentParameter = parameters[paramIndex];
            }
        }
Exemple #3
0
        private void Initialize()
        {
            if (_content != null)
            {
                Debug.Assert(_ppContent != null && _parameters != null);
                return;
            }

            Debug.Assert(_content == null && _ppContent == null && _parameters == null);

            var content    = new StringBuilder(_overload.name);
            var ppContent  = new StringBuilder(_overload.name);
            var parameters = new IParameter[_overload.parameters.Length];

            content.Append('(');
            ppContent.AppendLine("(");
            int start = content.Length, ppStart = ppContent.Length;

            for (int i = 0; i < _overload.parameters.Length; i++)
            {
                ppContent.Append("    ");
                ppStart = ppContent.Length;

                var param = _overload.parameters[i];
                if (param.optional)
                {
                    content.Append('[');
                    ppContent.Append('[');
                }
                if (i > 0)
                {
                    content.Append(", ");
                    start = content.Length;
                }

                var name   = param.name ?? "";
                var isDict = name.StartsWith("**");
                var isList = !isDict && name.StartsWith("*");

                content.Append(name);
                ppContent.Append(name);

                if (!string.IsNullOrEmpty(param.type) && param.type != "object")
                {
                    content.Append(": ");
                    content.Append(param.type);
                    ppContent.Append(": ");
                    ppContent.Append(param.type);
                }

                if (!String.IsNullOrWhiteSpace(param.defaultValue))
                {
                    content.Append(" = ");
                    content.Append(param.defaultValue);
                    ppContent.Append(" = ");
                    ppContent.Append(param.defaultValue);
                }

                var paramSpan   = new Span(start, content.Length - start);
                var ppParamSpan = new Span(ppStart, ppContent.Length - ppStart);

                if (param.optional)
                {
                    content.Append(']');
                    ppContent.Append(']');
                }

                ppContent.AppendLine(",");

                parameters[i] = new PythonParameter(
                    this,
                    param,
                    paramSpan,
                    ppParamSpan,
                    param.variables != null ? param.variables.Select(_analyzer.ToAnalysisVariable).ToArray() : null
                    );

                if (isDict && _dictParamIndex == int.MaxValue)
                {
                    _dictParamIndex = i;
                }

                if (isList && _listParamIndex == int.MaxValue)
                {
                    _listParamIndex = i;
                }
            }
            content.Append(')');
            ppContent.Append(')');

            _content   = content.ToString();
            _ppContent = ppContent.ToString();

            _parameters = new ReadOnlyCollection <IParameter>(parameters);
            SelectBestParameter(_initialParameterIndex, _initialParameterName);
        }
        public PythonSignature(ITrackingSpan span, IOverloadResult overload, int paramIndex, string lastKeywordArg = null)
        {
            _span     = span;
            _overload = overload;
            if (lastKeywordArg != null)
            {
                paramIndex = Int32.MaxValue;
            }

            var content   = new StringBuilder(overload.Name);
            var ppContent = new StringBuilder(overload.Name);

            content.Append('(');
            ppContent.AppendLine("(");
            int start = content.Length, ppStart = ppContent.Length;
            var parameters = new IParameter[overload.Parameters.Length];

            for (int i = 0; i < overload.Parameters.Length; i++)
            {
                ppContent.Append("    ");
                ppStart = ppContent.Length;

                var param = overload.Parameters[i];
                if (param.IsOptional)
                {
                    content.Append('[');
                    ppContent.Append('[');
                }
                if (i > 0)
                {
                    content.Append(", ");
                    start = content.Length;
                }

                content.Append(param.Name);
                ppContent.Append(param.Name);
                if (!string.IsNullOrEmpty(param.Type) && param.Type != "object")
                {
                    content.Append(": ");
                    content.Append(param.Type);
                    ppContent.Append(": ");
                    ppContent.Append(param.Type);
                }

                if (!String.IsNullOrWhiteSpace(param.DefaultValue))
                {
                    content.Append(" = ");
                    content.Append(param.DefaultValue);
                    ppContent.Append(" = ");
                    ppContent.Append(param.DefaultValue);
                }

                var paramSpan   = new Span(start, content.Length - start);
                var ppParamSpan = new Span(ppStart, ppContent.Length - ppStart);

                if (param.IsOptional)
                {
                    content.Append(']');
                    ppContent.Append(']');
                }

                ppContent.AppendLine(",");

                if (lastKeywordArg != null && param.Name == lastKeywordArg)
                {
                    paramIndex = i;
                }

                parameters[i] = new PythonParameter(this, param, paramSpan, ppParamSpan);
            }
            content.Append(')');
            ppContent.Append(')');

            _content       = content.ToString();
            _ppContent     = ppContent.ToString();
            _documentation = overload.Documentation.LimitLines(15, stopAtFirstBlankLine: true);

            _parameters = new ReadOnlyCollection <IParameter>(parameters);
            if (lastKeywordArg == null)
            {
                for (int i = 0; i < parameters.Length; ++i)
                {
                    if (i == paramIndex || IsParamArray(parameters[i].Name))
                    {
                        _currentParameter = parameters[i];
                        break;
                    }
                }
            }
            else if (paramIndex < parameters.Length)
            {
                _currentParameter = parameters[paramIndex];
            }
        }