Skip to content

Commit 5799f0e

Browse files
author
angelozerr
committed
Start implementing "Find References". See
#44
1 parent 0185405 commit 5799f0e

File tree

64 files changed

+1043
-616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1043
-616
lines changed

core/ts.core/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Export-Package: ts,
1616
ts.client.definition,
1717
ts.client.format,
1818
ts.client.geterr,
19-
ts.client.protocol,
2019
ts.client.quickinfo,
20+
ts.client.references,
2121
ts.client.signaturehelp,
2222
ts.compiler,
2323
ts.nodejs,

core/ts.core/src/ts/client/IInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import com.eclipsesource.json.JsonObject;
1414

15-
import ts.client.protocol.Request;
15+
import ts.internal.client.protocol.Request;
1616

1717
public interface IInterceptor {
1818

core/ts.core/src/ts/client/ITypeScriptServiceClient.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import ts.client.format.ITypeScriptFormatCollector;
1818
import ts.client.geterr.ITypeScriptGeterrCollector;
1919
import ts.client.quickinfo.ITypeScriptQuickInfoCollector;
20+
import ts.client.references.ITypeScriptReferencesCollector;
2021
import ts.client.signaturehelp.ITypeScriptSignatureHelpCollector;
2122

2223
/**
@@ -53,8 +54,12 @@ void changeFile(String fileName, int line, int offset, int endLine, int endOffse
5354

5455
void geterr(String[] files, int delay, ITypeScriptGeterrCollector collector) throws TypeScriptException;
5556

56-
void format(String fileName, int line, int offset, int endLine, int endOffset, ITypeScriptFormatCollector collector) throws TypeScriptException;
57-
57+
void format(String fileName, int line, int offset, int endLine, int endOffset, ITypeScriptFormatCollector collector)
58+
throws TypeScriptException;
59+
60+
void references(String fileName, int line, int offset, ITypeScriptReferencesCollector collector)
61+
throws TypeScriptException;
62+
5863
void join() throws InterruptedException;
5964

6065
void addClientListener(ITypeScriptClientListener listener);

core/ts.core/src/ts/client/LoggingInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import com.eclipsesource.json.JsonObject;
1414

15-
import ts.client.protocol.Request;
15+
import ts.internal.client.protocol.Request;
1616

1717
public class LoggingInterceptor implements IInterceptor {
1818

core/ts.core/src/ts/client/TypeScriptServiceClient.java

+48-14
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@
3232
import ts.client.definition.ITypeScriptDefinitionCollector;
3333
import ts.client.format.ITypeScriptFormatCollector;
3434
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;
4735
import ts.client.quickinfo.ITypeScriptQuickInfoCollector;
36+
import ts.client.references.ITypeScriptReferencesCollector;
4837
import ts.client.signaturehelp.ITypeScriptSignatureHelpCollector;
4938
import ts.internal.FileTempHelper;
5039
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;
5355
import ts.nodejs.INodejsLaunchConfiguration;
5456
import ts.nodejs.INodejsProcess;
5557
import ts.nodejs.INodejsProcessListener;
@@ -318,6 +320,8 @@ private void collect(JsonObject response, ITypeScriptGeterrCollector collector)
318320
}
319321
}
320322

323+
// -------------------------- Format
324+
321325
@Override
322326
public void format(String fileName, int line, int offset, int endLine, int endOffset,
323327
ITypeScriptFormatCollector collector) throws TypeScriptException {
@@ -340,6 +344,36 @@ private void collectFormat(JsonArray body, ITypeScriptFormatCollector collector)
340344
end.getInt("offset", -1), newText);
341345
}
342346
}
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+
}
343377

344378
/**
345379
* Write the buffer of editor content to a temporary file and have the

core/ts.core/src/ts/client/TypeScriptTimeoutException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ts.client;
22

33
import ts.TypeScriptException;
4-
import ts.client.protocol.Request;
4+
import ts.internal.client.protocol.Request;
55

66
public class TypeScriptTimeoutException extends TypeScriptException {
77

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ts.client.references;
2+
3+
import ts.TypeScriptException;
4+
import ts.client.ITypeScriptCollector;
5+
6+
public interface ITypeScriptReferencesCollector extends ITypeScriptCollector {
7+
8+
void ref(String file, int startLine, int startOffset, int endLine, int endOffset, String lineText)
9+
throws TypeScriptException;
10+
11+
}

core/ts.core/src/ts/internal/server/ICallbackItem.java renamed to core/ts.core/src/ts/internal/client/ICallbackItem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ts.internal.server;
1+
package ts.internal.client;
22

33
import java.util.concurrent.Callable;
44

core/ts.core/src/ts/internal/server/RequestItem.java renamed to core/ts.core/src/ts/internal/client/RequestItem.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package ts.internal.server;
1+
package ts.internal.client;
22

3-
import ts.client.protocol.Request;
3+
import ts.internal.client.protocol.Request;
44

55
public class RequestItem {
66

core/ts.core/src/ts/client/protocol/ChangeRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/ChangeRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Change request message; value of command field is "change". Update the

core/ts.core/src/ts/client/protocol/ChangeRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/ChangeRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Arguments for change request message.

core/ts.core/src/ts/client/protocol/CloseRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/CloseRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Close request.

core/ts.core/src/ts/client/protocol/CommandNames.java renamed to core/ts.core/src/ts/internal/client/protocol/CommandNames.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Command names of tsserver.
@@ -18,8 +18,8 @@ public enum CommandNames {
1818

1919
Open("open"), Close("close"), Change("change"), NavBar("navbar"), Completions(
2020
"completions"), CompletionEntryDetails("completionEntryDetails"), Reload("reload"), Definition(
21-
"definition"), SignatureHelp(
22-
"signatureHelp"), QuickInfo("quickinfo"), Geterr("geterr"), Format("format");
21+
"definition"), SignatureHelp("signatureHelp"), QuickInfo(
22+
"quickinfo"), Geterr("geterr"), Format("format"), References("references");
2323

2424
private final String name;
2525

core/ts.core/src/ts/client/protocol/CompletionDetailsRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/CompletionDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Completion entry details request; value of command field is

core/ts.core/src/ts/client/protocol/CompletionDetailsRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/CompletionDetailsRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
import ts.utils.JsonHelper;
1414

core/ts.core/src/ts/client/protocol/CompletionsRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/CompletionsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Completions request; value of command field is "completions". Given a file

core/ts.core/src/ts/client/protocol/CompletionsRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/CompletionsRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Arguments for completions messages.

core/ts.core/src/ts/client/protocol/DefinitionRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/DefinitionRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Go to definition request; value of command field is "definition". Return

core/ts.core/src/ts/client/protocol/FileLocationRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/FileLocationRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* A request whose arguments specify a file location (file, line, col).

core/ts.core/src/ts/client/protocol/FileLocationRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/FileLocationRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Instances of this interface specify a location in a source file: (file, line,

core/ts.core/src/ts/client/protocol/FileRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/FileRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Request whose sole parameter is a file name.

core/ts.core/src/ts/client/protocol/FileRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/FileRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
import com.eclipsesource.json.JsonObject;
1414

core/ts.core/src/ts/client/protocol/FormatRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/FormatRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Format request; value of command field is "format". Return response giving

core/ts.core/src/ts/client/protocol/FormatRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/FormatRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Arguments for format messages.

core/ts.core/src/ts/client/protocol/GeterrRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/GeterrRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
import java.util.Collection;
1414
import java.util.HashMap;

core/ts.core/src/ts/client/protocol/GeterrRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/GeterrRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
import com.eclipsesource.json.JsonArray;
1414
import com.eclipsesource.json.JsonObject;

core/ts.core/src/ts/client/protocol/Message.java renamed to core/ts.core/src/ts/internal/client/protocol/Message.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
import com.eclipsesource.json.JsonObject;
1414

core/ts.core/src/ts/client/protocol/NavBarRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/NavBarRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* NavBar itesm request; value of command field is "navbar". Return response

core/ts.core/src/ts/client/protocol/OpenRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/OpenRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Open request; value of command field is "open". Notify the server that the

core/ts.core/src/ts/client/protocol/OpenRequestArgs.java renamed to core/ts.core/src/ts/internal/client/protocol/OpenRequestArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
* Information found in an "open" request.

core/ts.core/src/ts/client/protocol/QuickInfoRequest.java renamed to core/ts.core/src/ts/internal/client/protocol/QuickInfoRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
1010
*/
11-
package ts.client.protocol;
11+
package ts.internal.client.protocol;
1212

1313
/**
1414
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ts.internal.client.protocol;
2+
3+
public class ReferencesRequest extends FileLocationRequest {
4+
5+
public ReferencesRequest(String fileName, int line, int offset) {
6+
super(CommandNames.References, new FileLocationRequestArgs(fileName, line, offset));
7+
}
8+
9+
}

0 commit comments

Comments
 (0)