diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/IConstant.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/IConstant.java index bc057d6..dfe54d8 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/IConstant.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/IConstant.java @@ -16,5 +16,5 @@ private IConstant() { public final static String DEFAULT_LSIF_FILE_NAME = "lsif.json"; - public final static String LSIF_FORMAT_VERSION = "0.3.0"; + public final static String LSIF_FORMAT_VERSION = "0.4.3"; } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/EdgeBuilder.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/EdgeBuilder.java index fcb650b..b12d974 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/EdgeBuilder.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/EdgeBuilder.java @@ -5,11 +5,12 @@ package com.microsoft.java.lsif.core.internal.indexer; +import java.util.Collections; +import java.util.List; + import com.microsoft.java.lsif.core.internal.protocol.Document; import com.microsoft.java.lsif.core.internal.protocol.Edge; -import com.microsoft.java.lsif.core.internal.protocol.Project; -import com.microsoft.java.lsif.core.internal.protocol.Range; -import com.microsoft.java.lsif.core.internal.protocol.ReferenceItem; +import com.microsoft.java.lsif.core.internal.protocol.ItemEdge; import com.microsoft.java.lsif.core.internal.protocol.Vertex; public class EdgeBuilder { @@ -20,26 +21,23 @@ public EdgeBuilder(IdGenerator idGenerator) { this.generator = idGenerator; } - public Edge contains(Project from, Document to) { - return new Edge(generator.next(), Edge.CONTAINS, from.getId(), to.getId()); + public Edge contains(Vertex from, Vertex to) { + return new Edge(generator.next(), Edge.CONTAINS, from.getId(), Collections.singletonList(to.getId())); } - public Edge contains(Document from, Range to) { - return new Edge(generator.next(), Edge.CONTAINS, from.getId(), to.getId()); + public Edge item(Vertex from, Vertex to, Document doc, String property) { + return new ItemEdge(generator.next(), Edge.ITEM, from.getId(), Collections.singletonList(to.getId()), + doc.getId(), property); } - public Edge contains(Vertex from, Vertex to) { - return new Edge(generator.next(), Edge.CONTAINS, from.getId(), to.getId()); + public Edge item(Vertex from, List inVs, Document doc, String property) { + return new ItemEdge(generator.next(), Edge.ITEM, from.getId(), inVs, doc.getId(), property); } public Edge hover(Vertex from, Vertex to) { return new Edge(generator.next(), Edge.T_HOVER, from.getId(), to.getId()); } - public Edge referenceItem(Vertex from, Vertex to, String property) { - return new ReferenceItem(generator.next(), Edge.ITEM, from.getId(), to.getId(), property); - } - public Edge definition(Vertex from, Vertex to) { return new Edge(generator.next(), Edge.T_DEFINITION, from.getId(), to.getId()); } @@ -60,8 +58,8 @@ public Edge documentSymbols(Vertex from, Vertex to) { return new Edge(generator.next(), Edge.T_DOCUMENTSYMBOL, from.getId(), to.getId()); } - public Edge refersTo(Vertex from, Vertex to) { - return new Edge(generator.next(), Edge.REFERSTO, from.getId(), to.getId()); + public Edge next(Vertex from, Vertex to) { + return new Edge(generator.next(), Edge.NEXT, from.getId(), to.getId()); } public Edge diagnostic(Vertex from, Vertex to) { diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Indexer.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Indexer.java index e680652..824411f 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Indexer.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Indexer.java @@ -26,11 +26,14 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.ls.core.internal.BuildWorkspaceStatus; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; +import org.eclipse.jdt.ls.core.internal.ResourceUtils; import org.eclipse.lsp4j.ClientCapabilities; import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter; import com.microsoft.java.lsif.core.internal.protocol.Document; +import com.microsoft.java.lsif.core.internal.protocol.Event; import com.microsoft.java.lsif.core.internal.protocol.Project; import com.microsoft.java.lsif.core.internal.visitors.DiagnosticVisitor; import com.microsoft.java.lsif.core.internal.visitors.DocumentVisitor; @@ -58,10 +61,14 @@ public void generateLsif() throws JavaModelException { LsifService lsif = new LsifService(); LsifEmitter.getInstance().start(); - LsifEmitter.getInstance().emit(lsif.getVertexBuilder().metaData()); + LsifEmitter.getInstance().emit(lsif.getVertexBuilder().metaData(ResourceUtils.fixURI(path.toFile().toURI()))); handler.importProject(path, monitor); - handler.buildProject(monitor); + BuildWorkspaceStatus buildStatus = handler.buildProject(monitor); + if (buildStatus != BuildWorkspaceStatus.SUCCEED) { + return; + + } buildIndex(path, monitor, lsif); handler.removeProject(monitor); @@ -85,10 +92,15 @@ private void buildIndex(IPath path, IProgressMonitor monitor, LsifService lsif) Project projVertex = lsif.getVertexBuilder().project(); LsifEmitter.getInstance().emit(projVertex); + LsifEmitter.getInstance() + .emit(lsif.getVertexBuilder().event(Event.EventScope.Project, Event.EventKind.BEGIN, + projVertex.getId())); List sourceList = getAllSourceFiles(javaProject); dumpParallely(sourceList, threadPool, projVertex, lsif, monitor); + LsifEmitter.getInstance().emit( + lsif.getVertexBuilder().event(Event.EventScope.Project, Event.EventKind.END, projVertex.getId())); } threadPool.shutdown(); @@ -141,6 +153,10 @@ private void dumpParallely(List sourceList, ExecutorService th DiagnosticVisitor diagnosticVisitor = new DiagnosticVisitor(lsif, context); diagnosticVisitor.enlist(); + LsifEmitter.getInstance() + .emit(lsif.getVertexBuilder().event(Event.EventScope.DOCUMENT, Event.EventKind.END, + docVertex.getId())); + return 0; })).blockingSubscribe(); } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Repository.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Repository.java index b0a237a..6a16615 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Repository.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/Repository.java @@ -11,8 +11,9 @@ import com.microsoft.java.lsif.core.internal.LsifUtils; import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter; import com.microsoft.java.lsif.core.internal.protocol.Document; +import com.microsoft.java.lsif.core.internal.protocol.Event; import com.microsoft.java.lsif.core.internal.protocol.Range; -import com.microsoft.java.lsif.core.internal.protocol.SymbolData; +import com.microsoft.java.lsif.core.internal.visitors.SymbolData; public class Repository { @@ -47,6 +48,9 @@ public synchronized Document enlistDocument(LsifService service, String uri) { if (targetDocument == null) { targetDocument = service.getVertexBuilder().document(uri); addDocument(targetDocument); + LsifEmitter.getInstance() + .emit(service.getVertexBuilder().event(Event.EventScope.DOCUMENT, Event.EventKind.BEGIN, + targetDocument.getId())); LsifEmitter.getInstance().emit(targetDocument); } @@ -69,10 +73,10 @@ public Range enlistRange(LsifService service, String uri, org.eclipse.lsp4j.Rang return enlistRange(service, enlistDocument(service, uri), lspRange); } - public synchronized SymbolData enlistSymbolData(String id) { + public synchronized SymbolData enlistSymbolData(String id, Document docVertex) { SymbolData symbolData = findSymbolDataById(id); if (symbolData == null) { - symbolData = new SymbolData(); + symbolData = new SymbolData(docVertex); addSymbolData(id, symbolData); } return symbolData; diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/VertexBuilder.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/VertexBuilder.java index 836ac19..ed9ec6a 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/VertexBuilder.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/VertexBuilder.java @@ -10,8 +10,6 @@ import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.Hover; -import org.eclipse.lsp4j.Location; -import org.eclipse.lsp4j.jsonrpc.messages.Either; import com.microsoft.java.lsif.core.internal.JdtlsUtils; import com.microsoft.java.lsif.core.internal.LsifUtils; @@ -19,6 +17,7 @@ import com.microsoft.java.lsif.core.internal.protocol.DiagnosticResult; import com.microsoft.java.lsif.core.internal.protocol.Document; import com.microsoft.java.lsif.core.internal.protocol.DocumentSymbolResult; +import com.microsoft.java.lsif.core.internal.protocol.Event; import com.microsoft.java.lsif.core.internal.protocol.HoverResult; import com.microsoft.java.lsif.core.internal.protocol.ImplementationResult; import com.microsoft.java.lsif.core.internal.protocol.MetaData; @@ -36,8 +35,12 @@ public VertexBuilder(IdGenerator generator) { this.generator = generator; } - public MetaData metaData() { - return new MetaData(generator.next()); + public MetaData metaData(String projectRoot) { + return new MetaData(generator.next(), projectRoot); + } + + public Event event(String scope, String kind, String data) { + return new Event(generator.next(), scope, kind, data); } public Project project() { @@ -60,29 +63,24 @@ public ResultSet resultSet() { return new ResultSet(generator.next()); } - public DefinitionResult definitionResult(String resultId) { - return new DefinitionResult(generator.next(), resultId); + public DefinitionResult definitionResult() { + return new DefinitionResult(generator.next()); } public HoverResult hoverResult(Hover hover) { return new HoverResult(generator.next(), hover); } - public TypeDefinitionResult typeDefinitionResult(String resultId) { - return new TypeDefinitionResult(generator.next(), resultId); + public TypeDefinitionResult typeDefinitionResult() { + return new TypeDefinitionResult(generator.next()); } public ReferenceResult referenceResult() { return new ReferenceResult(generator.next()); } - public ReferenceResult referenceResult(List declarations, List definitions, List references, - List referenceResults) { - return new ReferenceResult(generator.next(), declarations, definitions, references, referenceResults); - } - - public ImplementationResult implementationResult(List> result) { - return new ImplementationResult(generator.next(), result); + public ImplementationResult implementationResult() { + return new ImplementationResult(generator.next()); } public DocumentSymbolResult documentSymbolResult(List symbols) { diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/DefinitionResult.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/DefinitionResult.java index ea41fac..6d202c3 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/DefinitionResult.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/DefinitionResult.java @@ -5,19 +5,9 @@ package com.microsoft.java.lsif.core.internal.protocol; -import java.util.Arrays; -import java.util.List; - public class DefinitionResult extends Vertex { - private List result; - - public DefinitionResult(String id, String result) { + public DefinitionResult(String id) { super(id, Vertex.DEFINITIONRESULT); - this.result = Arrays.asList(result); - } - - public List getResult() { - return this.result; } } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Edge.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Edge.java index 4af4738..e0291c2 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Edge.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Edge.java @@ -5,13 +5,15 @@ package com.microsoft.java.lsif.core.internal.protocol; +import java.util.List; + public class Edge extends Element { public final static String CONTAINS = "contains"; public final static String ITEM = "item"; - public final static String REFERSTO = "refersTo"; + public final static String NEXT = "next"; public final static String EXPORTS = "exports"; @@ -41,12 +43,20 @@ public class Edge extends Element { private String inV; + private List inVs; + public Edge(String id, String label, String outV, String inV) { super(id, Element.EDGE, label); this.outV = outV; this.inV = inV; } + public Edge(String id, String label, String outV, List inVs) { + super(id, Element.EDGE, label); + this.outV = outV; + this.inVs = inVs; + } + public String getOutV() { return this.outV; } @@ -54,4 +64,8 @@ public String getOutV() { public String getInV() { return this.inV; } + + public List getInVs() { + return inVs; + } } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Event.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Event.java new file mode 100644 index 0000000..501128d --- /dev/null +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Event.java @@ -0,0 +1,45 @@ +/* -------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * ------------------------------------------------------------------------------------------ */ + + +package com.microsoft.java.lsif.core.internal.protocol; + +public class Event extends Vertex { + + private String kind; + + private String scope; + + private String data; + + public Event(String id, String scope, String kind, String data) { + super(id, Vertex.EVENT); + this.scope = scope; + this.kind = kind; + this.data = data; + } + + public String getScope() { + return scope; + } + + public String getKind() { + return kind; + } + + public String getData() { + return data; + } + + public static class EventScope { + public static final String Project = "project"; + public static final String DOCUMENT = "document"; + } + + public static class EventKind { + public static final String BEGIN = "begin"; + public static final String END = "end"; + } +} diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ImplementationResult.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ImplementationResult.java index 3d8ed05..1472c85 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ImplementationResult.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ImplementationResult.java @@ -5,21 +5,9 @@ package com.microsoft.java.lsif.core.internal.protocol; -import java.util.List; - -import org.eclipse.lsp4j.Location; -import org.eclipse.lsp4j.jsonrpc.messages.Either; - public class ImplementationResult extends Vertex { - private List> result; - - public ImplementationResult(String id, List> result) { + public ImplementationResult(String id) { super(id, Vertex.IMPLEMENTATIONRESULT); - this.result = result; - } - - public List> getResult() { - return this.result; } } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ItemEdge.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ItemEdge.java new file mode 100644 index 0000000..1ae980b --- /dev/null +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ItemEdge.java @@ -0,0 +1,43 @@ +/* -------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * ------------------------------------------------------------------------------------------ */ + +package com.microsoft.java.lsif.core.internal.protocol; + +import java.util.List; + +public class ItemEdge extends Edge { + + private String document; + + private String property; + + public ItemEdge(String id, String label, String outV, String inV, String documentId, String property) { + super(id, label, outV, inV); + this.document = documentId; + this.property = property; + } + + public ItemEdge(String id, String label, String outV, List inVs, String documentId, String property) { + super(id, label, outV, inVs); + this.document = documentId; + this.property = property; + } + + public String getDocument() { + return document; + } + + public String getProperty() { + return property; + } + + public static class ItemEdgeProperties { + public static final String DECLARATIONS = "declarations"; + public static final String DEFINITIONS = "definitions"; + public static final String REFERENCES = "references"; + public static final String REFERENCE_RESULTS = "referenceResults"; + public static final String IMPLEMENTATION_RESULTS = "implementationResults"; + } +} diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/MetaData.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/MetaData.java index aae9cd9..760ee9c 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/MetaData.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/MetaData.java @@ -9,10 +9,18 @@ public class MetaData extends Vertex { + private static final String DEFAULT_ENCODING = "utf-16"; + public String version; - public MetaData(String id) { + // URI String + public String projectRoot; + + public String positionEncoding = DEFAULT_ENCODING; + + public MetaData(String id, String projectRoot) { super(id, Vertex.METADATA); this.version = IConstant.LSIF_FORMAT_VERSION; + this.projectRoot = projectRoot; } } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Project.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Project.java index 0e7c226..29eeedc 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Project.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Project.java @@ -5,13 +5,15 @@ package com.microsoft.java.lsif.core.internal.protocol; +import com.microsoft.java.lsif.core.internal.IConstant; + public class Project extends Vertex { private String kind; public Project(String id) { super(id, Vertex.PROJECT); - this.kind = "java"; + this.kind = IConstant.JAVA_ID; } public String getKind() { diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ReferenceItem.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ReferenceItem.java deleted file mode 100644 index 8f8f701..0000000 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ReferenceItem.java +++ /dev/null @@ -1,26 +0,0 @@ -/* -------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - * ------------------------------------------------------------------------------------------ */ - -package com.microsoft.java.lsif.core.internal.protocol; - -public class ReferenceItem extends Edge { - - public final static String DECLARATIONS = "declarations"; - - public final static String DEFINITIONS = "definitions"; - - public final static String REFERENCES = "references"; - - private String property; - - public ReferenceItem(String id, String label, String outV, String inV, String property) { - super(id, label, outV, inV); - this.property = property; - } - - public String getProperty() { - return this.property; - } -} diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ReferenceResult.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ReferenceResult.java index 2d3e344..578fde0 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ReferenceResult.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/ReferenceResult.java @@ -5,43 +5,9 @@ package com.microsoft.java.lsif.core.internal.protocol; -import java.util.List; - public class ReferenceResult extends Vertex { - private List declarations; - - private List definitions; - - private List references; - - private List referenceResults; - public ReferenceResult(String id) { super(id, Vertex.REFERENCERESULT); } - - public ReferenceResult(String id, List declarations, List definitions, List references, List referenceResults) { - super(id, Vertex.REFERENCERESULT); - this.declarations = declarations; - this.definitions = definitions; - this.references = references; - this.referenceResults = referenceResults; - } - - public List getDeclarations() { - return this.declarations; - } - - public List getDefinitions() { - return this.definitions; - } - - public List getReferences() { - return this.references; - } - - public List getReferenceResults() { - return this.referenceResults; - } } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/TypeDefinitionResult.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/TypeDefinitionResult.java index 16c5d69..6b3b590 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/TypeDefinitionResult.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/TypeDefinitionResult.java @@ -5,19 +5,9 @@ package com.microsoft.java.lsif.core.internal.protocol; -import java.util.Arrays; -import java.util.List; - public class TypeDefinitionResult extends Vertex { - private List result; - - public TypeDefinitionResult(String id, String result) { + public TypeDefinitionResult(String id) { super(id, Vertex.TYPEDEFINITIONRESULT); - this.result = Arrays.asList(result); - } - - public List getResult() { - return this.result; } } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Vertex.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Vertex.java index 52bcbee..911846c 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Vertex.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/Vertex.java @@ -9,6 +9,8 @@ public class Vertex extends Element { public static final String METADATA = "metaData"; + public static final String EVENT = "$event"; + public static final String PROJECT = "project"; public static final String RANGE = "range"; diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/LsifVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/LsifVisitor.java index 8ccb193..f2a499c 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/LsifVisitor.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/LsifVisitor.java @@ -26,7 +26,6 @@ import com.microsoft.java.lsif.core.internal.protocol.Document; import com.microsoft.java.lsif.core.internal.protocol.Range; import com.microsoft.java.lsif.core.internal.protocol.ResultSet; -import com.microsoft.java.lsif.core.internal.protocol.SymbolData; public class LsifVisitor extends ProtocolVisitor { @@ -77,7 +76,7 @@ private void resolve(int startPosition, int length, boolean needResolveImpl) { } String id = createSymbolKey(definitionLocation); - SymbolData symbolData = Repository.getInstance().enlistSymbolData(id); + SymbolData symbolData = Repository.getInstance().enlistSymbolData(id, docVertex); /* Ensure resultSet */ symbolData.ensureResultSet(lsif, sourceRange); diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/SymbolData.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/SymbolData.java similarity index 67% rename from com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/SymbolData.java rename to com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/SymbolData.java index 64cc158..2c760cb 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/protocol/SymbolData.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/SymbolData.java @@ -3,21 +3,29 @@ * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ -package com.microsoft.java.lsif.core.internal.protocol; +package com.microsoft.java.lsif.core.internal.visitors; import java.util.List; import java.util.stream.Collectors; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Location; -import org.eclipse.lsp4j.jsonrpc.messages.Either; import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter; import com.microsoft.java.lsif.core.internal.indexer.LsifService; import com.microsoft.java.lsif.core.internal.indexer.Repository; -import com.microsoft.java.lsif.core.internal.visitors.VisitorUtils; +import com.microsoft.java.lsif.core.internal.protocol.DefinitionResult; +import com.microsoft.java.lsif.core.internal.protocol.Document; +import com.microsoft.java.lsif.core.internal.protocol.ImplementationResult; +import com.microsoft.java.lsif.core.internal.protocol.ItemEdge; +import com.microsoft.java.lsif.core.internal.protocol.Range; +import com.microsoft.java.lsif.core.internal.protocol.ReferenceResult; +import com.microsoft.java.lsif.core.internal.protocol.ResultSet; +import com.microsoft.java.lsif.core.internal.protocol.TypeDefinitionResult; public class SymbolData { + + private Document document; private ResultSet resultSet; private ReferenceResult referenceResult; private boolean definitionResolved; @@ -25,13 +33,17 @@ public class SymbolData { private boolean implementationResolved; private boolean hoverResolved; + public SymbolData(Document document) { + this.document = document; + } + synchronized public void ensureResultSet(LsifService lsif, Range sourceRange) { if (this.resultSet == null) { ResultSet resultSet = lsif.getVertexBuilder().resultSet(); LsifEmitter.getInstance().emit(resultSet); this.resultSet = resultSet; } - LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().refersTo(sourceRange, this.resultSet)); + LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().next(sourceRange, this.resultSet)); } synchronized public void resolveDefinition(LsifService lsif, Location definitionLocation) { @@ -41,8 +53,9 @@ synchronized public void resolveDefinition(LsifService lsif, Location definition org.eclipse.lsp4j.Range definitionLspRange = definitionLocation.getRange(); Document definitionDocument = Repository.getInstance().enlistDocument(lsif, definitionLocation.getUri()); Range definitionRange = Repository.getInstance().enlistRange(lsif, definitionDocument, definitionLspRange); - - VisitorUtils.ensureDefinitionResult(lsif, this.resultSet, definitionRange); + DefinitionResult defResult = VisitorUtils.ensureDefinitionResult(lsif, this.resultSet); + LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().item(defResult, definitionRange, document, + ItemEdge.ItemEdgeProperties.DEFINITIONS)); this.definitionResolved = true; } @@ -61,7 +74,9 @@ synchronized public void resolveTypeDefinition(LsifService lsif, Document docVer Range typeDefinitionRange = Repository.getInstance().enlistRange(lsif, typeDefinitionDocument, typeDefinitionLspRange); - VisitorUtils.ensureTypeDefinitionResult(lsif, this.resultSet, typeDefinitionRange); + TypeDefinitionResult typeDefResult = VisitorUtils.ensureTypeDefinitionResult(lsif, this.resultSet); + LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().item(typeDefResult, typeDefinitionRange, document, + ItemEdge.ItemEdgeProperties.DEFINITIONS)); } this.typeDefinitionResolved = true; } @@ -77,9 +92,10 @@ synchronized public void resolveImplementation(LsifService lsif, Document docVer if (implementationRanges != null && implementationRanges.size() > 0) { // ImplementationResult - List> result = implementationRanges.stream() - .map(r -> Either.forLeft(r.getId())).collect(Collectors.toList()); - VisitorUtils.ensureImplementationResult(lsif, this.resultSet, result); + List rangeIds = implementationRanges.stream().map(r -> r.getId()).collect(Collectors.toList()); + ImplementationResult implResult = VisitorUtils.ensureImplementationResult(lsif, this.resultSet); + LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().item(implResult, rangeIds, document, + ItemEdge.ItemEdgeProperties.IMPLEMENTATION_RESULTS)); } this.implementationResolved = true; } @@ -87,9 +103,7 @@ synchronized public void resolveImplementation(LsifService lsif, Document docVer synchronized public void resolveReference(LsifService lsif, Document sourceDocument, Location definitionLocation, Range sourceRange) { if (this.referenceResult == null) { - ReferenceResult referenceResult = lsif.getVertexBuilder().referenceResult(); - LsifEmitter.getInstance().emit(referenceResult); - LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().references(this.resultSet, referenceResult)); + ReferenceResult referenceResult = VisitorUtils.ensureReferenceResult(lsif, this.resultSet); this.referenceResult = referenceResult; } @@ -98,9 +112,8 @@ synchronized public void resolveReference(LsifService lsif, Document sourceDocum definitionLocation.getRange()); if (!VisitorUtils.isDefinitionItself(sourceDocument, sourceRange, definitionDocument, definitionRange)) { - LsifEmitter.getInstance() - .emit(lsif.getEdgeBuilder().referenceItem(this.referenceResult, - sourceRange, ReferenceItem.REFERENCES)); + LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().item(this.referenceResult, sourceRange, document, + ItemEdge.ItemEdgeProperties.REFERENCES)); } } diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/VisitorUtils.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/VisitorUtils.java index 6632d75..1367067 100644 --- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/VisitorUtils.java +++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/VisitorUtils.java @@ -33,6 +33,7 @@ import com.microsoft.java.lsif.core.internal.protocol.HoverResult; import com.microsoft.java.lsif.core.internal.protocol.ImplementationResult; import com.microsoft.java.lsif.core.internal.protocol.Range; +import com.microsoft.java.lsif.core.internal.protocol.ReferenceResult; import com.microsoft.java.lsif.core.internal.protocol.ResultSet; import com.microsoft.java.lsif.core.internal.protocol.TypeDefinitionResult; @@ -42,15 +43,16 @@ public class VisitorUtils { public static ResultSet ensureResultSet(LsifService lsif, Range sourceRange) { ResultSet resultSet = lsif.getVertexBuilder().resultSet(); LsifEmitter.getInstance().emit(resultSet); - LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().refersTo(sourceRange, resultSet)); + LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().next(sourceRange, resultSet)); return resultSet; } /* definition */ - public static void ensureDefinitionResult(LsifService lsif, ResultSet resultSet, Range targetRange) { - DefinitionResult defResult = lsif.getVertexBuilder().definitionResult(targetRange.getId()); + public static DefinitionResult ensureDefinitionResult(LsifService lsif, ResultSet resultSet) { + DefinitionResult defResult = lsif.getVertexBuilder().definitionResult(); LsifEmitter.getInstance().emit(defResult); LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().definition(resultSet, defResult)); + return defResult; } /* typeDefinition */ @@ -62,10 +64,18 @@ public static Location resolveTypeDefinitionLocation(Document docVertex, int lin return typeDefinition != null && typeDefinition.size() > 0 ? typeDefinition.get(0) : null; } - public static void ensureTypeDefinitionResult(LsifService lsif, ResultSet resultSet, Range targetRange) { - TypeDefinitionResult typeDefinitionResult = lsif.getVertexBuilder().typeDefinitionResult(targetRange.getId()); + public static TypeDefinitionResult ensureTypeDefinitionResult(LsifService lsif, ResultSet resultSet) { + TypeDefinitionResult typeDefinitionResult = lsif.getVertexBuilder().typeDefinitionResult(); LsifEmitter.getInstance().emit(typeDefinitionResult); LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().typeDefinition(resultSet, typeDefinitionResult)); + return typeDefinitionResult; + } + + public static ReferenceResult ensureReferenceResult(LsifService lsif, ResultSet resultSet) { + ReferenceResult referenceResult = lsif.getVertexBuilder().referenceResult(); + LsifEmitter.getInstance().emit(referenceResult); + LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().references(resultSet, referenceResult)); + return referenceResult; } /* implementation */ @@ -86,11 +96,11 @@ public static List getImplementations(Document docVertex, in return proxy.findImplementations(params, new NullProgressMonitor()); } - public static void ensureImplementationResult(LsifService lsif, ResultSet resultSet, - List> result) { - ImplementationResult implResult = lsif.getVertexBuilder().implementationResult(result); + public static ImplementationResult ensureImplementationResult(LsifService lsif, ResultSet resultSet) { + ImplementationResult implResult = lsif.getVertexBuilder().implementationResult(); LsifEmitter.getInstance().emit(implResult); LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().implementation(resultSet, implResult)); + return implResult; } /* reference */