(
cancellationToken: vscode.CancellationToken,
)
| 277 | } |
| 278 | |
| 279 | private async waitForSessionFile( |
| 280 | cancellationToken: vscode.CancellationToken, |
| 281 | ): Promise<IEditorServicesSessionDetails | undefined> { |
| 282 | const numOfTries = // We sleep for 1/5 of a second each try |
| 283 | 5 * this.sessionSettings.developer.waitForSessionFileTimeoutSeconds; |
| 284 | const warnAt = numOfTries - 5 * 30; // Warn at 30 seconds |
| 285 | |
| 286 | // Check every second. |
| 287 | this.logger.writeDebug( |
| 288 | `Waiting for session file: ${this.sessionFilePath}`, |
| 289 | ); |
| 290 | for (let i = numOfTries; i > 0; i--) { |
| 291 | if (cancellationToken.isCancellationRequested) { |
| 292 | this.logger.writeWarning( |
| 293 | "Canceled while waiting for session file.", |
| 294 | ); |
| 295 | return undefined; |
| 296 | } |
| 297 | |
| 298 | if (this.consoleTerminal === undefined) { |
| 299 | this.logger.writeError("Extension Terminal is undefined."); |
| 300 | return undefined; |
| 301 | } |
| 302 | |
| 303 | if (await utils.checkIfFileExists(this.sessionFilePath)) { |
| 304 | this.logger.writeDebug("Session file found."); |
| 305 | return await this.readSessionFile(this.sessionFilePath); |
| 306 | } |
| 307 | |
| 308 | if (warnAt === i) { |
| 309 | void this.logger.writeAndShowWarning( |
| 310 | "Loading the PowerShell extension is taking longer than expected. If you're using privilege enforcement software, this can affect start up performance.", |
| 311 | ); |
| 312 | } |
| 313 | |
| 314 | // Wait 1/5 of a second and try again |
| 315 | await utils.sleep(200); |
| 316 | } |
| 317 | |
| 318 | this.logger.writeError("Timed out waiting for session file!"); |
| 319 | return undefined; |
| 320 | } |
| 321 | |
| 322 | private onTerminalClose(terminal: vscode.Terminal): void { |
| 323 | if (terminal !== this.consoleTerminal) { |
no test coverage detected