Skip to content

Commit

Permalink
Merge pull request #105 from ironmansoftware/VariableFix
Browse files Browse the repository at this point in the history
Variable fix and PS Version fix.
  • Loading branch information
adamdriscoll authored Jan 2, 2025
2 parents c981b98 + 10217c9 commit 6789789
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 145 deletions.
7 changes: 7 additions & 0 deletions PowerShellProTools.SharedCommands/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ bool IsBaseType(object obj)

public Variable() { }

public Variable(string name, object value)
{
VarName = name;
VarValue = value?.ToString();
GetVariableInfo(value);
}

public Variable(PSVariable psVariable)
{
if (psVariable.Value != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace PowerShellTools.HostService.ServiceManagement.Debugging
public class PowerShellDebuggingService : PSHost, IHostSupportsInteractiveSession, IPowerShellDebuggingService
{
private PowerShell _currentPowerShell;
private string _varaiables;
private IEnumerable<Variable> _varaiables;
private IEnumerable<PSObject> _callstack;
private Collection<PSVariable> _localVariables;
private Dictionary<string, object> _propVariables;
Expand Down Expand Up @@ -901,18 +901,7 @@ public IEnumerable<Variable> GetScopedVariable()
ServiceCommon.Log("Failed to get variables. " + ex.Message);
}

if (string.IsNullOrEmpty(_varaiables))
{
yield break;
}

var variables = PSSerializer.Deserialize(_varaiables);

var varaibles = JsonConvert.DeserializeObject<Variable[]>(_varaiables);
foreach(var variable in varaibles)
{
yield return variable;
}
return _varaiables;
}

public IEnumerable<PowerShellProTools.Host.Module> GetModules()
Expand Down Expand Up @@ -1306,16 +1295,20 @@ private void RefreshScopedVariable()
var output = new PSDataCollection<PSObject>();
psCommand.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
Runspace.Debugger.ProcessCommand(psCommand, output);
_varaiables = output.FirstOrDefault()?.BaseObject.ToString();
_varaiables = output.OfType<PSObject>().Select(m => new Variable(m.Members[nameof(Variable.VarName)].Value.ToString(), m.Members[nameof(Variable.VarValue)].Value)
{
HasChildren = (bool)m.Members[nameof(Variable.HasChildren)].Value,
Path = m.Members[nameof(Variable.Path)].Value.ToString(),
Type = m.Members[nameof(Variable.Type)].Value.ToString()
});
}
else
{
using (var powershell = PowerShell.Create())
{
powershell.Runspace = Runspace;
powershell.AddScript("Get-Variable -Exclude @('foreach', 'switch') | Out-PoshToolsVariable -PassThru");
var json = powershell.Invoke<string>().FirstOrDefault();
_varaiables = json;
_varaiables = powershell.Invoke<Variable>();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@ public static PowerShellHostProcess CreatePowerShellHostProcess(string powershel
powershellPath = powershellLocator.PowerShellVersions[powershellLocator.DefaultVersion];
}

bool windowsPs = false;
if (powershellVersion != "Windows PowerShell (x86)" && powershellVersion != "Windows PowerShell (x64)")
{
powershellPath = powershellLocator.PowerShellVersions[powershellLocator.DefaultVersion];
}
else
{
windowsPs = true;
}
var windowsPs = powershellVersion.StartsWith("Windows PowerShell");

if (string.IsNullOrEmpty(powershellPath))
{
Expand Down
5 changes: 3 additions & 2 deletions PowerShellToolsPro.Cmdlets/PowerShellProTools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# Generated by: Ironman Software, LLC
#
# Generated on: 1/2/2025
#

@{
Expand All @@ -16,8 +17,8 @@ ModuleVersion = '2024.7.0'
# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this modul
GUID = '2439a3d7-b56b-4f35-81d1-05bc1c1ec287'
# ID used to uniquely identify this module
GUID = 'd58b50e7-7308-40ab-88d6-047d257369f9'

# Author of this module
Author = 'Ironman Software, LLC'
Expand Down
Loading

0 comments on commit 6789789

Please sign in to comment.