|
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.occurrences.ITypeScriptOccurrencesCollector; |
35 | 36 | import ts.client.quickinfo.ITypeScriptQuickInfoCollector;
|
36 | 37 | import ts.client.references.ITypeScriptReferencesCollector;
|
37 | 38 | import ts.client.signaturehelp.ITypeScriptSignatureHelpCollector;
|
|
46 | 47 | import ts.internal.client.protocol.DefinitionRequest;
|
47 | 48 | import ts.internal.client.protocol.FormatRequest;
|
48 | 49 | import ts.internal.client.protocol.GeterrRequest;
|
| 50 | +import ts.internal.client.protocol.OccurrencesRequest; |
49 | 51 | import ts.internal.client.protocol.OpenRequest;
|
50 | 52 | import ts.internal.client.protocol.QuickInfoRequest;
|
51 | 53 | import ts.internal.client.protocol.ReferencesRequest;
|
@@ -375,6 +377,35 @@ private void collectReferences(JsonObject response, ITypeScriptReferencesCollect
|
375 | 377 | }
|
376 | 378 | }
|
377 | 379 |
|
| 380 | + // ----------------- Occurrences |
| 381 | + |
| 382 | + @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); |
| 388 | + } |
| 389 | + |
| 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 | + |
| 406 | + } |
| 407 | + } |
| 408 | + |
378 | 409 | /**
|
379 | 410 | * Write the buffer of editor content to a temporary file and have the
|
380 | 411 | * server reload it
|
|
0 commit comments