@@ -323,7 +323,7 @@ private void collect(JsonObject response, ITypeScriptGeterrCollector collector)
323
323
}
324
324
325
325
// -------------------------- Format
326
-
326
+
327
327
@ Override
328
328
public void format (String fileName , int line , int offset , int endLine , int endOffset ,
329
329
ITypeScriptFormatCollector collector ) throws TypeScriptException {
@@ -346,63 +346,31 @@ private void collectFormat(JsonArray body, ITypeScriptFormatCollector collector)
346
346
end .getInt ("offset" , -1 ), newText );
347
347
}
348
348
}
349
-
349
+
350
350
// ----------------- Find References
351
-
352
- @ Override
353
- public void references (String fileName , int line , int offset ,
354
- ITypeScriptReferencesCollector collector ) throws TypeScriptException {
355
- ReferencesRequest request = new ReferencesRequest (fileName , line , offset );
356
- JsonObject response = execute (request , true , null ).asObject ();
357
- collectReferences (response , collector );
358
- }
359
351
360
- private void collectReferences (JsonObject response , ITypeScriptReferencesCollector collector ) throws TypeScriptException {
361
- JsonObject body = response .get ("body" ).asObject ();
362
- JsonArray refs = body .get ("refs" ).asArray ();
363
- JsonObject ref = null ;
364
- String file = null ;
365
- JsonObject start = null ;
366
- JsonObject end = null ;
367
- String lineText = null ;
368
- for (JsonValue r : refs ) {
369
- ref = r .asObject ();
370
- file = ref .getString ("file" , null );
371
- start = ref .get ("start" ).asObject ();
372
- end = ref .get ("end" ).asObject ();
373
- lineText = ref .getString ("lineText" , null );
374
- collector .ref (file , start .getInt ("line" , -1 ), start .getInt ("offset" , -1 ), end .getInt ("line" , -1 ),
375
- end .getInt ("offset" , -1 ), lineText );
376
-
377
- }
352
+ @ Override
353
+ public void references (String fileName , int line , int offset , ITypeScriptReferencesCollector collector )
354
+ throws TypeScriptException {
355
+ ReferencesRequest request = new ReferencesRequest (fileName , line , offset , collector );
356
+ execute (request );
378
357
}
379
358
380
359
// ----------------- Occurrences
381
-
360
+
382
361
@ Override
383
- public void occurrences (String fileName , int line , int offset ,
384
- ITypeScriptOccurrencesCollector collector ) throws TypeScriptException {
385
- OccurrencesRequest request = new OccurrencesRequest (fileName , line , offset );
386
- JsonObject response = execute (request , true , null ).asObject ();
387
- collectOccurrences (response , collector );
362
+ public void occurrences (String fileName , int line , int offset , ITypeScriptOccurrencesCollector collector )
363
+ throws TypeScriptException {
364
+ OccurrencesRequest request = new OccurrencesRequest (fileName , line , offset , collector );
365
+ execute (request );
388
366
}
389
367
390
- private void collectOccurrences (JsonObject response , ITypeScriptOccurrencesCollector collector ) throws TypeScriptException {
391
- JsonArray body = response .get ("body" ).asArray ();
392
- JsonObject occurrence = null ;
393
- String file = null ;
394
- JsonObject start = null ;
395
- JsonObject end = null ;
396
- boolean isWriteAccess = false ;
397
- for (JsonValue b : body ) {
398
- occurrence = b .asObject ();
399
- file = occurrence .getString ("file" , null );
400
- start = occurrence .get ("start" ).asObject ();
401
- end = occurrence .get ("end" ).asObject ();
402
- isWriteAccess = occurrence .getBoolean ("isWriteAccess" , false );
403
- collector .addOccurrence (file , start .getInt ("line" , -1 ), start .getInt ("offset" , -1 ), end .getInt ("line" , -1 ),
404
- end .getInt ("offset" , -1 ), isWriteAccess );
405
-
368
+ private void execute (Request request ) throws TypeScriptException {
369
+ if (!request .isAsynch ()) {
370
+ JsonObject response = execute (request , true , null ).asObject ();
371
+ request .collect (response );
372
+ } else {
373
+ execute (request , true , null );
406
374
}
407
375
}
408
376
@@ -575,7 +543,7 @@ public void join() throws InterruptedException {
575
543
* @return the result of the request if it needed and null otherwise.
576
544
* @throws TypeScriptException
577
545
*/
578
- private JsonValue execute (Request request , boolean expectsResult , CancellationToken token )
546
+ private JsonValue execute (Request request , boolean expectsResult , ICancellationToken token )
579
547
throws TypeScriptException {
580
548
boolean eventRequest = (request instanceof GeterrRequest );
581
549
RequestItem requestInfo = null ;
@@ -600,11 +568,11 @@ private JsonValue execute(Request request, boolean expectsResult, CancellationTo
600
568
handleError (request , e , request .getStartTime ());
601
569
TypeScriptException tse = getTypeScriptException (e );
602
570
if (tse != null ) {
603
- if (tse instanceof TypeScriptTimeoutException ) {
604
- // when time out exception, we must be sure that the request
605
- // is removed
606
- tryCancelRequest (((TypeScriptTimeoutException ) tse ).getRequest ().getSeq ());
607
- }
571
+ // if (tse instanceof TypeScriptTimeoutException) {
572
+ // // when time out exception, we must be sure that the request
573
+ // // is removed
574
+ // tryCancelRequest(((TypeScriptTimeoutException) tse).getRequest().getSeq());
575
+ // }
608
576
throw (TypeScriptException ) tse ;
609
577
}
610
578
throw new TypeScriptException (e );
@@ -633,7 +601,7 @@ private boolean tryCancelRequest(int seq) {
633
601
return false ;
634
602
}
635
603
636
- private void sendNextRequests () throws TypeScriptException {
604
+ private void sendNextRequests () {
637
605
RequestItem requestItem = null ;
638
606
while (this .pendingResponses .get () == 0 && !this .requestQueue .isEmpty ()) {
639
607
synchronized (requestQueue ) {
@@ -643,7 +611,7 @@ private void sendNextRequests() throws TypeScriptException {
643
611
}
644
612
}
645
613
646
- private void sendRequest (RequestItem requestItem ) throws TypeScriptException {
614
+ private void sendRequest (RequestItem requestItem ) {
647
615
Request serverRequest = requestItem .request ;
648
616
// log request
649
617
handleRequest (serverRequest );
@@ -680,18 +648,18 @@ private void sendRequest(RequestItem requestItem) throws TypeScriptException {
680
648
synchronized (this .callbacks ) {
681
649
ICallbackItem callback = this .callbacks .get (serverRequest .getSeq ());
682
650
if (callback != null ) {
683
- // callback.e(err );
651
+ callback .error ( e );
684
652
this .callbacks .remove (serverRequest .getSeq ());
685
653
}
686
654
this .pendingResponses .getAndDecrement ();
687
655
}
688
656
}
689
- throw e ;
690
657
}
691
658
692
659
}
693
660
694
661
private void dispatchMessage (JsonObject response ) {
662
+ try {
695
663
String type = response .getString ("type" , null );
696
664
if ("response" .equals (type )) {
697
665
int seq = response .getInt ("request_seq" , -1 );
@@ -725,6 +693,10 @@ private void dispatchMessage(JsonObject response) {
725
693
}
726
694
}
727
695
}
696
+ }
697
+ finally {
698
+ this .sendNextRequests ();
699
+ }
728
700
}
729
701
730
702
// --------------------------- Handler for Request/response/Error
0 commit comments