Exemplo n.º 1
0
        private static void PopSpan(
            Stack <Tuple <int, string> > spanStartStack,
            IDictionary <string, List <IndexSpan> > spans,
            int finalIndex)
        {
            var spanStartTuple = spanStartStack.Pop();

            var span = IndexSpan.FromBounds(spanStartTuple.Item1, finalIndex);

            GetOrAdd(spans, spanStartTuple.Item2, _ => new List <IndexSpan>()).Add(span);
        }
        public string GetSignatureString(IPythonFunctionType ft, IPythonType self, out IndexSpan[] parameterSpans, int overloadIndex = 0, string name = null)
        {
            var o = ft.Overloads[overloadIndex];

            var parameterStrings = GetFunctionParameters(ft, out var parameterNameLengths);
            var returnDoc        = o.GetReturnDocumentation(self);
            var annString        = string.IsNullOrEmpty(returnDoc) ? string.Empty : $" -> {returnDoc}";

            // Calculate parameter spans
            parameterSpans = new IndexSpan[parameterStrings.Length];
            name           = name ?? ft.Name;
            var offset = name.Length + 1;

            for (var i = 0; i < parameterStrings.Length; i++)
            {
                parameterSpans[i] = IndexSpan.FromBounds(offset, offset + parameterNameLengths[i]);
                offset           += parameterStrings[i].Length + 2; // name,<space>
            }

            var combinedParameterString = string.Join(", ", parameterStrings);

            return($"{name}({combinedParameterString}){annString}");
        }
 public static IndexSpan ToIndexSpan(this Range range, PythonAst ast)
 => IndexSpan.FromBounds(ast.LocationToIndex(range.start), ast.LocationToIndex(range.end));
 public static IndexSpan ToIndexSpan(this SourceSpan span, PythonAst ast)
 => IndexSpan.FromBounds(ast.LocationToIndex(span.Start), ast.LocationToIndex(span.End));
Exemplo n.º 5
0
 public static IndexSpan ToIndexSpan(this Range range, ILocationConverter lc)
 => IndexSpan.FromBounds(lc.LocationToIndex(range.start), lc.LocationToIndex(range.end));
Exemplo n.º 6
0
 public static IndexSpan ToIndexSpan(this SourceSpan span, ILocationConverter lc)
 => IndexSpan.FromBounds(lc.LocationToIndex(span.Start), lc.LocationToIndex(span.End));