Skip to content

Commit da66597

Browse files
authored
feat: Update the implementation to V4 protocol (#45)
1 parent 8e38d7a commit da66597

File tree

19 files changed

+220
-160
lines changed

19 files changed

+220
-160
lines changed

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/IConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ private IConstant() {
1616

1717
public final static String DEFAULT_LSIF_FILE_NAME = "lsif.json";
1818

19-
public final static String LSIF_FORMAT_VERSION = "0.3.0";
19+
public final static String LSIF_FORMAT_VERSION = "0.4.3";
2020
}

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/EdgeBuilder.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
package com.microsoft.java.lsif.core.internal.indexer;
77

8+
import java.util.Collections;
9+
import java.util.List;
10+
811
import com.microsoft.java.lsif.core.internal.protocol.Document;
912
import com.microsoft.java.lsif.core.internal.protocol.Edge;
10-
import com.microsoft.java.lsif.core.internal.protocol.Project;
11-
import com.microsoft.java.lsif.core.internal.protocol.Range;
12-
import com.microsoft.java.lsif.core.internal.protocol.ReferenceItem;
13+
import com.microsoft.java.lsif.core.internal.protocol.ItemEdge;
1314
import com.microsoft.java.lsif.core.internal.protocol.Vertex;
1415

1516
public class EdgeBuilder {
@@ -20,26 +21,23 @@ public EdgeBuilder(IdGenerator idGenerator) {
2021
this.generator = idGenerator;
2122
}
2223

23-
public Edge contains(Project from, Document to) {
24-
return new Edge(generator.next(), Edge.CONTAINS, from.getId(), to.getId());
24+
public Edge contains(Vertex from, Vertex to) {
25+
return new Edge(generator.next(), Edge.CONTAINS, from.getId(), Collections.singletonList(to.getId()));
2526
}
2627

27-
public Edge contains(Document from, Range to) {
28-
return new Edge(generator.next(), Edge.CONTAINS, from.getId(), to.getId());
28+
public Edge item(Vertex from, Vertex to, Document doc, String property) {
29+
return new ItemEdge(generator.next(), Edge.ITEM, from.getId(), Collections.singletonList(to.getId()),
30+
doc.getId(), property);
2931
}
3032

31-
public Edge contains(Vertex from, Vertex to) {
32-
return new Edge(generator.next(), Edge.CONTAINS, from.getId(), to.getId());
33+
public Edge item(Vertex from, List<String> inVs, Document doc, String property) {
34+
return new ItemEdge(generator.next(), Edge.ITEM, from.getId(), inVs, doc.getId(), property);
3335
}
3436

3537
public Edge hover(Vertex from, Vertex to) {
3638
return new Edge(generator.next(), Edge.T_HOVER, from.getId(), to.getId());
3739
}
3840

39-
public Edge referenceItem(Vertex from, Vertex to, String property) {
40-
return new ReferenceItem(generator.next(), Edge.ITEM, from.getId(), to.getId(), property);
41-
}
42-
4341
public Edge definition(Vertex from, Vertex to) {
4442
return new Edge(generator.next(), Edge.T_DEFINITION, from.getId(), to.getId());
4543
}
@@ -60,8 +58,8 @@ public Edge documentSymbols(Vertex from, Vertex to) {
6058
return new Edge(generator.next(), Edge.T_DOCUMENTSYMBOL, from.getId(), to.getId());
6159
}
6260

63-
public Edge refersTo(Vertex from, Vertex to) {
64-
return new Edge(generator.next(), Edge.REFERSTO, from.getId(), to.getId());
61+
public Edge next(Vertex from, Vertex to) {
62+
return new Edge(generator.next(), Edge.NEXT, from.getId(), to.getId());
6563
}
6664

6765
public Edge diagnostic(Vertex from, Vertex to) {

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Indexer.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
import org.eclipse.jdt.core.JavaCore;
2727
import org.eclipse.jdt.core.JavaModelException;
2828
import org.eclipse.jdt.core.dom.CompilationUnit;
29+
import org.eclipse.jdt.ls.core.internal.BuildWorkspaceStatus;
2930
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
31+
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
3032
import org.eclipse.lsp4j.ClientCapabilities;
3133

3234
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
3335
import com.microsoft.java.lsif.core.internal.protocol.Document;
36+
import com.microsoft.java.lsif.core.internal.protocol.Event;
3437
import com.microsoft.java.lsif.core.internal.protocol.Project;
3538
import com.microsoft.java.lsif.core.internal.visitors.DiagnosticVisitor;
3639
import com.microsoft.java.lsif.core.internal.visitors.DocumentVisitor;
@@ -58,10 +61,14 @@ public void generateLsif() throws JavaModelException {
5861
LsifService lsif = new LsifService();
5962

6063
LsifEmitter.getInstance().start();
61-
LsifEmitter.getInstance().emit(lsif.getVertexBuilder().metaData());
64+
LsifEmitter.getInstance().emit(lsif.getVertexBuilder().metaData(ResourceUtils.fixURI(path.toFile().toURI())));
6265

6366
handler.importProject(path, monitor);
64-
handler.buildProject(monitor);
67+
BuildWorkspaceStatus buildStatus = handler.buildProject(monitor);
68+
if (buildStatus != BuildWorkspaceStatus.SUCCEED) {
69+
return;
70+
71+
}
6572
buildIndex(path, monitor, lsif);
6673
handler.removeProject(monitor);
6774

@@ -85,10 +92,15 @@ private void buildIndex(IPath path, IProgressMonitor monitor, LsifService lsif)
8592

8693
Project projVertex = lsif.getVertexBuilder().project();
8794
LsifEmitter.getInstance().emit(projVertex);
95+
LsifEmitter.getInstance()
96+
.emit(lsif.getVertexBuilder().event(Event.EventScope.Project, Event.EventKind.BEGIN,
97+
projVertex.getId()));
8898

8999
List<ICompilationUnit> sourceList = getAllSourceFiles(javaProject);
90100

91101
dumpParallely(sourceList, threadPool, projVertex, lsif, monitor);
102+
LsifEmitter.getInstance().emit(
103+
lsif.getVertexBuilder().event(Event.EventScope.Project, Event.EventKind.END, projVertex.getId()));
92104
}
93105

94106
threadPool.shutdown();
@@ -141,6 +153,10 @@ private void dumpParallely(List<ICompilationUnit> sourceList, ExecutorService th
141153
DiagnosticVisitor diagnosticVisitor = new DiagnosticVisitor(lsif, context);
142154
diagnosticVisitor.enlist();
143155

156+
LsifEmitter.getInstance()
157+
.emit(lsif.getVertexBuilder().event(Event.EventScope.DOCUMENT, Event.EventKind.END,
158+
docVertex.getId()));
159+
144160
return 0;
145161
})).blockingSubscribe();
146162
}

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Repository.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
import com.microsoft.java.lsif.core.internal.LsifUtils;
1212
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
1313
import com.microsoft.java.lsif.core.internal.protocol.Document;
14+
import com.microsoft.java.lsif.core.internal.protocol.Event;
1415
import com.microsoft.java.lsif.core.internal.protocol.Range;
15-
import com.microsoft.java.lsif.core.internal.protocol.SymbolData;
16+
import com.microsoft.java.lsif.core.internal.visitors.SymbolData;
1617

1718
public class Repository {
1819

@@ -47,6 +48,9 @@ public synchronized Document enlistDocument(LsifService service, String uri) {
4748
if (targetDocument == null) {
4849
targetDocument = service.getVertexBuilder().document(uri);
4950
addDocument(targetDocument);
51+
LsifEmitter.getInstance()
52+
.emit(service.getVertexBuilder().event(Event.EventScope.DOCUMENT, Event.EventKind.BEGIN,
53+
targetDocument.getId()));
5054
LsifEmitter.getInstance().emit(targetDocument);
5155
}
5256

@@ -69,10 +73,10 @@ public Range enlistRange(LsifService service, String uri, org.eclipse.lsp4j.Rang
6973
return enlistRange(service, enlistDocument(service, uri), lspRange);
7074
}
7175

72-
public synchronized SymbolData enlistSymbolData(String id) {
76+
public synchronized SymbolData enlistSymbolData(String id, Document docVertex) {
7377
SymbolData symbolData = findSymbolDataById(id);
7478
if (symbolData == null) {
75-
symbolData = new SymbolData();
79+
symbolData = new SymbolData(docVertex);
7680
addSymbolData(id, symbolData);
7781
}
7882
return symbolData;

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/VertexBuilder.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
import org.eclipse.lsp4j.Diagnostic;
1111
import org.eclipse.lsp4j.DocumentSymbol;
1212
import org.eclipse.lsp4j.Hover;
13-
import org.eclipse.lsp4j.Location;
14-
import org.eclipse.lsp4j.jsonrpc.messages.Either;
1513

1614
import com.microsoft.java.lsif.core.internal.JdtlsUtils;
1715
import com.microsoft.java.lsif.core.internal.LsifUtils;
1816
import com.microsoft.java.lsif.core.internal.protocol.DefinitionResult;
1917
import com.microsoft.java.lsif.core.internal.protocol.DiagnosticResult;
2018
import com.microsoft.java.lsif.core.internal.protocol.Document;
2119
import com.microsoft.java.lsif.core.internal.protocol.DocumentSymbolResult;
20+
import com.microsoft.java.lsif.core.internal.protocol.Event;
2221
import com.microsoft.java.lsif.core.internal.protocol.HoverResult;
2322
import com.microsoft.java.lsif.core.internal.protocol.ImplementationResult;
2423
import com.microsoft.java.lsif.core.internal.protocol.MetaData;
@@ -36,8 +35,12 @@ public VertexBuilder(IdGenerator generator) {
3635
this.generator = generator;
3736
}
3837

39-
public MetaData metaData() {
40-
return new MetaData(generator.next());
38+
public MetaData metaData(String projectRoot) {
39+
return new MetaData(generator.next(), projectRoot);
40+
}
41+
42+
public Event event(String scope, String kind, String data) {
43+
return new Event(generator.next(), scope, kind, data);
4144
}
4245

4346
public Project project() {
@@ -60,29 +63,24 @@ public ResultSet resultSet() {
6063
return new ResultSet(generator.next());
6164
}
6265

63-
public DefinitionResult definitionResult(String resultId) {
64-
return new DefinitionResult(generator.next(), resultId);
66+
public DefinitionResult definitionResult() {
67+
return new DefinitionResult(generator.next());
6568
}
6669

6770
public HoverResult hoverResult(Hover hover) {
6871
return new HoverResult(generator.next(), hover);
6972
}
7073

71-
public TypeDefinitionResult typeDefinitionResult(String resultId) {
72-
return new TypeDefinitionResult(generator.next(), resultId);
74+
public TypeDefinitionResult typeDefinitionResult() {
75+
return new TypeDefinitionResult(generator.next());
7376
}
7477

7578
public ReferenceResult referenceResult() {
7679
return new ReferenceResult(generator.next());
7780
}
7881

79-
public ReferenceResult referenceResult(List<String> declarations, List<String> definitions, List<String> references,
80-
List<String> referenceResults) {
81-
return new ReferenceResult(generator.next(), declarations, definitions, references, referenceResults);
82-
}
83-
84-
public ImplementationResult implementationResult(List<Either<String, Location>> result) {
85-
return new ImplementationResult(generator.next(), result);
82+
public ImplementationResult implementationResult() {
83+
return new ImplementationResult(generator.next());
8684
}
8785

8886
public DocumentSymbolResult documentSymbolResult(List<DocumentSymbol> symbols) {

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/DefinitionResult.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,9 @@
55

66
package com.microsoft.java.lsif.core.internal.protocol;
77

8-
import java.util.Arrays;
9-
import java.util.List;
10-
118
public class DefinitionResult extends Vertex {
129

13-
private List<String> result;
14-
15-
public DefinitionResult(String id, String result) {
10+
public DefinitionResult(String id) {
1611
super(id, Vertex.DEFINITIONRESULT);
17-
this.result = Arrays.asList(result);
18-
}
19-
20-
public List<String> getResult() {
21-
return this.result;
2212
}
2313
}

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Edge.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
package com.microsoft.java.lsif.core.internal.protocol;
77

8+
import java.util.List;
9+
810
public class Edge extends Element {
911

1012
public final static String CONTAINS = "contains";
1113

1214
public final static String ITEM = "item";
1315

14-
public final static String REFERSTO = "refersTo";
16+
public final static String NEXT = "next";
1517

1618
public final static String EXPORTS = "exports";
1719

@@ -41,17 +43,29 @@ public class Edge extends Element {
4143

4244
private String inV;
4345

46+
private List<String> inVs;
47+
4448
public Edge(String id, String label, String outV, String inV) {
4549
super(id, Element.EDGE, label);
4650
this.outV = outV;
4751
this.inV = inV;
4852
}
4953

54+
public Edge(String id, String label, String outV, List<String> inVs) {
55+
super(id, Element.EDGE, label);
56+
this.outV = outV;
57+
this.inVs = inVs;
58+
}
59+
5060
public String getOutV() {
5161
return this.outV;
5262
}
5363

5464
public String getInV() {
5565
return this.inV;
5666
}
67+
68+
public List<String> getInVs() {
69+
return inVs;
70+
}
5771
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
6+
7+
package com.microsoft.java.lsif.core.internal.protocol;
8+
9+
public class Event extends Vertex {
10+
11+
private String kind;
12+
13+
private String scope;
14+
15+
private String data;
16+
17+
public Event(String id, String scope, String kind, String data) {
18+
super(id, Vertex.EVENT);
19+
this.scope = scope;
20+
this.kind = kind;
21+
this.data = data;
22+
}
23+
24+
public String getScope() {
25+
return scope;
26+
}
27+
28+
public String getKind() {
29+
return kind;
30+
}
31+
32+
public String getData() {
33+
return data;
34+
}
35+
36+
public static class EventScope {
37+
public static final String Project = "project";
38+
public static final String DOCUMENT = "document";
39+
}
40+
41+
public static class EventKind {
42+
public static final String BEGIN = "begin";
43+
public static final String END = "end";
44+
}
45+
}

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ImplementationResult.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,9 @@
55

66
package com.microsoft.java.lsif.core.internal.protocol;
77

8-
import java.util.List;
9-
10-
import org.eclipse.lsp4j.Location;
11-
import org.eclipse.lsp4j.jsonrpc.messages.Either;
12-
138
public class ImplementationResult extends Vertex {
149

15-
private List<Either<String, Location>> result;
16-
17-
public ImplementationResult(String id, List<Either<String, Location>> result) {
10+
public ImplementationResult(String id) {
1811
super(id, Vertex.IMPLEMENTATIONRESULT);
19-
this.result = result;
20-
}
21-
22-
public List<Either<String, Location>> getResult() {
23-
return this.result;
2412
}
2513
}

0 commit comments

Comments
 (0)