From 57613460441f5b7cbf27e708e9d1ecce4a15847e Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Wed, 18 Sep 2024 15:36:51 -0700 Subject: [PATCH] Display parameter names in a structured way Fixes #817 --- src/StructuredLogViewer/themes/Generic.xaml | 37 +++++++++++++++ .../Construction/MessageProcessor.cs | 47 ++++++++++++++----- src/StructuredLogger/ObjectModel/AddItem.cs | 5 ++ src/StructuredLogger/ObjectModel/Parameter.cs | 2 + src/StructuredLogger/ObjectModel/Property.cs | 5 ++ 5 files changed, 85 insertions(+), 11 deletions(-) diff --git a/src/StructuredLogViewer/themes/Generic.xaml b/src/StructuredLogViewer/themes/Generic.xaml index 311347d93..d97d8addc 100644 --- a/src/StructuredLogViewer/themes/Generic.xaml +++ b/src/StructuredLogViewer/themes/Generic.xaml @@ -439,6 +439,28 @@ + + + + + + + + + + + + + + @@ -571,11 +593,26 @@ + + + + + + + + + + + + + + + diff --git a/src/StructuredLogger/Construction/MessageProcessor.cs b/src/StructuredLogger/Construction/MessageProcessor.cs index da32fb96c..9932d1dd0 100644 --- a/src/StructuredLogger/Construction/MessageProcessor.cs +++ b/src/StructuredLogger/Construction/MessageProcessor.cs @@ -198,11 +198,9 @@ private void ProcessTaskParameter(TaskParameterEventArgs args) parent = task.GetOrCreateNodeWithName(folderName); parent.DisableChildrenCache = true; - string itemName = isOutput && parameterName is not null - ? $"{propertyName ?? itemType} from parameter {parameterName}" - : propertyName ?? itemType; + string itemName = propertyName ?? itemType; - node = CreateParameterNode(itemName, items, isOutput); + node = CreateParameterNode(itemName, items, isOutput, parameterName); } else if ( kind == TaskParameterMessageKind.AddItem || @@ -254,26 +252,53 @@ private void ProcessTaskParameter(TaskParameterEventArgs args) } } - private BaseNode CreateParameterNode(string itemName, IEnumerable items, bool isOutput = false) + private BaseNode CreateParameterNode(string itemName, IEnumerable items, bool isOutput = false, string parameterName = null) { if (items is IList list && list.Count == 1 && list[0] is ITaskItem scalar && scalar.MetadataCount == 0) { - var property = new Property + BaseNode property; + if (parameterName != null && parameterName != itemName) { - Name = itemName, - Value = scalar.ItemSpec - }; + property = new TaskParameterProperty + { + Name = itemName, + Value = scalar.ItemSpec, + ParameterName = parameterName + }; + } + else + { + property = new Property + { + Name = itemName, + Value = scalar.ItemSpec + }; + } + return property; } TreeNode parent; if (isOutput) { - parent = new AddItem { Name = itemName }; + if (!string.IsNullOrEmpty(parameterName) && parameterName != itemName) + { + parent = new TaskParameterItem { Name = itemName, ParameterName = parameterName }; + } + else + { + parent = new AddItem { Name = itemName }; + } } else { - parent = new Parameter { Name = itemName }; + // no need to display the same string twice + if (parameterName == itemName) + { + parameterName = null; + } + + parent = new Parameter { Name = itemName, ParameterName = parameterName }; parent.DisableChildrenCache = true; } diff --git a/src/StructuredLogger/ObjectModel/AddItem.cs b/src/StructuredLogger/ObjectModel/AddItem.cs index 199b9b247..da874aee0 100644 --- a/src/StructuredLogger/ObjectModel/AddItem.cs +++ b/src/StructuredLogger/ObjectModel/AddItem.cs @@ -11,4 +11,9 @@ public AddItem() public int? LineNumber { get; set; } } + + public class TaskParameterItem : AddItem + { + public string ParameterName { get; set; } + } } diff --git a/src/StructuredLogger/ObjectModel/Parameter.cs b/src/StructuredLogger/ObjectModel/Parameter.cs index b99c16a5d..b4fb6b6dd 100644 --- a/src/StructuredLogger/ObjectModel/Parameter.cs +++ b/src/StructuredLogger/ObjectModel/Parameter.cs @@ -3,5 +3,7 @@ public class Parameter : NamedNode { public override string TypeName => nameof(Parameter); + + public string ParameterName { get; set; } } } diff --git a/src/StructuredLogger/ObjectModel/Property.cs b/src/StructuredLogger/ObjectModel/Property.cs index 03c1601e1..2fe317520 100644 --- a/src/StructuredLogger/ObjectModel/Property.cs +++ b/src/StructuredLogger/ObjectModel/Property.cs @@ -4,4 +4,9 @@ public class Property : NameValueNode { public override string TypeName => nameof(Property); } + + public class TaskParameterProperty : Property + { + public string ParameterName { get; set; } + } }