Skip to content

Commit d392fce

Browse files
committed
Fix #29: Variables should use proper '$' notation
This change adds the dollar sign '$' character to top-level variables that are retrieved using the Get-Variables command via the DebugService. This character is used to refer to variables in PowerShell scripts so we need to add it to variable names that are returned from the debugging service for the sake of consistency.
1 parent 9669da3 commit d392fce

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/PowerShellEditorServices/Debugging/VariableDetails.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class VariableDetails
2020
{
2121
#region Fields
2222

23+
/// <summary>
24+
/// Provides a constant for the dollar sign variable prefix string.
25+
/// </summary>
26+
public const string DollarPrefix = "$";
27+
2328
/// <summary>
2429
/// Provides a constant for the variable ID of the local variable scope.
2530
/// </summary>
@@ -79,7 +84,7 @@ public class VariableDetails
7984
/// The PSVariable instance from which variable details will be obtained.
8085
/// </param>
8186
public VariableDetails(PSVariable psVariable)
82-
: this(psVariable.Name, psVariable.Value)
87+
: this(DollarPrefix + psVariable.Name, psVariable.Value)
8388
{
8489
}
8590

@@ -105,8 +110,8 @@ public VariableDetails(string name, object value)
105110
{
106111
this.valueObject = value;
107112

108-
this.IsExpandable = GetIsExpandable(value);
109113
this.Name = name;
114+
this.IsExpandable = GetIsExpandable(value);
110115
this.ValueString =
111116
this.IsExpandable == false ?
112117
GetValueString(value) :

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,25 @@ await this.debugService.SetBreakpoints(
177177

178178
// TODO: Add checks for correct value strings as well
179179

180-
var strVar = variables.FirstOrDefault(v => v.Name == "strVar");
180+
var strVar = variables.FirstOrDefault(v => v.Name == "$strVar");
181181
Assert.NotNull(strVar);
182182
Assert.False(strVar.IsExpandable);
183183

184-
var objVar = variables.FirstOrDefault(v => v.Name == "objVar");
184+
var objVar = variables.FirstOrDefault(v => v.Name == "$objVar");
185185
Assert.NotNull(objVar);
186186
Assert.True(objVar.IsExpandable);
187187

188188
var objChildren = debugService.GetVariables(objVar.Id);
189189
Assert.Equal(2, objChildren.Length);
190190

191-
var arrVar = variables.FirstOrDefault(v => v.Name == "arrVar");
191+
var arrVar = variables.FirstOrDefault(v => v.Name == "$arrVar");
192192
Assert.NotNull(arrVar);
193193
Assert.True(arrVar.IsExpandable);
194194

195195
var arrChildren = debugService.GetVariables(arrVar.Id);
196196
Assert.Equal(4, arrChildren.Length);
197197

198-
var classVar = variables.FirstOrDefault(v => v.Name == "classVar");
198+
var classVar = variables.FirstOrDefault(v => v.Name == "$classVar");
199199
Assert.NotNull(classVar);
200200
Assert.True(classVar.IsExpandable);
201201

0 commit comments

Comments
 (0)