diff --git a/KustoSchemaTools/Changes/ScriptCompareChange.cs b/KustoSchemaTools/Changes/ScriptCompareChange.cs
index 0fcc095..4993ffb 100644
--- a/KustoSchemaTools/Changes/ScriptCompareChange.cs
+++ b/KustoSchemaTools/Changes/ScriptCompareChange.cs
@@ -1,4 +1,7 @@
-using Kusto.Language;
+using DiffPlex;
+using DiffPlex.DiffBuilder;
+using DiffPlex.DiffBuilder.Model;
+using Kusto.Language;
using KustoSchemaTools.Model;
using KustoSchemaTools.Parser;
using System.Text;
@@ -47,18 +50,37 @@ private void Init()
sb.AppendLine($"
{logo} | ");
sb.AppendLine($"{change.Kind} | ");
sb.AppendLine($"");
+
+
+ var beforeText = before?.Text.PrettifyKql() ?? "";
+ var afterText = change.Text.PrettifyKql();
+ var differ = new Differ();
+ var diff = InlineDiffBuilder.Diff(beforeText, afterText, false);
+
if (before != null)
{
sb.AppendLine("");
sb.AppendLine($" From: | ");
- sb.AppendLine($" {before.Text.PrettifyKql()} | ");
+ sb.AppendLine($" ");
+
+ sb.AppendLine(FormatChangeDiff(diff.Lines.Where(itm => itm.Type == ChangeType.Deleted || itm.Type == ChangeType.Unchanged)));
+
+ sb.AppendLine();
+ sb.AppendLine(" | ");
sb.AppendLine("
");
}
+
sb.AppendLine("");
sb.AppendLine($" {addActionText}: | ");
- sb.AppendLine($" {change.Text.PrettifyKql()} | ");
+ sb.AppendLine($" ");
+
+ sb.AppendLine(FormatChangeDiff(diff.Lines.Where(itm => itm.Type == ChangeType.Inserted || itm.Type == ChangeType.Unchanged)));
+
+ sb.AppendLine();
+ sb.AppendLine(" | ");
sb.AppendLine("
");
+
if (change.IsValid == false)
{
foreach (var diagnostic in diagnostics)
@@ -73,6 +95,40 @@ private void Init()
sb.AppendLine("");
Markdown = sb.ToString();
}
+
+
+ public string FormatChangeDiff(IEnumerable diffs)
+ {
+ var allDiffs = diffs.ToList();
+
+ if (allDiffs.Count <= 1)
+ {
+ return allDiffs.Any() ? allDiffs[0].Text : "";
+ }
+
+ var sb = new StringBuilder();
+ sb.AppendLine();
+ sb.AppendLine("```diff");
+ foreach (var diff in allDiffs)
+ {
+ switch (diff.Type)
+ {
+ case ChangeType.Deleted:
+ sb.AppendLine($"- {diff.Text}");
+ break;
+ case ChangeType.Inserted:
+ sb.AppendLine($"+ {diff.Text}");
+ break;
+ case ChangeType.Unchanged:
+ sb.AppendLine($"{diff.Text}");
+ break;
+ default: throw new NotSupportedException();
+ }
+ }
+ sb.AppendLine("```");
+ sb.AppendLine();
+ return sb.ToString();
+ }
}
}
diff --git a/KustoSchemaTools/KustoSchemaTools.csproj b/KustoSchemaTools/KustoSchemaTools.csproj
index 3c3f282..28b02ef 100644
--- a/KustoSchemaTools/KustoSchemaTools.csproj
+++ b/KustoSchemaTools/KustoSchemaTools.csproj
@@ -7,6 +7,7 @@
+