From 7e6ff7490ce51f7ef9adceae65adec7adbb29790 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 16 Mar 2017 07:35:20 -0700 Subject: [PATCH] Fix #562: Extension times out prematurely on long language server startup This change extends the timeout for language server startup to a full minute and also adds some startup logging to keep track of how long startup took. --- src/session.ts | 5 +++++ src/utils.ts | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/session.ts b/src/session.ts index 7e0de91c13..fad251e751 100644 --- a/src/session.ts +++ b/src/session.ts @@ -298,6 +298,8 @@ export class SessionManager { // Make sure no old session file exists utils.deleteSessionFile(); + this.log.write(`${utils.getTimestampString()} Language server starting...`); + // Launch PowerShell in the integrated terminal this.consoleTerminal = vscode.window.createTerminal( @@ -312,6 +314,8 @@ export class SessionManager { (sessionDetails, error) => { if (sessionDetails) { if (sessionDetails.status === "started") { + this.log.write(`${utils.getTimestampString()} Language server started.`); + // Write out the session configuration file utils.writeSessionFile(sessionDetails); @@ -332,6 +336,7 @@ export class SessionManager { } } else { + this.log.write(`${utils.getTimestampString()} Language server startup failed.`); this.setSessionFailure("Could not start language service: ", error); } }); diff --git a/src/utils.ts b/src/utils.ts index e474aa0f0d..0db0a5619b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -91,13 +91,15 @@ export function writeSessionFile(sessionDetails: EditorServicesSessionDetails) { export function waitForSessionFile(callback: WaitForSessionFileCallback) { - function innerTryFunc(remainingTries: number) { + function innerTryFunc(remainingTries: number, delayMilliseconds: number) { if (remainingTries == 0) { callback(undefined, "Timed out waiting for session file to appear."); } else if(!checkIfFileExists(sessionFilePath)) { // Wait a bit and try again - setTimeout(function() { innerTryFunc(remainingTries - 1); }, 500); + setTimeout( + function() { innerTryFunc(remainingTries - 1, delayMilliseconds); }, + delayMilliseconds); } else { // Session file was found, load and return it @@ -105,9 +107,8 @@ export function waitForSessionFile(callback: WaitForSessionFileCallback) { } } - // Since the delay is 500ms, 50 tries gives 25 seconds of time - // for the session file to appear - innerTryFunc(50); + // Try once per second for 60 seconds, one full minute + innerTryFunc(60, 1000); } export function readSessionFile(): EditorServicesSessionDetails { @@ -132,4 +133,9 @@ export function checkIfFileExists(filePath: string): boolean { catch (e) { return false; } -} \ No newline at end of file +} + +export function getTimestampString() { + var time = new Date(); + return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}]` +}