@@ -73,26 +73,38 @@ export class PickPSHostProcessFeature implements IFeature {
7373 vscode . commands . registerCommand ( 'PowerShell.PickPSHostProcess' , ( ) => {
7474
7575 if ( ! this . languageClient && ! this . waitingForClientToken ) {
76+ return new Promise < string > ( ( resolve , reject ) => {
77+ reject ( "PowerShell has not fully initialized. Try to attach again after PowerShell has been initialized." ) ;
78+ } ) ;
7679
77- // If PowerShell isn't finished loading yet, show a loading message
78- // until the LanguageClient is passed on to us
79- this . waitingForClientToken = new vscode . CancellationTokenSource ( ) ;
80- vscode . window
81- . showQuickPick (
82- [ "Cancel" ] ,
83- { placeHolder : "Select PowerShell Host Process to attach to: Please wait, starting PowerShell..." } ,
84- this . waitingForClientToken . token )
85- . then ( response => { if ( response === "Cancel" ) { this . clearWaitingToken ( ) ; } } ) ;
86-
87- // Cancel the loading prompt after 60 seconds
88- setTimeout ( ( ) => {
89- if ( this . waitingForClientToken ) {
90- this . clearWaitingToken ( ) ;
91-
92- vscode . window . showErrorMessage (
93- "Select PowerShell Host Process to attach to: PowerShell session took too long to start." ) ;
94- }
95- } , 60000 ) ;
80+ // // If PowerShell isn't finished loading yet, show a loading message
81+ // // until the LanguageClient is passed on to us
82+ // var cancelled = false;
83+ // var timedOut = false;
84+ // this.waitingForClientToken = new vscode.CancellationTokenSource();
85+
86+ // vscode.window
87+ // .showQuickPick(
88+ // ["Cancel"],
89+ // { placeHolder: "Attach to PowerShell host process: Please wait, starting PowerShell..." },
90+ // this.waitingForClientToken.token)
91+ // .then(response => {
92+ // if (response === "Cancel") {
93+ // this.clearWaitingToken();
94+ // }
95+ // });
96+
97+ // // Cancel the loading prompt after 60 seconds
98+ // setTimeout(() => {
99+ // if (this.waitingForClientToken) {
100+ // this.clearWaitingToken();
101+
102+ // vscode.window.showErrorMessage(
103+ // "Attach to PowerShell host process: PowerShell session took too long to start.");
104+ // }
105+ // }, 60000);
106+
107+ // // Wait w/timeout on language client to be initialized and then return this.pickPSHostProcess;
96108 }
97109 else {
98110 return this . pickPSHostProcess ( ) ;
@@ -105,7 +117,7 @@ export class PickPSHostProcessFeature implements IFeature {
105117
106118 if ( this . waitingForClientToken ) {
107119 this . clearWaitingToken ( ) ;
108- return this . pickPSHostProcess ( ) ;
120+ // Signal language client initialized
109121 }
110122 }
111123
@@ -114,37 +126,36 @@ export class PickPSHostProcessFeature implements IFeature {
114126 }
115127
116128 // 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 ;
129+ private pickPSHostProcess ( ) : Promise < string > {
130+ return new Promise ( ( resolve , reject ) => {
131+ this . languageClient . sendRequest ( GetPSHostProcessesRequest . type , null ) . then ( hostProcesses => {
132+ var items : ProcessItem [ ] = [ ] ;
133+
134+ for ( var p in hostProcesses ) {
135+ items . push ( {
136+ label : hostProcesses [ p ] . processName ,
137+ description : hostProcesses [ p ] . processId . toString ( ) ,
138+ detail : hostProcesses [ p ] . mainWindowTitle ,
139+ pid : hostProcesses [ p ] . processId
134140 } ) ;
135- }
136- else {
137- let options : vscode . QuickPickOptions = {
138- placeHolder : "Select a PowerShell Host process to attach to" ,
139- matchOnDescription : true ,
140- matchOnDetail : true
141141 } ;
142142
143- return vscode . window . showQuickPick ( items , options ) . then ( item => {
144- return item ? item . pid : null ;
145- } ) ;
146- }
147- } ) ;
143+ if ( items . length === 0 ) {
144+ reject ( "There are no PowerShell host processes to attach to." ) ;
145+ }
146+ else {
147+ let options : vscode . QuickPickOptions = {
148+ placeHolder : "Select a PowerShell host process to attach to" ,
149+ matchOnDescription : true ,
150+ matchOnDetail : true
151+ } ;
152+
153+ return vscode . window . showQuickPick ( items , options ) . then ( item => {
154+ resolve ( item ? item . pid : "" ) ;
155+ } ) ;
156+ }
157+ } ) ;
158+ } ) ;
148159 }
149160
150161 private clearWaitingToken ( ) {
0 commit comments