@@ -123,6 +123,8 @@ protected override void Initialize()
123123 this . SetRequestHandler ( GetPSSARulesRequest . Type , this . HandleGetPSSARulesRequest ) ;
124124 this . SetRequestHandler ( SetPSSARulesRequest . Type , this . HandleSetPSSARulesRequest ) ;
125125
126+ this . SetRequestHandler ( GetPSHostProcessesRequest . Type , this . HandleGetPSHostProcessesRequest ) ;
127+
126128 // Initialize the extension service
127129 // TODO: This should be made awaited once Initialize is async!
128130 this . editorSession . ExtensionService . Initialize (
@@ -924,6 +926,42 @@ await requestContext.SendResult(
924926 this . editorSession . PowerShellContext . LocalPowerShellVersion ) ) ;
925927 }
926928
929+ protected async Task HandleGetPSHostProcessesRequest (
930+ object noParams ,
931+ RequestContext < GetPSHostProcessesResponse [ ] > requestContext )
932+ {
933+ var psHostProcesses = new List < GetPSHostProcessesResponse > ( ) ;
934+
935+ if ( this . editorSession . PowerShellContext . LocalPowerShellVersion . Version . Major >= 5 )
936+ {
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 )
947+ {
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+ }
959+ }
960+ }
961+
962+ await requestContext . SendResult ( psHostProcesses . ToArray ( ) ) ;
963+ }
964+
927965 private bool IsQueryMatch ( string query , string symbolName )
928966 {
929967 return symbolName . IndexOf ( query , StringComparison . OrdinalIgnoreCase ) >= 0 ;
0 commit comments