@@ -38,6 +38,16 @@ connection.onInitialize(params => {
3838 } ) ;
3939
4040 let simpleLs : LanguageService | undefined ;
41+ let tsserverRequestId = 0 ;
42+
43+ const tsserverRequestHandlers = new Map < number , ( res : any ) => void > ( ) ;
44+
45+ if ( Array . isArray ( options . typescript . tsserverRequestCommand ) ) {
46+ connection . onNotification ( options . typescript . tsserverRequestCommand [ 1 ] , ( [ id , res ] ) => {
47+ tsserverRequestHandlers . get ( id ) ?.( res ) ;
48+ tsserverRequestHandlers . delete ( id ) ;
49+ } ) ;
50+ }
4151
4252 return server . initialize (
4353 params ,
@@ -139,8 +149,17 @@ connection.onInitialize(params => {
139149 } : undefined )
140150 ) ;
141151
142- function sendTsRequest < T > ( command : string , args : any ) : Promise < T | null > {
143- return connection . sendRequest < T > ( options . typescript . tsserverRequestCommand ! , [ command , args ] ) ;
152+ async function sendTsRequest < T > ( command : string , args : any ) : Promise < T | null > {
153+ if ( typeof options . typescript . tsserverRequestCommand === 'string' ) {
154+ return await connection . sendRequest < T > ( options . typescript . tsserverRequestCommand , [ command , args ] ) ;
155+ } else {
156+ const [ requestCommand ] = options . typescript . tsserverRequestCommand ! ;
157+ return await new Promise < T | null > ( resolve => {
158+ const requestId = ++ tsserverRequestId ;
159+ tsserverRequestHandlers . set ( requestId , resolve ) ;
160+ connection . sendNotification ( requestCommand , [ command , args , requestId ] ) ;
161+ } ) ;
162+ }
144163 }
145164
146165 function createLs ( server : LanguageServer , tsconfig : string | undefined ) {
@@ -185,3 +204,4 @@ connection.onInitialize(params => {
185204connection . onInitialized ( server . initialized ) ;
186205
187206connection . onShutdown ( server . shutdown ) ;
207+
0 commit comments