Skip to content

Commit 174b74d

Browse files
committed
Handle invoke of getPSHostProcesses on < PS v5.
1 parent 65d5bc5 commit 174b74d

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -932,27 +932,30 @@ protected async Task HandleGetPSHostProcessesRequest(
932932
{
933933
var psHostProcesses = new List<GetPSHostProcessesResponse>();
934934

935-
int processId = System.Diagnostics.Process.GetCurrentProcess().Id;
936-
var psCommand = new PSCommand();
937-
psCommand.AddCommand("Get-PSHostProcessInfo");
938-
psCommand.AddCommand("Where-Object")
939-
.AddParameter("Property", "ProcessId")
940-
.AddParameter("NE")
941-
.AddParameter("Value", processId.ToString());
942-
943-
var processes = await editorSession.PowerShellContext.ExecuteCommand<PSObject>(psCommand);
944-
if (processes != null)
935+
if (this.editorSession.PowerShellContext.LocalPowerShellVersion.Version.Major >= 5)
945936
{
946-
foreach (dynamic p in processes)
937+
int processId = System.Diagnostics.Process.GetCurrentProcess().Id;
938+
var psCommand = new PSCommand();
939+
psCommand.AddCommand("Get-PSHostProcessInfo");
940+
psCommand.AddCommand("Where-Object")
941+
.AddParameter("Property", "ProcessId")
942+
.AddParameter("NE")
943+
.AddParameter("Value", processId.ToString());
944+
945+
var processes = await editorSession.PowerShellContext.ExecuteCommand<PSObject>(psCommand);
946+
if (processes != null)
947947
{
948-
psHostProcesses.Add(
949-
new GetPSHostProcessesResponse
950-
{
951-
ProcessName = p.ProcessName,
952-
ProcessId = p.ProcessId,
953-
AppDomainName = p.AppDomainName,
954-
MainWindowTitle = p.MainWindowTitle
955-
});
948+
foreach (dynamic p in processes)
949+
{
950+
psHostProcesses.Add(
951+
new GetPSHostProcessesResponse
952+
{
953+
ProcessName = p.ProcessName,
954+
ProcessId = p.ProcessId,
955+
AppDomainName = p.AppDomainName,
956+
MainWindowTitle = p.MainWindowTitle
957+
});
958+
}
956959
}
957960
}
958961

0 commit comments

Comments
 (0)