Skip to content

Commit 7e6ff74

Browse files
committed
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.
1 parent 409763a commit 7e6ff74

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/session.ts

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ export class SessionManager {
298298
// Make sure no old session file exists
299299
utils.deleteSessionFile();
300300

301+
this.log.write(`${utils.getTimestampString()} Language server starting...`);
302+
301303
// Launch PowerShell in the integrated terminal
302304
this.consoleTerminal =
303305
vscode.window.createTerminal(
@@ -312,6 +314,8 @@ export class SessionManager {
312314
(sessionDetails, error) => {
313315
if (sessionDetails) {
314316
if (sessionDetails.status === "started") {
317+
this.log.write(`${utils.getTimestampString()} Language server started.`);
318+
315319
// Write out the session configuration file
316320
utils.writeSessionFile(sessionDetails);
317321

@@ -332,6 +336,7 @@ export class SessionManager {
332336
}
333337
}
334338
else {
339+
this.log.write(`${utils.getTimestampString()} Language server startup failed.`);
335340
this.setSessionFailure("Could not start language service: ", error);
336341
}
337342
});

src/utils.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,24 @@ export function writeSessionFile(sessionDetails: EditorServicesSessionDetails) {
9191

9292
export function waitForSessionFile(callback: WaitForSessionFileCallback) {
9393

94-
function innerTryFunc(remainingTries: number) {
94+
function innerTryFunc(remainingTries: number, delayMilliseconds: number) {
9595
if (remainingTries == 0) {
9696
callback(undefined, "Timed out waiting for session file to appear.");
9797
}
9898
else if(!checkIfFileExists(sessionFilePath)) {
9999
// Wait a bit and try again
100-
setTimeout(function() { innerTryFunc(remainingTries - 1); }, 500);
100+
setTimeout(
101+
function() { innerTryFunc(remainingTries - 1, delayMilliseconds); },
102+
delayMilliseconds);
101103
}
102104
else {
103105
// Session file was found, load and return it
104106
callback(readSessionFile(), undefined);
105107
}
106108
}
107109

108-
// Since the delay is 500ms, 50 tries gives 25 seconds of time
109-
// for the session file to appear
110-
innerTryFunc(50);
110+
// Try once per second for 60 seconds, one full minute
111+
innerTryFunc(60, 1000);
111112
}
112113

113114
export function readSessionFile(): EditorServicesSessionDetails {
@@ -132,4 +133,9 @@ export function checkIfFileExists(filePath: string): boolean {
132133
catch (e) {
133134
return false;
134135
}
135-
}
136+
}
137+
138+
export function getTimestampString() {
139+
var time = new Date();
140+
return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}]`
141+
}

0 commit comments

Comments
 (0)