-
Notifications
You must be signed in to change notification settings - Fork 238
Description
VSCode added the ability to set a variable in the debugger’s Variables window as long as a debug extension declares support for such a feature. I’m currently working on adding that support to PSES. But a question has cropped up that I’d like to get your feedback on. Given that a variable in your script is type [int] at runtime, would you expect the debugger to “strictly” convert a “new value string” (you typed into the UI) to type [int] and fail if not convertible? Or would you expect it to change the type if necessary? That is, if you changed the value of $i (type int) to “42a” should that fail or set the value to [string] “42a”? Would that be weird?
Where the ability to change type comes in handy is when you have an optional parameter $p that is initially set to $null (no type). Setting that to string “Foo” or int 42 seems like something you’d want (which will set the type to [string] or [int] in this case). And I think you would want to be able to set the value back to $null – wiping out the previous type. There are also variables declared like [int]$i
. Should the debugger allow the type to be changed for a variable declared as strongly typed? I lean towards not changing the type – assuming I can tell at runtime the variable was declared like that (presence of ArgumentTypeConverterAttribute?).
I guess I have a bit of VS bias where it doesn’t allow you to change types of variables in the debugger but I think you would want this in a debugger for the “type promiscuous” PowerShell.
The attached animated GIF shows using the VSCode UI for this feature: