@@ -7,7 +7,7 @@ import * as fs from 'fs';
77import * as stream from 'stream' ;
88import * as vscode from 'vscode' ;
99import * as Proto from '../protocol' ;
10- import { ServerResponse } from '../typescriptService' ;
10+ import { ServerResponse , TypeScriptRequests } from '../typescriptService' ;
1111import { Disposable } from '../utils/dispose' ;
1212import TelemetryReporter from '../utils/telemetry' ;
1313import Tracer from '../utils/tracer' ;
@@ -23,6 +23,7 @@ export interface OngoingRequestCanceller {
2323
2424export class PipeRequestCanceller implements OngoingRequestCanceller {
2525 public constructor (
26+ private readonly _serverId : string ,
2627 private readonly _cancellationPipeName : string | undefined ,
2728 private readonly _tracer : Tracer ,
2829 ) { }
@@ -31,7 +32,7 @@ export class PipeRequestCanceller implements OngoingRequestCanceller {
3132 if ( ! this . _cancellationPipeName ) {
3233 return false ;
3334 }
34- this . _tracer . logTrace ( `TypeScript Server: trying to cancel ongoing request with sequence number ${ seq } ` ) ;
35+ this . _tracer . logTrace ( this . _serverId , `TypeScript Server: trying to cancel ongoing request with sequence number ${ seq } ` ) ;
3536 try {
3637 fs . writeFileSync ( this . _cancellationPipeName + seq , '' ) ;
3738 } catch {
@@ -51,9 +52,9 @@ export interface ITypeScriptServer {
5152
5253 kill ( ) : void ;
5354
54- executeImpl ( command : string , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : false , lowPriority ?: boolean } ) : undefined ;
55- executeImpl ( command : string , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > ;
56- executeImpl ( command : string , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > | undefined ;
55+ executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : false , lowPriority ?: boolean } ) : undefined ;
56+ executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > ;
57+ executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > | undefined ;
5758
5859 dispose ( ) : void ;
5960}
@@ -75,6 +76,7 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
7576 private readonly _pendingResponses = new Set < number > ( ) ;
7677
7778 constructor (
79+ private readonly _serverId : string ,
7880 private readonly _process : TsServerProcess ,
7981 private readonly _tsServerLogFile : string | undefined ,
8082 private readonly _requestCanceller : OngoingRequestCanceller ,
@@ -136,11 +138,11 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
136138 const seq = ( event as Proto . RequestCompletedEvent ) . body . request_seq ;
137139 const p = this . _callbacks . fetch ( seq ) ;
138140 if ( p ) {
139- this . _tracer . traceRequestCompleted ( 'requestCompleted' , seq , p . startTime ) ;
141+ this . _tracer . traceRequestCompleted ( this . _serverId , 'requestCompleted' , seq , p . startTime ) ;
140142 p . onSuccess ( undefined ) ;
141143 }
142144 } else {
143- this . _tracer . traceEvent ( event ) ;
145+ this . _tracer . traceEvent ( this . _serverId , event ) ;
144146 this . _onEvent . fire ( event ) ;
145147 }
146148 break ;
@@ -156,15 +158,15 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
156158 private tryCancelRequest ( seq : number , command : string ) : boolean {
157159 try {
158160 if ( this . _requestQueue . tryDeletePendingRequest ( seq ) ) {
159- this . _tracer . logTrace ( `TypeScript Server: canceled request with sequence number ${ seq } ` ) ;
161+ this . logTrace ( `Canceled request with sequence number ${ seq } ` ) ;
160162 return true ;
161163 }
162164
163165 if ( this . _requestCanceller . tryCancelOngoingRequest ( seq ) ) {
164166 return true ;
165167 }
166168
167- this . _tracer . logTrace ( `TypeScript Server: tried to cancel request with sequence number ${ seq } . But request got already delivered.` ) ;
169+ this . logTrace ( `Tried to cancel request with sequence number ${ seq } . But request got already delivered.` ) ;
168170 return false ;
169171 } finally {
170172 const callback = this . fetchCallback ( seq ) ;
@@ -180,7 +182,7 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
180182 return ;
181183 }
182184
183- this . _tracer . traceResponse ( response , callback . startTime ) ;
185+ this . _tracer . traceResponse ( this . _serverId , response , callback . startTime ) ;
184186 if ( response . success ) {
185187 callback . onSuccess ( response ) ;
186188 } else if ( response . message === 'No content available.' ) {
@@ -191,9 +193,9 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
191193 }
192194 }
193195
194- public executeImpl ( command : string , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : false , lowPriority ?: boolean } ) : undefined ;
195- public executeImpl ( command : string , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > ;
196- public executeImpl ( command : string , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > | undefined {
196+ public executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : false , lowPriority ?: boolean } ) : undefined ;
197+ public executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > ;
198+ public executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > | undefined {
197199 const request = this . _requestQueue . createRequest ( command , args ) ;
198200 const requestInfo : RequestItem = {
199201 request,
@@ -255,7 +257,7 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
255257
256258 private sendRequest ( requestItem : RequestItem ) : void {
257259 const serverRequest = requestItem . request ;
258- this . _tracer . traceRequest ( serverRequest , requestItem . expectsResponse , this . _requestQueue . length ) ;
260+ this . _tracer . traceRequest ( this . _serverId , serverRequest , requestItem . expectsResponse , this . _requestQueue . length ) ;
259261
260262 if ( requestItem . expectsResponse && ! requestItem . isAsync ) {
261263 this . _pendingResponses . add ( requestItem . request . seq ) ;
@@ -281,6 +283,10 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
281283 return callback ;
282284 }
283285
286+ private logTrace ( message : string ) {
287+ this . _tracer . logTrace ( this . _serverId , message ) ;
288+ }
289+
284290 private static readonly fenceCommands = new Set ( [ 'change' , 'close' , 'open' , 'updateOpen' ] ) ;
285291
286292 private static getQueueingType (
@@ -294,3 +300,53 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
294300 }
295301}
296302
303+
304+ export class SyntaxRoutingTsServer extends Disposable implements ITypeScriptServer {
305+ public constructor (
306+ private readonly syntaxServer : ITypeScriptServer ,
307+ private readonly semanticServer : ITypeScriptServer ,
308+ ) {
309+ super ( ) ;
310+
311+ this . _register ( syntaxServer . onEvent ( e => this . _onEvent . fire ( e ) ) ) ;
312+ this . _register ( semanticServer . onEvent ( e => this . _onEvent . fire ( e ) ) ) ;
313+
314+ this . _register ( semanticServer . onExit ( e => this . _onExit . fire ( e ) ) ) ;
315+ this . _register ( semanticServer . onError ( e => this . _onError . fire ( e ) ) ) ;
316+ }
317+
318+ private readonly _onEvent = this . _register ( new vscode . EventEmitter < Proto . Event > ( ) ) ;
319+ public readonly onEvent = this . _onEvent . event ;
320+
321+ private readonly _onExit = this . _register ( new vscode . EventEmitter < any > ( ) ) ;
322+ public readonly onExit = this . _onExit . event ;
323+
324+ private readonly _onError = this . _register ( new vscode . EventEmitter < any > ( ) ) ;
325+ public readonly onError = this . _onError . event ;
326+
327+ public get onReaderError ( ) { return this . semanticServer . onReaderError ; }
328+
329+ public get tsServerLogFile ( ) { return this . semanticServer . tsServerLogFile ; }
330+
331+ public kill ( ) : void {
332+ this . syntaxServer . kill ( ) ;
333+ this . semanticServer . kill ( ) ;
334+ }
335+
336+ private static readonly syntaxCommands = new Set < keyof TypeScriptRequests > ( [ 'navtree' , 'getOutliningSpans' , 'jsxClosingTag' , 'selectionRange' ] ) ;
337+ private static readonly sharedCommands = new Set < keyof TypeScriptRequests > ( [ 'change' , 'close' , 'open' , 'updateOpen' , 'configure' , 'configurePlugin' ] ) ;
338+
339+ public executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : false , lowPriority ?: boolean } ) : undefined ;
340+ public executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > ;
341+ public executeImpl ( command : keyof TypeScriptRequests , args : any , executeInfo : { isAsync : boolean , token ?: vscode . CancellationToken , expectsResult : boolean , lowPriority ?: boolean } ) : Promise < ServerResponse . Response < Proto . Response > > | undefined {
342+
343+ if ( SyntaxRoutingTsServer . syntaxCommands . has ( command ) ) {
344+ return this . syntaxServer . executeImpl ( command , args , executeInfo ) ;
345+ } else if ( SyntaxRoutingTsServer . sharedCommands . has ( command ) ) {
346+ this . syntaxServer . executeImpl ( command , args , executeInfo ) ;
347+ return this . semanticServer . executeImpl ( command , args , executeInfo ) ;
348+ } else {
349+ return this . semanticServer . executeImpl ( command , args , executeInfo ) ;
350+ }
351+ }
352+ }
0 commit comments