Rkeithhill/fix getvariables failed #108
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Fix for Get-Variable -Scope doesn't always work.
Ideally we should be using CallStackFrame.GetFrameVariables() but it currently seems to be broken. We've been informed that using Get-Variable -Scope isn't great because scope numbers and frames don't always line up. For instance, dot source introducing a new stack frame but not a new scope. But until GetFrameVariables is fixed in a future drop, we have no option but to use Get-Variable -Scope . This will result in stack frames that have no Auto or Local variables. But the good news is that the debug host will no longer crash. :-)
BTW this commit introduces a new optional parameter on PowerShellContext.ExecuteCommand(). While there is a parameter to suppress "output" there was no parameter to suppress "errors" from being written to the debug console. I see no benefit in littering the user's debug console with a bunch of "get-variable : The scope number '#' exceeds the number of active scopes". So there is now a "sendErrorToHost" parameter that defaults to true. However, even when that parameter is set to false, the error info shows up in the DebugAdapter.log file.