Skip to content

Fix #562: Extension times out prematurely on long language server startup #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);

Expand All @@ -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);
}
});
Expand Down
18 changes: 12 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,24 @@ 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
callback(readSessionFile(), undefined);
}
}

// 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 {
Expand All @@ -132,4 +133,9 @@ export function checkIfFileExists(filePath: string): boolean {
catch (e) {
return false;
}
}
}

export function getTimestampString() {
var time = new Date();
return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}]`
}