[gh-88] Added limit on variables values (removed total limit for now).
This commit is contained in:
Родитель
de8b5f7976
Коммит
09024f2b40
|
@ -6,11 +6,13 @@ using System.Text;
|
||||||
|
|
||||||
namespace SharpLab.Runtime.Internal {
|
namespace SharpLab.Runtime.Internal {
|
||||||
public static class Flow {
|
public static class Flow {
|
||||||
private const int MaxReportLength = 20;
|
private static class ReportLimits {
|
||||||
private const int MaxVariableNameLength = 10;
|
public const int MaxVariableNameLength = 10;
|
||||||
private const int MaxReportEnumerableItemCount = 3;
|
public const int MaxVariableValueLength = 10;
|
||||||
private const int MaxReportStepNotesPerLineCount = 3;
|
public const int MaxEnumerableItems = 3;
|
||||||
private const int MaxReportVariablesPerStepCount = 3;
|
public const int MaxStepNotesPerLine = 3;
|
||||||
|
public const int MaxVariablesPerStep = 3;
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly IDictionary<int, int> _stepNotesCountPerLine = new Dictionary<int, int>();
|
private static readonly IDictionary<int, int> _stepNotesCountPerLine = new Dictionary<int, int>();
|
||||||
private static readonly List<Step> _steps = new List<Step>();
|
private static readonly List<Step> _steps = new List<Step>();
|
||||||
|
@ -29,19 +31,21 @@ namespace SharpLab.Runtime.Internal {
|
||||||
countPerLine += 1;
|
countPerLine += 1;
|
||||||
_stepNotesCountPerLine[step.LineNumber] = countPerLine;
|
_stepNotesCountPerLine[step.LineNumber] = countPerLine;
|
||||||
|
|
||||||
if (countPerLine == MaxReportStepNotesPerLineCount + 1) {
|
if (countPerLine == ReportLimits.MaxStepNotesPerLine + 1) {
|
||||||
step.Notes = new StringBuilder("…");
|
step.Notes = new StringBuilder("…");
|
||||||
_steps[_steps.Count - 1] = step;
|
_steps[_steps.Count - 1] = step;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countPerLine >= MaxReportStepNotesPerLineCount + 1)
|
if (countPerLine >= ReportLimits.MaxStepNotesPerLine + 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
step.VariableCount += 1;
|
step.VariableCount += 1;
|
||||||
if (step.VariableCount > MaxReportVariablesPerStepCount + 1)
|
if (step.VariableCount > ReportLimits.MaxVariablesPerStep + 1) {
|
||||||
|
_steps[_steps.Count - 1] = step;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var notes = step.Notes;
|
var notes = step.Notes;
|
||||||
if (notes == null) {
|
if (notes == null) {
|
||||||
|
@ -52,12 +56,12 @@ namespace SharpLab.Runtime.Internal {
|
||||||
if (notes.Length > 0)
|
if (notes.Length > 0)
|
||||||
notes.Append(", ");
|
notes.Append(", ");
|
||||||
|
|
||||||
if (step.VariableCount == MaxReportVariablesPerStepCount + 1) {
|
if (step.VariableCount == ReportLimits.MaxVariablesPerStep + 1) {
|
||||||
notes.Append("…");
|
notes.Append("…");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendString(notes, name, MaxVariableNameLength);
|
AppendString(notes, name, ReportLimits.MaxVariableNameLength);
|
||||||
notes.Append(": ");
|
notes.Append(": ");
|
||||||
AppendValue(notes, value);
|
AppendValue(notes, value);
|
||||||
// Have to reassign in case we set Notes
|
// Have to reassign in case we set Notes
|
||||||
|
@ -77,7 +81,7 @@ namespace SharpLab.Runtime.Internal {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case IList<int> e: return AppendEnumerable(builder, e);
|
case IList<int> e: return AppendEnumerable(builder, e);
|
||||||
case ICollection e: return AppendEnumerable(builder, e.Cast<object>());
|
case ICollection e: return AppendEnumerable(builder, e.Cast<object>());
|
||||||
default: return AppendString(builder, value.ToString(), MaxReportLength - builder.Length);
|
default: return AppendString(builder, value.ToString(), ReportLimits.MaxVariableValueLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +92,7 @@ namespace SharpLab.Runtime.Internal {
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
builder.Append(", ");
|
builder.Append(", ");
|
||||||
|
|
||||||
if (index > MaxReportEnumerableItemCount) {
|
if (index > ReportLimits.MaxEnumerableItems) {
|
||||||
builder.Append("…");
|
builder.Append("…");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -101,9 +105,6 @@ namespace SharpLab.Runtime.Internal {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StringBuilder AppendString(StringBuilder builder, string value, int limit) {
|
private static StringBuilder AppendString(StringBuilder builder, string value, int limit) {
|
||||||
if (limit <= 0)
|
|
||||||
return builder;
|
|
||||||
|
|
||||||
if (value.Length <= limit) {
|
if (value.Length <= limit) {
|
||||||
builder.Append(value);
|
builder.Append(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,8 @@ namespace SharpLab.Tests {
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Loop.For.10Iterations.cs", 3, "i: 0; i: 1; i: 2; …")]
|
[InlineData("Loop.For.10Iterations.cs", 3, "i: 0; i: 1; i: 2; …")]
|
||||||
[InlineData("Variable.MultipleDeclarationsOnTheSameLine.cs", 3, "a: 0, b: 0, c: 0, …")]
|
[InlineData("Variable.MultipleDeclarationsOnTheSameLine.cs", 3, "a: 0, b: 0, c: 0, …")]
|
||||||
[InlineData("Variable.VeryLongName.cs", 3, "whyMyVari…: 0")]
|
[InlineData("Variable.LongName.cs", 3, "abcdefghi…: 0")]
|
||||||
|
[InlineData("Variable.LongValue.cs", 3, "x: 123456789…")]
|
||||||
public async Task SlowUpdate_ReportsVariableNotesWithLengthLimits(string resourceName, int lineNumber, string expectedNotes) {
|
public async Task SlowUpdate_ReportsVariableNotesWithLengthLimits(string resourceName, int lineNumber, string expectedNotes) {
|
||||||
var driver = await NewTestDriverAsync(LoadCodeFromResource(resourceName));
|
var driver = await NewTestDriverAsync(LoadCodeFromResource(resourceName));
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
public class C {
|
||||||
|
public void M() {
|
||||||
|
var abcdefghijklmnoprstquvwxyz = 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
public class C {
|
||||||
|
public void M() {
|
||||||
|
var x = "12345678901234567890";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
public class C {
|
|
||||||
public void M() {
|
|
||||||
var whyMyVariableNameIsThisLong7GladThatYouAsked1ItStartsOneFatefulEvening = 0;
|
|
||||||
}
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче