@@ -76,23 +76,32 @@ export class PickPSHostProcessFeature implements IFeature {
76
76
77
77
// If PowerShell isn't finished loading yet, show a loading message
78
78
// until the LanguageClient is passed on to us
79
+ var cancelled = false ;
80
+ var timedOut = false ;
79
81
this . waitingForClientToken = new vscode . CancellationTokenSource ( ) ;
82
+
80
83
vscode . window
81
84
. showQuickPick (
82
85
[ "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..." } ,
84
87
this . waitingForClientToken . token )
85
- . then ( response => { if ( response === "Cancel" ) { this . clearWaitingToken ( ) ; } } ) ;
88
+ . then ( response => {
89
+ if ( response === "Cancel" ) {
90
+ this . clearWaitingToken ( ) ;
91
+ }
92
+ } ) ;
86
93
87
94
// Cancel the loading prompt after 60 seconds
88
95
setTimeout ( ( ) => {
89
96
if ( this . waitingForClientToken ) {
90
97
this . clearWaitingToken ( ) ;
91
98
92
99
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." ) ;
94
101
}
95
102
} , 60000 ) ;
103
+
104
+ // Wait w/timeout on language client to be initialized and then return this.pickPSHostProcess;
96
105
}
97
106
else {
98
107
return this . pickPSHostProcess ( ) ;
@@ -105,7 +114,7 @@ export class PickPSHostProcessFeature implements IFeature {
105
114
106
115
if ( this . waitingForClientToken ) {
107
116
this . clearWaitingToken ( ) ;
108
- return this . pickPSHostProcess ( ) ;
117
+ // Signal language client initialized
109
118
}
110
119
}
111
120
@@ -114,37 +123,36 @@ export class PickPSHostProcessFeature implements IFeature {
114
123
}
115
124
116
125
// 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
134
137
} ) ;
135
- }
136
- else {
137
- let options : vscode . QuickPickOptions = {
138
- placeHolder : "Select a PowerShell Host process to attach to" ,
139
- matchOnDescription : true ,
140
- matchOnDetail : true
141
138
} ;
142
139
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
+ } ) ;
148
156
}
149
157
150
158
private clearWaitingToken ( ) {
0 commit comments