Skip to content

Commit 29cfe73

Browse files
JustinGroteandyleejordan
authored andcommitted
Add Command variables container
1 parent 0bd5490 commit 29cfe73

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,12 @@ public VariableScope[] GetVariableScopes(int stackFrameId)
609609
{
610610
var stackFrames = GetStackFrames();
611611
int autoVariablesId = stackFrames[stackFrameId].AutoVariables.Id;
612+
int commandVariablesId = stackFrames[stackFrameId].CommandVariables.Id;
612613

613614
return new VariableScope[]
614615
{
615616
new VariableScope(autoVariablesId, VariableContainerDetails.AutoVariablesName),
617+
new VariableScope(commandVariablesId, VariableContainerDetails.CommandVariablesName),
616618
new VariableScope(localScopeVariables.Id, VariableContainerDetails.LocalScopeName),
617619
new VariableScope(scriptScopeVariables.Id, VariableContainerDetails.ScriptScopeName),
618620
new VariableScope(globalScopeVariables.Id, VariableContainerDetails.GlobalScopeName),
@@ -810,6 +812,12 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
810812

811813
variables.Add(autoVariables);
812814

815+
var commandVariables = new VariableContainerDetails(
816+
nextVariableId++,
817+
VariableContainerDetails.CommandVariablesName);
818+
819+
variables.Add(commandVariables);
820+
813821
foreach (DictionaryEntry entry in callStackVariables)
814822
{
815823
// TODO: This should be deduplicated into a new function.
@@ -823,13 +831,14 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
823831
var variableDetails = new VariableDetails(psVarName, psVarValue) { Id = nextVariableId++ };
824832
variables.Add(variableDetails);
825833

834+
commandVariables.Children.Add(variableDetails.Name, variableDetails);
826835
if (AddToAutoVariables(new PSObject(entry.Value)))
827836
{
828837
autoVariables.Children.Add(variableDetails.Name, variableDetails);
829838
}
830839
}
831840

832-
var stackFrameDetailsEntry = StackFrameDetails.Create(callStackFrame, autoVariables);
841+
var stackFrameDetailsEntry = StackFrameDetails.Create(callStackFrame, autoVariables, commandVariables);
833842

834843
string stackFrameScriptPath = stackFrameDetailsEntry.ScriptPath;
835844
if (scriptNameOverride is not null

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ internal class StackFrameDetails
6464
/// </summary>
6565
public VariableContainerDetails AutoVariables { get; private set; }
6666

67+
/// <summary>
68+
/// Gets or sets the VariableContainerDetails that contains the call stack frame variables.
69+
/// </summary>
70+
public VariableContainerDetails CommandVariables { get; private set; }
71+
6772
#endregion
6873

6974
#region Constructors
@@ -81,7 +86,8 @@ internal class StackFrameDetails
8186
/// <returns>A new instance of the StackFrameDetails class.</returns>
8287
static internal StackFrameDetails Create(
8388
PSObject callStackFrameObject,
84-
VariableContainerDetails autoVariables)
89+
VariableContainerDetails autoVariables,
90+
VariableContainerDetails commandVariables)
8591
{
8692
string scriptPath = (callStackFrameObject.Properties["ScriptName"].Value as string) ?? NoFileScriptPath;
8793
int startLineNumber = (int)(callStackFrameObject.Properties["ScriptLineNumber"].Value ?? 0);
@@ -95,6 +101,7 @@ static internal StackFrameDetails Create(
95101
StartColumnNumber = 0, // Column number isn't given in PowerShell stack frames
96102
EndColumnNumber = 0,
97103
AutoVariables = autoVariables,
104+
CommandVariables = commandVariables,
98105
// TODO: Re-enable `isExternal` detection along with a setting. Will require
99106
// `workspaceRootPath`, see Git blame.
100107
IsExternalCode = false

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter
2020
internal class VariableContainerDetails : VariableDetailsBase
2121
{
2222
/// <summary>
23-
/// Provides a constant for the name of the Global scope.
23+
/// Provides a constant for the name of the filtered auto variables.
2424
/// </summary>
2525
public const string AutoVariablesName = "Auto";
2626

2727
/// <summary>
28-
/// Provides a constant for the name of the Global scope.
28+
/// Provides a constant for the name of the current stack frame variables.
29+
/// </summary>
30+
public const string CommandVariablesName = "Command";
31+
32+
/// <summary>
33+
/// Provides a constant for the name of the global scope variables.
2934
/// </summary>
3035
public const string GlobalScopeName = "Global";
3136

3237
/// <summary>
33-
/// Provides a constant for the name of the Local scope.
38+
/// Provides a constant for the name of the local scope variables.
3439
/// </summary>
3540
public const string LocalScopeName = "Local";
3641

0 commit comments

Comments
 (0)