@@ -76,23 +76,32 @@ export class PickPSHostProcessFeature implements IFeature {
7676
7777 // If PowerShell isn't finished loading yet, show a loading message 
7878 // until the LanguageClient is passed on to us 
79+  var  cancelled  =  false ; 
80+  var  timedOut  =  false ; 
7981 this . waitingForClientToken  =  new  vscode . CancellationTokenSource ( ) ; 
82+ 
8083 vscode . window 
8184 . showQuickPick ( 
8285 [ "Cancel" ] , 
83-  {  placeHolder : "Select PowerShell Host Process  to attach to : Please wait, starting PowerShell..."  } , 
86+  {  placeHolder : "Attach  to PowerShell host process : Please wait, starting PowerShell..."  } , 
8487 this . waitingForClientToken . token ) 
85-  . then ( response  =>  {  if  ( response  ===  "Cancel" )  {  this . clearWaitingToken ( ) ;  }  } ) ; 
88+  . then ( response  =>  { 
89+  if  ( response  ===  "Cancel" )  { 
90+  this . clearWaitingToken ( ) ; 
91+  } 
92+  } ) ; 
8693
8794 // Cancel the loading prompt after 60 seconds 
8895 setTimeout ( ( )  =>  { 
8996 if  ( this . waitingForClientToken )  { 
9097 this . clearWaitingToken ( ) ; 
9198
9299 vscode . window . showErrorMessage ( 
93-  "Select PowerShell Host Process  to attach to : PowerShell session took too long to start." ) ; 
100+  "Attach  to PowerShell host process : PowerShell session took too long to start." ) ; 
94101 } 
95102 } ,  60000 ) ; 
103+ 
104+  // Wait w/timeout on language client to be initialized and then return this.pickPSHostProcess; 
96105 } 
97106 else  { 
98107 return  this . pickPSHostProcess ( ) ; 
@@ -105,7 +114,7 @@ export class PickPSHostProcessFeature implements IFeature {
105114
106115 if  ( this . waitingForClientToken )  { 
107116 this . clearWaitingToken ( ) ; 
108-  return   this . pickPSHostProcess ( ) ; 
117+  // Signal language client initialized 
109118 } 
110119 } 
111120
@@ -114,37 +123,36 @@ export class PickPSHostProcessFeature implements IFeature {
114123 } 
115124
116125 // In node, the function returned a Promise<string> not sure about "Thenable<string>" 
117- private  pickPSHostProcess ( ) : Thenable < string >  { 
118- return  this . languageClient . sendRequest ( GetPSHostProcessesRequest . type ,  null ) . then ( hostProcesses  =>  { 
119- var  items : ProcessItem [ ]  =  [ ] ; 
120- 
121- for ( var  p  in  hostProcesses )  { 
122- items . push ( { 
123- label : hostProcesses [ p ] . processName , 
124-  description : hostProcesses [ p ] . processId . toString ( ) , 
125- detail : hostProcesses [ p ] . mainWindowTitle , 
126- pid : hostProcesses [ p ] . processId 
127-  } ) ; 
128- } ; 
129- 
130-  if  ( items . length  ===  0 )  { 
131-  return  vscode . window . showInformationMessage ( 
132-  "There are no other PowerShell host processes to attach to." ) . then ( _  =>  { 
133-  return  null ; 
126+ private  pickPSHostProcess ( ) : Promise < string >  { 
127+  return  new  Promise ( ( resolve ,  reject )  =>  { 
128+  this . languageClient . sendRequest ( GetPSHostProcessesRequest . type ,  null ) . then ( hostProcesses  =>  { 
129+  var  items : ProcessItem [ ]  =  [ ] ; 
130+ 
131+  for ( var  p  in  hostProcesses )  { 
132+  items . push ( { 
133+  label : hostProcesses [ p ] . processName , 
134+  description : hostProcesses [ p ] . processId . toString ( ) , 
135+  detail : hostProcesses [ p ] . mainWindowTitle , 
136+  pid : hostProcesses [ p ] . processId 
134137 } ) ; 
135-  } 
136-  else  { 
137-  let  options  : vscode . QuickPickOptions  =  { 
138-  placeHolder : "Select a PowerShell Host process to attach to" , 
139-  matchOnDescription : true , 
140-  matchOnDetail : true 
141138 } ; 
142139
143-  return  vscode . window . showQuickPick ( items ,  options ) . then ( item  =>  { 
144-  return  item  ? item . pid  : null ; 
145-  } ) ; 
146-  } 
147- } ) ; 
140+  if  ( items . length  ===  0 )  { 
141+  reject ( "There are no PowerShell host processes to attach to." ) ; 
142+  } 
143+  else  { 
144+  let  options  : vscode . QuickPickOptions  =  { 
145+  placeHolder : "Select a PowerShell host process to attach to" , 
146+  matchOnDescription : true , 
147+  matchOnDetail : true 
148+  } ; 
149+ 
150+  return  vscode . window . showQuickPick ( items ,  options ) . then ( item  =>  { 
151+  resolve ( item  ? item . pid  : "" ) ; 
152+  } ) ; 
153+  } 
154+  } ) ; 
155+  } ) ; 
148156} 
149157
150158 private  clearWaitingToken ( )  { 
0 commit comments