32
32
import ts .client .definition .ITypeScriptDefinitionCollector ;
33
33
import ts .client .format .ITypeScriptFormatCollector ;
34
34
import ts .client .geterr .ITypeScriptGeterrCollector ;
35
- import ts .client .protocol .ChangeRequest ;
36
- import ts .client .protocol .CloseRequest ;
37
- import ts .client .protocol .CompletionDetailsRequest ;
38
- import ts .client .protocol .CompletionsRequest ;
39
- import ts .client .protocol .DefinitionRequest ;
40
- import ts .client .protocol .FormatRequest ;
41
- import ts .client .protocol .GeterrRequest ;
42
- import ts .client .protocol .OpenRequest ;
43
- import ts .client .protocol .QuickInfoRequest ;
44
- import ts .client .protocol .ReloadRequest ;
45
- import ts .client .protocol .Request ;
46
- import ts .client .protocol .SignatureHelpRequest ;
47
35
import ts .client .quickinfo .ITypeScriptQuickInfoCollector ;
36
+ import ts .client .references .ITypeScriptReferencesCollector ;
48
37
import ts .client .signaturehelp .ITypeScriptSignatureHelpCollector ;
49
38
import ts .internal .FileTempHelper ;
50
39
import ts .internal .SequenceHelper ;
51
- import ts .internal .server .ICallbackItem ;
52
- import ts .internal .server .RequestItem ;
40
+ import ts .internal .client .ICallbackItem ;
41
+ import ts .internal .client .RequestItem ;
42
+ import ts .internal .client .protocol .ChangeRequest ;
43
+ import ts .internal .client .protocol .CloseRequest ;
44
+ import ts .internal .client .protocol .CompletionDetailsRequest ;
45
+ import ts .internal .client .protocol .CompletionsRequest ;
46
+ import ts .internal .client .protocol .DefinitionRequest ;
47
+ import ts .internal .client .protocol .FormatRequest ;
48
+ import ts .internal .client .protocol .GeterrRequest ;
49
+ import ts .internal .client .protocol .OpenRequest ;
50
+ import ts .internal .client .protocol .QuickInfoRequest ;
51
+ import ts .internal .client .protocol .ReferencesRequest ;
52
+ import ts .internal .client .protocol .ReloadRequest ;
53
+ import ts .internal .client .protocol .Request ;
54
+ import ts .internal .client .protocol .SignatureHelpRequest ;
53
55
import ts .nodejs .INodejsLaunchConfiguration ;
54
56
import ts .nodejs .INodejsProcess ;
55
57
import ts .nodejs .INodejsProcessListener ;
@@ -318,6 +320,8 @@ private void collect(JsonObject response, ITypeScriptGeterrCollector collector)
318
320
}
319
321
}
320
322
323
+ // -------------------------- Format
324
+
321
325
@ Override
322
326
public void format (String fileName , int line , int offset , int endLine , int endOffset ,
323
327
ITypeScriptFormatCollector collector ) throws TypeScriptException {
@@ -340,6 +344,36 @@ private void collectFormat(JsonArray body, ITypeScriptFormatCollector collector)
340
344
end .getInt ("offset" , -1 ), newText );
341
345
}
342
346
}
347
+
348
+ // ----------------- Find References
349
+
350
+ @ Override
351
+ public void references (String fileName , int line , int offset ,
352
+ ITypeScriptReferencesCollector collector ) throws TypeScriptException {
353
+ ReferencesRequest request = new ReferencesRequest (fileName , line , offset );
354
+ JsonObject response = execute (request , true , null ).asObject ();
355
+ collectReferences (response , collector );
356
+ }
357
+
358
+ private void collectReferences (JsonObject response , ITypeScriptReferencesCollector collector ) throws TypeScriptException {
359
+ JsonObject body = response .get ("body" ).asObject ();
360
+ JsonArray refs = body .get ("refs" ).asArray ();
361
+ JsonObject ref = null ;
362
+ String file = null ;
363
+ JsonObject start = null ;
364
+ JsonObject end = null ;
365
+ String lineText = null ;
366
+ for (JsonValue r : refs ) {
367
+ ref = r .asObject ();
368
+ file = ref .getString ("file" , null );
369
+ start = ref .get ("start" ).asObject ();
370
+ end = ref .get ("end" ).asObject ();
371
+ lineText = ref .getString ("lineText" , null );
372
+ collector .ref (file , start .getInt ("line" , -1 ), start .getInt ("offset" , -1 ), end .getInt ("line" , -1 ),
373
+ end .getInt ("offset" , -1 ), lineText );
374
+
375
+ }
376
+ }
343
377
344
378
/**
345
379
* Write the buffer of editor content to a temporary file and have the
0 commit comments