Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update the implementation to V4 protocol #45

Merged
merged 8 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String> 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());
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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<ICompilationUnit> 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();
Expand Down Expand Up @@ -141,6 +153,10 @@ private void dumpParallely(List<ICompilationUnit> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
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;
import com.microsoft.java.lsif.core.internal.protocol.DefinitionResult;
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;
Expand All @@ -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() {
Expand All @@ -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<String> declarations, List<String> definitions, List<String> references,
List<String> referenceResults) {
return new ReferenceResult(generator.next(), declarations, definitions, references, referenceResults);
}

public ImplementationResult implementationResult(List<Either<String, Location>> result) {
return new ImplementationResult(generator.next(), result);
public ImplementationResult implementationResult() {
return new ImplementationResult(generator.next());
}

public DocumentSymbolResult documentSymbolResult(List<DocumentSymbol> symbols) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> result;

public DefinitionResult(String id, String result) {
public DefinitionResult(String id) {
super(id, Vertex.DEFINITIONRESULT);
this.result = Arrays.asList(result);
}

public List<String> getResult() {
return this.result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -41,17 +43,29 @@ public class Edge extends Element {

private String inV;

private List<String> 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<String> inVs) {
super(id, Element.EDGE, label);
this.outV = outV;
this.inVs = inVs;
}

public String getOutV() {
return this.outV;
}

public String getInV() {
return this.inV;
}

public List<String> getInVs() {
return inVs;
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Either<String, Location>> result;

public ImplementationResult(String id, List<Either<String, Location>> result) {
public ImplementationResult(String id) {
super(id, Vertex.IMPLEMENTATIONRESULT);
this.result = result;
}

public List<Either<String, Location>> getResult() {
return this.result;
}
}
Loading