Skip to content

Commit 0edeed4

Browse files
committed
Feature: Add "Raw View" to IEnumerables and IDictionaries
1 parent 3c5a7ae commit 0edeed4

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Diagnostics;
88
using System.Linq;
9+
using System.Linq.Expressions;
910
using System.Management.Automation;
1011
using System.Reflection;
1112
using Microsoft.Extensions.Logging;
@@ -27,7 +28,7 @@ internal class VariableDetails : VariableDetailsBase
2728
/// </summary>
2829
public const string DollarPrefix = "$";
2930

30-
private object valueObject;
31+
protected object valueObject;
3132
private VariableDetails[] cachedChildren;
3233

3334
#endregion
@@ -366,10 +367,23 @@ private VariableDetails[] GetChildren(object obj, ILogger logger)
366367

367368
return childVariables.ToArray();
368369
}
369-
370-
private static void AddDotNetProperties(object obj, List<VariableDetails> childVariables)
370+
protected static void AddDotNetProperties(object obj, List<VariableDetails> childVariables, bool noRawView = false)
371371
{
372372
Type objectType = obj.GetType();
373+
374+
// For certain array or dictionary types, we want to hide additional properties under a "raw view" header
375+
// to reduce noise. This is inspired by the C# vscode extension.
376+
if (!noRawView &&
377+
(
378+
obj is IEnumerable
379+
|| obj is IDictionary
380+
)
381+
)
382+
{
383+
childVariables.Add(new VariableDetailsRawView(obj));
384+
return;
385+
}
386+
373387
var properties =
374388
objectType.GetProperties(
375389
BindingFlags.Public | BindingFlags.Instance);
@@ -424,4 +438,19 @@ public override string ToString()
424438
}
425439
}
426440
}
441+
442+
/// <summary>
443+
/// A VariableDetails that only returns the raw view properties of the object, rather than its values.
444+
/// </summary>
445+
internal class VariableDetailsRawView : VariableDetails
446+
{
447+
private const string RawViewName = "Raw View";
448+
public VariableDetailsRawView(object value) : base(RawViewName, value) { }
449+
public override VariableDetailsBase[] GetChildren(ILogger logger)
450+
{
451+
List<VariableDetails> childVariables = new();
452+
AddDotNetProperties(valueObject, childVariables, noRawView: true);
453+
return childVariables.ToArray();
454+
}
455+
}
427456
}

0 commit comments

Comments
 (0)