@@ -111,28 +111,28 @@ export class PowerShellProcess {
111
111
hideFromUser : this . sessionSettings . integratedConsole . startInBackground ,
112
112
} ;
113
113
114
+ // Subscribe a log event for when the terminal closes (this fires for
115
+ // all terminals and the event itself checks if it's our terminal). This
116
+ // subscription should happen before we create the terminal so if it
117
+ // fails immediately, the event fires.
118
+ this . consoleCloseSubscription = vscode . window . onDidCloseTerminal ( ( terminal ) => this . onTerminalClose ( terminal ) ) ;
119
+
114
120
this . consoleTerminal = vscode . window . createTerminal ( terminalOptions ) ;
115
121
116
122
const pwshName = path . basename ( this . exePath ) ;
117
123
this . logger . write ( `${ pwshName } started.` ) ;
118
124
125
+ // Log that the PowerShell terminal process has been started
126
+ const pid = await this . getPid ( ) ;
127
+ this . logTerminalPid ( pid ?? 0 , pwshName ) ;
128
+
119
129
if ( this . sessionSettings . integratedConsole . showOnStartup
120
130
&& ! this . sessionSettings . integratedConsole . startInBackground ) {
121
131
// We still need to run this to set the active terminal to the extension terminal.
122
132
this . consoleTerminal . show ( true ) ;
123
133
}
124
134
125
- // Start the language client
126
- const sessionDetails = await this . waitForSessionFile ( ) ;
127
-
128
- // Subscribe a log event for when the terminal closes
129
- this . consoleCloseSubscription = vscode . window . onDidCloseTerminal ( ( terminal ) => this . onTerminalClose ( terminal ) ) ;
130
-
131
- // Log that the PowerShell terminal process has been started
132
- const pid = await this . getPid ( ) ;
133
- this . logTerminalPid ( pid ?? 0 , pwshName ) ;
134
-
135
- return sessionDetails ;
135
+ return await this . waitForSessionFile ( ) ;
136
136
}
137
137
138
138
// This function should only be used after a failure has occurred because it is slow!
@@ -154,7 +154,7 @@ export class PowerShellProcess {
154
154
155
155
public async dispose ( ) : Promise < void > {
156
156
// Clean up the session file
157
- this . logger . write ( "Terminating PowerShell process ..." ) ;
157
+ this . logger . write ( "Disposing PowerShell Extension Terminal ..." ) ;
158
158
159
159
this . consoleTerminal ?. dispose ( ) ;
160
160
this . consoleTerminal = undefined ;
@@ -199,8 +199,8 @@ export class PowerShellProcess {
199
199
private static async deleteSessionFile ( sessionFilePath : vscode . Uri ) : Promise < void > {
200
200
try {
201
201
await vscode . workspace . fs . delete ( sessionFilePath ) ;
202
- } catch ( e ) {
203
- // TODO: Be more specific about what we're catching
202
+ } catch {
203
+ // We don't care about any reasons for it to fail.
204
204
}
205
205
}
206
206
@@ -212,6 +212,12 @@ export class PowerShellProcess {
212
212
// Check every 2 seconds
213
213
this . logger . write ( "Waiting for session file..." ) ;
214
214
for ( let i = numOfTries ; i > 0 ; i -- ) {
215
+ if ( this . consoleTerminal === undefined ) {
216
+ const err = "PowerShell Extension Terminal didn't start!" ;
217
+ this . logger . write ( err ) ;
218
+ throw new Error ( err ) ;
219
+ }
220
+
215
221
if ( await utils . checkIfFileExists ( this . sessionFilePath ) ) {
216
222
this . logger . write ( "Session file found!" ) ;
217
223
const sessionDetails = await PowerShellProcess . readSessionFile ( this . sessionFilePath ) ;
@@ -237,7 +243,8 @@ export class PowerShellProcess {
237
243
return ;
238
244
}
239
245
240
- this . logger . write ( "powershell.exe terminated or terminal UI was closed" ) ;
246
+ this . logger . write ( "PowerShell process terminated or Extension Terminal was closed! " ) ;
241
247
this . onExitedEmitter . fire ( ) ;
248
+ void this . dispose ( ) ;
242
249
}
243
250
}
0 commit comments