Skip to content

Commit a50a463

Browse files
Merge pull request #880 from wjk/configurable-timeout
Add a setting to configure the server load timeout
2 parents 32b9472 + 986a430 commit a50a463

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@
259259
"type": "boolean",
260260
"default": true,
261261
"description": "Specifies whether the OmniSharp server will be automatically started or not. If false, OmniSharp can be started with the 'Restart OmniSharp' command"
262+
},
263+
"omnisharp.projectLoadTimeout": {
264+
"type": "number",
265+
"default": 60,
266+
"description": "The time Visual Studio Code will wait for the OmniSharp server to start. Time is expressed in seconds."
262267
}
263268
}
264269
},

src/omnisharp/options.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export class Options {
1010
public path?: string,
1111
public useMono?: boolean,
1212
public loggingLevel?: string,
13-
public autoStart?: boolean) { }
13+
public autoStart?: boolean,
14+
public projectLoadTimeout?: number) { }
1415

1516
public static Read(): Options {
1617
// Extra effort is taken below to ensure that legacy versions of options
@@ -33,6 +34,8 @@ export class Options {
3334
const loggingLevel = omnisharpConfig.get<string>('loggingLevel');
3435
const autoStart = omnisharpConfig.get<boolean>('autoStart', true);
3536

36-
return new Options(path, useMono, loggingLevel, autoStart);
37+
const projectLoadTimeout = omnisharpConfig.get<number>('projectLoadTimeout', 60);
38+
39+
return new Options(path, useMono, loggingLevel, autoStart, projectLoadTimeout);
3740
}
3841
}

src/omnisharp/server.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export abstract class OmnisharpServer {
8282

8383
protected _serverProcess: ChildProcess;
8484
protected _extraArgs: string[];
85+
protected _options: Options;
8586

8687
constructor(reporter: TelemetryReporter) {
8788
this._extraArgs = [];
@@ -240,9 +241,9 @@ export abstract class OmnisharpServer {
240241
'--encoding', 'utf-8'
241242
];
242243

243-
const options = Options.Read();
244+
this._options = Options.Read();
244245

245-
if (options.loggingLevel === 'verbose') {
246+
if (this._options.loggingLevel === 'verbose') {
246247
args.push('-v');
247248
}
248249

@@ -498,7 +499,6 @@ namespace WireProtocol {
498499
export class StdioOmnisharpServer extends OmnisharpServer {
499500

500501
private static _seqPool = 1;
501-
private static StartupTimeout = 1000 * 60;
502502

503503
private _rl: ReadLine;
504504
private _activeRequest: { [seq: number]: { onSuccess: Function; onError: Function; } } = Object.create(null);
@@ -534,14 +534,17 @@ export class StdioOmnisharpServer extends OmnisharpServer {
534534
const p = new Promise<void>((resolve, reject) => {
535535
let listener: vscode.Disposable;
536536

537+
// Convert the timeout from the seconds to milliseconds, which is required by setTimeout().
538+
const timeoutDuration = this._options.projectLoadTimeout * 1000
539+
537540
// timeout logic
538541
const handle = setTimeout(() => {
539542
if (listener) {
540543
listener.dispose();
541544
}
542545

543-
reject(new Error('Failed to start OmniSharp'));
544-
}, StdioOmnisharpServer.StartupTimeout);
546+
reject(new Error("OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute)."));
547+
}, timeoutDuration);
545548

546549
// handle started-event
547550
listener = this.onOmnisharpStart(() => {

0 commit comments

Comments
 (0)