Skip to content

Commit 826cda7

Browse files
feat: add maxStartAttemptCount option
1 parent cea74e5 commit 826cda7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CodinGameInfrastructure, Infrastructure } from './infrastructure'
55
import { WillShutdownParams } from './customRequests'
66
import { loadExtensionConfigurations } from './extensionConfiguration'
77
import './hacks'
8-
import { createLanguageClientManager, LanguageClientManager, StatusChangeEvent } from './languageClient'
8+
import { createLanguageClientManager, LanguageClientManager, LanguageClientManagerOptions, StatusChangeEvent } from './languageClient'
99
import { LanguageClientId, LanguageClientOptions, registerLanguageClient } from './languageClientOptions'
1010
import { StaticLanguageClientId } from './staticOptions'
1111

@@ -27,5 +27,6 @@ export type {
2727
TextDocument,
2828
TextDocumentSaveReason,
2929
LanguageClientOptions,
30+
LanguageClientManagerOptions,
3031
MessageTransports
3132
}

src/languageClient.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export interface StatusChangeEvent {
2424

2525
const RETRY_CONNECTION_DELAY = 3000
2626

27+
export interface LanguageClientManagerOptions {
28+
/**
29+
* The language client will stop trying to start after `maxStartAttemptCount` failed attempts
30+
*/
31+
maxStartAttemptCount?: number
32+
}
33+
2734
export class LanguageClientManager implements LanguageClient {
2835
languageClient?: MonacoLanguageClient
2936
private disposed: boolean = false
@@ -37,7 +44,8 @@ export class LanguageClientManager implements LanguageClient {
3744
constructor (
3845
private id: LanguageClientId,
3946
private clientOptions: LanguageClientOptions,
40-
private infrastructure: Infrastructure
47+
private infrastructure: Infrastructure,
48+
private managerOptions: LanguageClientManagerOptions = {}
4149
) {
4250
this.useMutualizedProxy = this.infrastructure.useMutualizedProxy(this.id, this.clientOptions)
4351
}
@@ -124,7 +132,14 @@ export class LanguageClientManager implements LanguageClient {
124132
}))
125133
}
126134
let started = false
127-
while (!this.isDisposed() && !started) {
135+
let attempt = 0
136+
while (
137+
!this.isDisposed() &&
138+
!started && (
139+
this.managerOptions.maxStartAttemptCount == null ||
140+
attempt < this.managerOptions.maxStartAttemptCount
141+
)
142+
) {
128143
try {
129144
await this._start()
130145
started = true
@@ -134,6 +149,7 @@ export class LanguageClientManager implements LanguageClient {
134149
}))
135150
await delay(RETRY_CONNECTION_DELAY)
136151
}
152+
++attempt
137153
}
138154
}
139155

0 commit comments

Comments
 (0)