|
1 | 1 | import * as monaco from 'monaco-editor' |
2 | 2 | import { |
3 | | - CloseAction, ErrorAction, MonacoLanguageClient, Emitter, Event, TextDocument, Services, State, DisposableCollection, CancellationToken, RequestType, NotificationType, Disposable |
| 3 | + CloseAction, ErrorAction, MonacoLanguageClient, Emitter, Event, TextDocument, Services, State, DisposableCollection, CancellationToken, RequestType, NotificationType, Disposable, LogMessageNotification |
4 | 4 | } from 'monaco-languageclient' |
5 | 5 | import delay from 'delay' |
6 | 6 | import { Uri } from 'monaco-editor' |
@@ -32,12 +32,14 @@ export class LanguageClientManager implements LanguageClient { |
32 | 32 | protected readonly onWillCloseEmitter = new Emitter<void>() |
33 | 33 | protected readonly onWillShutdownEmitter = new Emitter<WillShutdownParams>() |
34 | 34 | protected currentStatus: Status = 'connecting' |
| 35 | + private useMutualizedProxy: boolean |
35 | 36 |
|
36 | 37 | constructor ( |
37 | 38 | private id: LanguageClientId, |
38 | 39 | private languageServerOptions: LanguageClientOptions, |
39 | 40 | private infrastructure: Infrastructure |
40 | 41 | ) { |
| 42 | + this.useMutualizedProxy = this.infrastructure.useMutualizedProxy(this.id, this.languageServerOptions) |
41 | 43 | } |
42 | 44 |
|
43 | 45 | private updateStatus (status: Status) { |
@@ -109,7 +111,7 @@ export class LanguageClientManager implements LanguageClient { |
109 | 111 |
|
110 | 112 | public async start (): Promise<void> { |
111 | 113 | try { |
112 | | - await loadExtensionConfigurations([this.id], this.infrastructure.useMutualizedProxy(this.id, this.languageServerOptions)) |
| 114 | + await loadExtensionConfigurations([this.id], this.useMutualizedProxy) |
113 | 115 | } catch (error) { |
114 | 116 | console.error('Unable to load extension configuration', error) |
115 | 117 | } |
@@ -201,11 +203,26 @@ export class LanguageClientManager implements LanguageClient { |
201 | 203 | this.updateStatus('connecting') |
202 | 204 | readyPromise = languageClient.onReady().then(async () => { |
203 | 205 | const disposableCollection = new DisposableCollection() |
204 | | - await Promise.race([ |
205 | | - new Promise<void>(resolve => { |
| 206 | + |
| 207 | + let readyPromise: Promise<void> |
| 208 | + const { maxInitializeDuration, readinessMessageMatcher } = this.languageServerOptions |
| 209 | + if (readinessMessageMatcher != null && !this.useMutualizedProxy) { |
| 210 | + readyPromise = new Promise<void>(resolve => { |
| 211 | + disposableCollection.push(languageClient.onNotification(LogMessageNotification.type, logMessage => { |
| 212 | + if (readinessMessageMatcher.exec(logMessage.message) != null) { |
| 213 | + resolve() |
| 214 | + } |
| 215 | + })) |
| 216 | + }) |
| 217 | + } else { |
| 218 | + readyPromise = new Promise<void>(resolve => { |
206 | 219 | disposableCollection.push(onServerResponse.event(resolve)) |
207 | | - }), |
208 | | - delay(15000) |
| 220 | + }) |
| 221 | + } |
| 222 | + |
| 223 | + await Promise.race([ |
| 224 | + readyPromise, |
| 225 | + delay(maxInitializeDuration ?? 15_000) |
209 | 226 | ]) |
210 | 227 | disposableCollection.dispose() |
211 | 228 | }, error => { |
|
0 commit comments