Skip to content

Commit b0eed6e

Browse files
authored
WI #2185 #2319 Add last 5 incremental changes into debug trace (#2426)
1 parent f440b77 commit b0eed6e

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

TypeCobol/Compiler/CompilationUnit.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public CompilationUnit(TextSourceInfo textSourceInfo, bool isImported, IEnumerab
4949
_analyzerProvider = null;
5050
}
5151

52+
_history = this.TrackChanges(5);
5253
}
5354

5455
/// <summary>
@@ -235,6 +236,8 @@ public void RefreshProgramClassDocumentSnapshot()
235236
#endif
236237
}
237238

239+
private readonly IncrementalChangesHistory _history;
240+
238241
/// <summary>
239242
/// Creates a temporary snapshot which contains element before the cross check phase
240243
/// Usefull to create a program symboltable without checking nodes.
@@ -263,6 +266,7 @@ public void ProduceTemporarySemanticDocument()
263266
CustomSymbols,
264267
perfStatsForParserInvocation,
265268
customAnalyzers,
269+
_history,
266270
out var root,
267271
out var newDiagnostics,
268272
out var nodeCodeElementLinkers,

TypeCobol/Compiler/CupParser/NodeBuilder/ProgramClassBuilder.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,26 @@ private void LogErrorIncludingFullSourceCode(string message)
3737
}
3838
}
3939

40+
var changes = new StringBuilder();
41+
int i = -4; //Number last 5 changes from -4 to 0
42+
foreach (var textChangedEvent in _history.TextChangedEvents)
43+
{
44+
changes.AppendLine($"change {i}:");
45+
foreach (var documentChange in textChangedEvent.DocumentChanges)
46+
{
47+
string text = documentChange.NewLine == null
48+
? string.Empty
49+
: '"' + documentChange.NewLine.Text + '"';
50+
changes.AppendLine($"{documentChange.Type}@{documentChange.LineIndex} {text}");
51+
}
52+
i++;
53+
}
54+
4055
var contextData = new Dictionary<string, object>()
4156
{
4257
{ "codeElements", codeElements.ToString() },
43-
{ "sourceCode", sourceCode.ToString() }
58+
{ "sourceCode", sourceCode.ToString() },
59+
{ "changes", changes.ToString() }
4460
};
4561
LoggingSystem.LogMessage(LogLevel.Error, message, contextData);
4662

@@ -88,8 +104,9 @@ private Program CurrentProgram
88104
private readonly SymbolTable TableOfNamespaces;
89105

90106
private readonly IReadOnlyList<CodeElementsLine> _codeElementsLines;
107+
private readonly IncrementalChangesHistory _history;
91108

92-
public ProgramClassBuilder(IReadOnlyList<CodeElementsLine> codeElementsLines)
109+
public ProgramClassBuilder(IReadOnlyList<CodeElementsLine> codeElementsLines, IncrementalChangesHistory history)
93110
{
94111
// Intrinsics and Namespaces always exist. Intrinsic table has no enclosing scope.
95112
TableOfIntrinsics = new SymbolTable(null, SymbolTable.Scope.Intrinsic);
@@ -98,6 +115,7 @@ public ProgramClassBuilder(IReadOnlyList<CodeElementsLine> codeElementsLines)
98115
programsStack = new Stack<Program>();
99116

100117
_codeElementsLines = codeElementsLines;
118+
_history = history;
101119
}
102120

103121
public SymbolTable CustomSymbols

TypeCobol/Compiler/Parser/ProgramClassParserStep.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static void CupParseProgramOrClass(
4747
SymbolTable customSymbols,
4848
PerfStatsForParserInvocation perfStatsForParserInvocation,
4949
ISyntaxDrivenAnalyzer[] customAnalyzers,
50+
IncrementalChangesHistory history,
5051
out SourceFile root,
5152
out List<Diagnostic> diagnostics,
5253
out Dictionary<CodeElement, Node> nodeCodeElementLinkers,
@@ -69,7 +70,7 @@ public static void CupParseProgramOrClass(
6970
CupParser.TypeCobolProgramParser parser = new CupParser.TypeCobolProgramParser(scanner);
7071
CupParserTypeCobolProgramDiagnosticErrorReporter diagReporter = new CupParserTypeCobolProgramDiagnosticErrorReporter();
7172
parser.ErrorReporter = diagReporter;
72-
ProgramClassBuilder builder = new ProgramClassBuilder(codeElementsLines);
73+
ProgramClassBuilder builder = new ProgramClassBuilder(codeElementsLines, history);
7374
parser.Builder = builder;
7475
ParserDiagnostic programClassBuilderError = null;
7576

0 commit comments

Comments
 (0)