11import  *  as  monaco  from  'monaco-editor' 
22import  { 
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 
44}  from  'monaco-languageclient' 
55import  delay  from  'delay' 
66import  {  Uri  }  from  'monaco-editor' 
@@ -32,12 +32,14 @@ export class LanguageClientManager implements LanguageClient {
3232  protected  readonly  onWillCloseEmitter  =  new  Emitter < void > ( ) 
3333  protected  readonly  onWillShutdownEmitter  =  new  Emitter < WillShutdownParams > ( ) 
3434  protected  currentStatus : Status  =  'connecting' 
35+   private  useMutualizedProxy : boolean 
3536
3637  constructor  ( 
3738    private  id : LanguageClientId , 
3839    private  languageServerOptions : LanguageClientOptions , 
3940    private  infrastructure : Infrastructure 
4041  )  { 
42+     this . useMutualizedProxy  =  this . infrastructure . useMutualizedProxy ( this . id ,  this . languageServerOptions ) 
4143  } 
4244
4345  private  updateStatus  ( status : Status )  { 
@@ -109,7 +111,7 @@ export class LanguageClientManager implements LanguageClient {
109111
110112  public  async  start  ( ) : Promise < void >  { 
111113    try  { 
112-       await  loadExtensionConfigurations ( [ this . id ] ,  this . infrastructure . useMutualizedProxy ) 
114+       await  loadExtensionConfigurations ( [ this . id ] ,  this . useMutualizedProxy ) 
113115    }  catch  ( error )  { 
114116      console . error ( 'Unable to load extension configuration' ,  error ) 
115117    } 
@@ -201,11 +203,26 @@ export class LanguageClientManager implements LanguageClient {
201203          this . updateStatus ( 'connecting' ) 
202204          readyPromise  =  languageClient . onReady ( ) . then ( async  ( )  =>  { 
203205            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  =>  { 
206219                disposableCollection . push ( onServerResponse . event ( resolve ) ) 
207-               } ) , 
208-               delay ( 15000 ) 
220+               } ) 
221+             } 
222+ 
223+             await  Promise . race ( [ 
224+               readyPromise , 
225+               delay ( maxInitializeDuration  ??  15_000 ) 
209226            ] ) 
210227            disposableCollection . dispose ( ) 
211228          } ,  error  =>  { 
@@ -268,7 +285,7 @@ function createLanguageClientManager (
268285    throw  new  Error ( `Unknown ${ id }   language server` ) 
269286  } 
270287
271-   if  ( infrastructure . useMutualizedProxy  &&  languageServerOptions . mutualizable )  { 
288+   if  ( infrastructure . useMutualizedProxy ( id ,   languageServerOptions )  &&  languageServerOptions . mutualizable )  { 
272289    // When using the mutualized proxy, we don't need to synchronize the configuration nor send the initialization options 
273290    languageServerOptions  =  { 
274291      ...languageServerOptions , 
@@ -289,8 +306,7 @@ function createLanguageClientManager (
289306
290307  disposableCollection . push ( registerTextModelContentProvider ( 'file' ,  { 
291308    async  provideTextContent  ( resource : Uri ) : Promise < monaco . editor . ITextModel  |  null >  { 
292-       const  content  =  await  infrastructure . getFileContent ( resource ,  languageClientManager ) 
293-       return  content  !=  null  ? monaco . editor . createModel ( content ,  undefined ,  resource )  : null 
309+       return  await  infrastructure . getFileContent ( resource ,  languageClientManager ) 
294310    } 
295311  } ) ) 
296312  disposableCollection . push ( getServices ( ) . workspace . registerSaveDocumentHandler ( { 
0 commit comments