diff --git a/com.microsoft.java.lsif.core/.classpath b/com.microsoft.java.lsif.core/.classpath
index 7498423..d37652d 100644
--- a/com.microsoft.java.lsif.core/.classpath
+++ b/com.microsoft.java.lsif.core/.classpath
@@ -2,6 +2,8 @@
+
+
diff --git a/com.microsoft.java.lsif.core/META-INF/MANIFEST.MF b/com.microsoft.java.lsif.core/META-INF/MANIFEST.MF
index 0b60f1f..97d719f 100644
--- a/com.microsoft.java.lsif.core/META-INF/MANIFEST.MF
+++ b/com.microsoft.java.lsif.core/META-INF/MANIFEST.MF
@@ -29,8 +29,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.jdt.ls.core;bundle-version="0.32.0",
org.apache.commons.io;bundle-version="2.2.0"
Export-Package: com.microsoft.java.lsif.core.internal
-Bundle-ClassPath: lib/jsoup-1.9.2.jar,
- lib/remark-1.0.0.jar,
+Bundle-ClassPath: lib/rxjava-2.2.8.jar,
+ lib/reactive-streams-1.0.0.jar,
.
Bundle-Vendor: %Bundle-Vendor
Automatic-Module-Name: org.eclipse.jdt.ls.core
diff --git a/com.microsoft.java.lsif.core/build.properties b/com.microsoft.java.lsif.core/build.properties
index 27d47f2..f4e812b 100644
--- a/com.microsoft.java.lsif.core/build.properties
+++ b/com.microsoft.java.lsif.core/build.properties
@@ -5,7 +5,8 @@ bin.includes = META-INF/,\
plugin.xml,\
lifecycle-mapping-metadata.xml,\
plugin.properties,\
- pom.xml
+ pom.xml,\
+ lib/
src.includes = src/,\
META-INF/,\
plugin.xml,\
diff --git a/com.microsoft.java.lsif.core/pom.xml b/com.microsoft.java.lsif.core/pom.xml
index 9280c30..f165e29 100644
--- a/com.microsoft.java.lsif.core/pom.xml
+++ b/com.microsoft.java.lsif.core/pom.xml
@@ -10,4 +10,32 @@
com.microsoft.java.lsif.core
eclipse-plugin
${base.name} :: Core
+
+
+
+ org.eclipse.tycho
+ tycho-maven-plugin
+ ${tycho-version}
+ true
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+
+ io.reactivex.rxjava2
+ rxjava
+ 2.2.8
+
+
+ org.reactivestreams
+ reactive-streams
+ 1.0.0
+
+
+
+
+
+
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/ASTUtil.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/ASTUtil.java
index bd8163b..ba5d9db 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/ASTUtil.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/ASTUtil.java
@@ -6,14 +6,9 @@
package com.microsoft.java.lsif.core.internal.indexer;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.ITypeRoot;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
@@ -21,8 +16,6 @@
import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
-import com.microsoft.java.lsif.core.internal.IConstant;
-
public final class ASTUtil {
/**
@@ -39,49 +32,36 @@ public static CompilationUnit createAST(final ITypeRoot input, final IProgressMo
final CompilationUnit root[] = new CompilationUnit[1];
- SafeRunner.run(new ISafeRunnable() {
- @Override
- public void run() {
- try {
- if (progressMonitor != null && progressMonitor.isCanceled()) {
- return;
- }
- if (input instanceof ICompilationUnit) {
- ICompilationUnit cu = (ICompilationUnit) input;
- if (cu.isWorkingCopy()) {
- root[0] = cu.reconcile(IASTSharedValues.SHARED_AST_LEVEL, true, null, progressMonitor);
- }
- }
- if (root[0] == null) {
- final ASTParser parser = newASTParser();
- parser.setSource(input);
- root[0] = (CompilationUnit) parser.createAST(progressMonitor);
- }
- // mark as unmodifiable
- ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
- } catch (OperationCanceledException ex) {
- return;
- } catch (JavaModelException e) {
- JavaLanguageServerPlugin.logException(e.getMessage(), e);
- return;
+ try {
+ if (progressMonitor != null && progressMonitor.isCanceled()) {
+ return null;
+ }
+ if (input instanceof ICompilationUnit) {
+ ICompilationUnit cu = (ICompilationUnit) input;
+ if (cu.isWorkingCopy()) {
+ root[0] = cu.reconcile(IASTSharedValues.SHARED_AST_LEVEL, true, null, progressMonitor);
}
}
-
- @Override
- public void handleException(Throwable ex) {
- IStatus status = new Status(IStatus.ERROR, IConstant.PLUGIN_ID, IStatus.OK,
- "Error in JDT Core during AST creation", ex); //$NON-NLS-1$
- JavaLanguageServerPlugin.log(status);
+ if (root[0] == null) {
+ final ASTParser parser = newASTParser();
+ parser.setSource(input);
+ root[0] = (CompilationUnit) parser.createAST(progressMonitor);
}
- });
+ // mark as unmodifiable
+ ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
+ } catch (OperationCanceledException ex) {
+ return null;
+ } catch (Throwable e) {
+ JavaLanguageServerPlugin.logException("Error in JDT Core during AST creation", e);
+ return null;
+ }
return root[0];
}
public static ASTParser newASTParser() {
final ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
- parser.setResolveBindings(true);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setStatementsRecovery(IASTSharedValues.SHARED_AST_STATEMENT_RECOVERY);
- parser.setBindingsRecovery(IASTSharedValues.SHARED_BINDING_RECOVERY);
return parser;
}
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 437c6de..174b21e 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
@@ -1,12 +1,17 @@
+/* --------------------------------------------------------------------------------------------
+ * 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.indexer;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -14,43 +19,37 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.ITypeRoot;
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.JavaLanguageServerPlugin;
import org.eclipse.lsp4j.ClientCapabilities;
-import com.microsoft.java.lsif.core.internal.LanguageServerIndexerPlugin;
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.Project;
+import com.microsoft.java.lsif.core.internal.task.ASTTask;
+import com.microsoft.java.lsif.core.internal.task.TaskType;
import com.microsoft.java.lsif.core.internal.visitors.DefinitionVisitor;
import com.microsoft.java.lsif.core.internal.visitors.DiagnosticVisitor;
import com.microsoft.java.lsif.core.internal.visitors.DocumentVisitor;
import com.microsoft.java.lsif.core.internal.visitors.HoverVisitor;
import com.microsoft.java.lsif.core.internal.visitors.ImplementationsVisitor;
-import com.microsoft.java.lsif.core.internal.visitors.ProtocolVisitor;
import com.microsoft.java.lsif.core.internal.visitors.ReferencesVisitor;
import com.microsoft.java.lsif.core.internal.visitors.TypeDefinitionVisitor;
+import io.reactivex.Observable;
+import io.reactivex.schedulers.Schedulers;
+
public class Indexer {
private WorkspaceHandler handler;
- //@formatter:off
- private List visitors = Arrays.asList(
- new DefinitionVisitor(),
- new TypeDefinitionVisitor(),
- new ImplementationsVisitor(),
- new ReferencesVisitor(),
- new HoverVisitor());
- //@formatter:on
-
public Indexer() {
this.handler = new WorkspaceHandler(System.getProperty("intellinav.repo.path"));
}
@@ -78,59 +77,52 @@ private void buildIndex(IPath path, IProgressMonitor monitor, LsifService lsif)
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ final ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+
for (IProject proj : projects) {
if (proj == null) {
return;
}
-
IJavaProject javaProject = JavaCore.create(proj);
if (!javaProject.exists()) {
continue;
}
+
Project projVertex = lsif.getVertexBuilder().project();
LsifEmitter.getInstance().emit(projVertex);
- IClasspathEntry[] references = javaProject.getRawClasspath();
- for (IClasspathEntry reference : references) {
- if (reference.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
- IPackageFragmentRoot[] fragmentRoots = javaProject.findPackageFragmentRoots(reference);
- for (IPackageFragmentRoot fragmentRoot : fragmentRoots) {
- for (IJavaElement child : fragmentRoot.getChildren()) {
- IPackageFragment fragment = (IPackageFragment) child;
- if (fragment.hasChildren()) {
- for (IJavaElement sourceFile : fragment.getChildren()) {
- if (!sourceFile.exists()) {
- continue;
- }
- CompilationUnit cu = ASTUtil.createAST((ITypeRoot) sourceFile, monitor);
-
- IndexerContext currentContext = new IndexerContext(lsif, null,
- (ITypeRoot) sourceFile, JavaLanguageServerPlugin.getPreferencesManager());
-
- Document docVertex = (new DocumentVisitor(currentContext, projVertex))
- .enlist(sourceFile);
- currentContext.setDocVertex(docVertex);
-
- List> completableFutures = new ArrayList<>();
- for (ProtocolVisitor vis : this.visitors) {
- vis.setContext(currentContext);
- completableFutures.add(CompletableFuture.runAsync(() -> {
- cu.accept(vis);
- }));
- }
-
- DiagnosticVisitor diagnosticVisitor = new DiagnosticVisitor(currentContext, cu);
- completableFutures.add(CompletableFuture.runAsync(() -> {
- diagnosticVisitor.enlist();
- }));
- try {
- CompletableFuture
- .allOf(completableFutures
- .toArray(new CompletableFuture[completableFutures.size()]))
- .get();
- } catch (InterruptedException | ExecutionException e) {
- LanguageServerIndexerPlugin.logException("Exception occurs when indexing: ",
- e);
- }
+
+ List sourceList = getAllSourceFiles(javaProject);
+
+ ConcurrentLinkedQueue taskQueue = new ConcurrentLinkedQueue<>();
+ buildASTParallely(sourceList, taskQueue, threadPool, projVertex, lsif,
+ monitor);
+
+ dumpParallely(taskQueue, threadPool, lsif);
+ }
+
+ threadPool.shutdown();
+ }
+
+ private void initializeJdtls() {
+ Map extendedClientCapabilities = new HashMap<>();
+ extendedClientCapabilities.put("classFileContentsSupport", false);
+ JavaLanguageServerPlugin.getPreferencesManager().updateClientPrefences(new ClientCapabilities(),
+ extendedClientCapabilities);
+ }
+
+ private List getAllSourceFiles(IJavaProject javaProject) throws JavaModelException {
+ List res = new LinkedList<>();
+ IClasspathEntry[] references = javaProject.getRawClasspath();
+ for (IClasspathEntry reference : references) {
+ if (reference.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ IPackageFragmentRoot[] fragmentRoots = javaProject.findPackageFragmentRoots(reference);
+ for (IPackageFragmentRoot fragmentRoot : fragmentRoots) {
+ for (IJavaElement child : fragmentRoot.getChildren()) {
+ IPackageFragment fragment = (IPackageFragment) child;
+ if (fragment.hasChildren()) {
+ for (IJavaElement sourceFile : fragment.getChildren()) {
+ if (sourceFile.exists() && sourceFile instanceof ICompilationUnit) {
+ res.add((ICompilationUnit) sourceFile);
}
}
}
@@ -138,12 +130,59 @@ private void buildIndex(IPath path, IProgressMonitor monitor, LsifService lsif)
}
}
}
+ return res;
}
- private void initializeJdtls() {
- Map extendedClientCapabilities = new HashMap<>();
- extendedClientCapabilities.put("classFileContentsSupport", false);
- JavaLanguageServerPlugin.getPreferencesManager().updateClientPrefences(new ClientCapabilities(),
- extendedClientCapabilities);
+ private void buildASTParallely(List sourceList,
+ ConcurrentLinkedQueue taskQueue, ExecutorService threadPool,
+ Project projVertex, LsifService lsif, IProgressMonitor monitor) {
+ Observable.fromIterable(sourceList)
+ .flatMap(item -> Observable.just(item).observeOn(Schedulers.from(threadPool)).map(sourceFile -> {
+ CompilationUnit cu = ASTUtil.createAST(sourceFile, monitor);
+ Document docVertex = (new DocumentVisitor(lsif, projVertex)).enlist(sourceFile);
+ if (cu == null || docVertex == null) {
+ return 0;
+ }
+ IndexerContext context = new IndexerContext(docVertex, cu);
+ for (TaskType type : TaskType.values()) {
+ taskQueue.add(new ASTTask(type, context));
+ }
+ return 0;
+ })).blockingSubscribe();
+ }
+
+ private void dumpParallely(ConcurrentLinkedQueue taskQueue, ExecutorService threadPool, LsifService lsif) {
+ Observable.fromIterable(taskQueue)
+ .flatMap(item -> Observable.just(item).observeOn(Schedulers.from(threadPool)).map(task -> {
+ switch (task.getTaskType()) {
+ case DEFINITION:
+ DefinitionVisitor definitionVisitor = new DefinitionVisitor(lsif, task.getContext());
+ task.getContext().getCompilationUnit().accept(definitionVisitor);
+ break;
+ case DIAGNOSTIC:
+ DiagnosticVisitor diagnosticVisitor = new DiagnosticVisitor(lsif, task.getContext());
+ diagnosticVisitor.enlist();
+ break;
+ case HOVER:
+ HoverVisitor hoverVisitor = new HoverVisitor(lsif, task.getContext());
+ task.getContext().getCompilationUnit().accept(hoverVisitor);
+ break;
+ case IMPLEMENTATION:
+ ImplementationsVisitor implementationVisitor = new ImplementationsVisitor(lsif,
+ task.getContext());
+ task.getContext().getCompilationUnit().accept(implementationVisitor);
+ break;
+ case REFERENCE:
+ ReferencesVisitor referencesVisitor = new ReferencesVisitor(lsif, task.getContext());
+ task.getContext().getCompilationUnit().accept(referencesVisitor);
+ break;
+ case TYPEDEFINITION:
+ TypeDefinitionVisitor typeDefinitionVisitor = new TypeDefinitionVisitor(lsif,
+ task.getContext());
+ task.getContext().getCompilationUnit().accept(typeDefinitionVisitor);
+ break;
+ }
+ return 0;
+ })).blockingSubscribe();
}
}
\ No newline at end of file
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/IndexerContext.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/IndexerContext.java
index e03e262..3b5d592 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/IndexerContext.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/IndexerContext.java
@@ -5,61 +5,25 @@
package com.microsoft.java.lsif.core.internal.indexer;
-import org.eclipse.jdt.core.ITypeRoot;
-import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import com.microsoft.java.lsif.core.internal.protocol.Document;
public class IndexerContext {
- private LsifService lsif;
-
private Document docVertex;
- private ITypeRoot typeRoot;
-
- private PreferenceManager preferenceManger;
+ private CompilationUnit compilationUnit;
- public IndexerContext(LsifService lsif, Document docVertex, ITypeRoot typeRoot,
- PreferenceManager preferenceManager) {
- this.setLsif(lsif);
+ public IndexerContext(Document docVertex, CompilationUnit compilationUnit) {
this.setDocVertex(docVertex);
- this.setTypeRoot(typeRoot);
- this.setPreferenceManger(preferenceManager);
- }
-
- /**
- * @return the lsif
- */
- public LsifService getLsif() {
- return lsif;
+ this.setCompilationUnit(compilationUnit);
}
public Document getDocVertex() {
return this.docVertex;
}
- /**
- * @return the typeRoot
- */
- public ITypeRoot getTypeRoot() {
- return typeRoot;
- }
-
- /**
- * @param typeRoot the typeRoot to set
- */
- public void setTypeRoot(ITypeRoot typeRoot) {
- this.typeRoot = typeRoot;
- }
-
- /**
- * @param lsif the lsif to set
- */
- public void setLsif(LsifService lsif) {
- this.lsif = lsif;
- }
-
/**
* @param docVertex the docVertex to set
*/
@@ -68,16 +32,16 @@ public void setDocVertex(Document docVertex) {
}
/**
- * @return the preferenceManger
+ * @return the compilationUnit
*/
- public PreferenceManager getPreferenceManger() {
- return preferenceManger;
+ public CompilationUnit getCompilationUnit() {
+ return compilationUnit;
}
/**
- * @param preferenceManger the preferenceManger to set
+ * @param compilationUnit the compilationUnit to set
*/
- public void setPreferenceManger(PreferenceManager preferenceManger) {
- this.preferenceManger = preferenceManger;
+ public void setCompilationUnit(CompilationUnit compilationUnit) {
+ this.compilationUnit = compilationUnit;
}
}
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 3bf9e4f..8d8c073 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
@@ -48,11 +48,11 @@ public static Repository getInstance() {
return RepositoryHolder.INSTANCE;
}
- public synchronized Document enlistDocument(IndexerContext context, String uri) {
+ public synchronized Document enlistDocument(LsifService service, String uri) {
uri = JdtlsUtils.normalizeUri(uri);
Document targetDocument = findDocumentByUri(uri);
if (targetDocument == null) {
- targetDocument = context.getLsif().getVertexBuilder().document(uri);
+ targetDocument = service.getVertexBuilder().document(uri);
addDocument(targetDocument);
LsifEmitter.getInstance().emit(targetDocument);
}
@@ -60,43 +60,43 @@ public synchronized Document enlistDocument(IndexerContext context, String uri)
return targetDocument;
}
- public synchronized ResultSet enlistResultSet(IndexerContext context, Range range) {
+ public synchronized ResultSet enlistResultSet(LsifService service, Range range) {
ResultSet resultSet = findResultSetByRange(range);
if (resultSet == null) {
- resultSet = context.getLsif().getVertexBuilder().resultSet();
+ resultSet = service.getVertexBuilder().resultSet();
addResultSet(range, resultSet);
LsifEmitter.getInstance().emit(resultSet);
- LsifEmitter.getInstance().emit(context.getLsif().getEdgeBuilder().refersTo(range, resultSet));
+ LsifEmitter.getInstance().emit(service.getEdgeBuilder().refersTo(range, resultSet));
}
return resultSet;
}
- public synchronized Range enlistRange(IndexerContext context, Document docVertex,
+ public synchronized Range enlistRange(LsifService service, Document docVertex,
org.eclipse.lsp4j.Range lspRange) {
Range range = findRange(docVertex.getUri(), lspRange);
if (range == null) {
- range = context.getLsif().getVertexBuilder().range(lspRange);
+ range = service.getVertexBuilder().range(lspRange);
addRange(docVertex, lspRange, range);
LsifEmitter.getInstance().emit(range);
- LsifEmitter.getInstance().emit(context.getLsif().getEdgeBuilder().contains(docVertex, range));
+ LsifEmitter.getInstance().emit(service.getEdgeBuilder().contains(docVertex, range));
}
return range;
}
- public synchronized HoverResult enlistHoverResult(IndexerContext context, Hover hover) {
+ public synchronized HoverResult enlistHoverResult(LsifService service, Hover hover) {
int contentHash = hover.getContents().hashCode();
HoverResult hoverResult = findHoverResultByHashCode(contentHash);
if (hoverResult == null) {
- hoverResult = context.getLsif().getVertexBuilder().hoverResult(hover);
+ hoverResult = service.getVertexBuilder().hoverResult(hover);
LsifEmitter.getInstance().emit(hoverResult);
addHoverResult(contentHash, hoverResult);
}
return hoverResult;
}
- public Range enlistRange(IndexerContext context, String uri, org.eclipse.lsp4j.Range lspRange) {
- return enlistRange(context, enlistDocument(context, uri), lspRange);
+ public Range enlistRange(LsifService service, String uri, org.eclipse.lsp4j.Range lspRange) {
+ return enlistRange(service, enlistDocument(service, uri), lspRange);
}
private void addDocument(Document doc) {
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/task/ASTTask.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/task/ASTTask.java
new file mode 100644
index 0000000..b24c5a3
--- /dev/null
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/task/ASTTask.java
@@ -0,0 +1,41 @@
+/* --------------------------------------------------------------------------------------------
+ * 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.task;
+
+import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
+
+public class ASTTask {
+
+ private TaskType taskType;
+
+ private IndexerContext context;
+
+ public ASTTask(TaskType taskType, IndexerContext context) {
+ this.taskType = taskType;
+ this.context = context;
+ }
+
+ /**
+ * @return the taskType
+ */
+ public TaskType getTaskType() {
+ return taskType;
+ }
+
+ /**
+ * @return the context
+ */
+ public IndexerContext getContext() {
+ return context;
+ }
+
+ /**
+ * @param context the context to set
+ */
+ public void setContext(IndexerContext context) {
+ this.context = context;
+ }
+}
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/task/TaskType.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/task/TaskType.java
new file mode 100644
index 0000000..3ac2e5f
--- /dev/null
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/task/TaskType.java
@@ -0,0 +1,10 @@
+/* --------------------------------------------------------------------------------------------
+ * 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.task;
+
+public enum TaskType {
+ DEFINITION, DIAGNOSTIC, HOVER, IMPLEMENTATION, REFERENCE, TYPEDEFINITION
+}
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DefinitionVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DefinitionVisitor.java
index 44494e3..f168281 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DefinitionVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DefinitionVisitor.java
@@ -16,6 +16,7 @@
import com.microsoft.java.lsif.core.internal.JdtlsUtils;
import com.microsoft.java.lsif.core.internal.LanguageServerIndexerPlugin;
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
+import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
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.protocol.DefinitionResult;
@@ -25,7 +26,8 @@
public class DefinitionVisitor extends ProtocolVisitor {
- public DefinitionVisitor() {
+ public DefinitionVisitor(LsifService lsif, IndexerContext context) {
+ super(lsif, context);
}
@Override
@@ -42,10 +44,11 @@ public boolean visit(SimpleType node) {
private void emitDefinition(int startPosition, int length) {
try {
- org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getTypeRoot(), startPosition,
+ org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getCompilationUnit().getTypeRoot(),
+ startPosition,
length);
- IJavaElement element = JDTUtils.findElementAtSelection(this.getContext().getTypeRoot(),
+ IJavaElement element = JDTUtils.findElementAtSelection(this.getContext().getCompilationUnit().getTypeRoot(),
fromRange.getStart().getLine(), fromRange.getStart().getCharacter(), new PreferenceManager(),
new NullProgressMonitor());
if (element == null) {
@@ -57,20 +60,20 @@ private void emitDefinition(int startPosition, int length) {
return;
}
- LsifService lsif = this.getContext().getLsif();
+ LsifService lsif = this.getLsif();
Document docVertex = this.getContext().getDocVertex();
// Source range:
- Range sourceRange = Repository.getInstance().enlistRange(this.getContext(), docVertex, fromRange);
+ Range sourceRange = Repository.getInstance().enlistRange(lsif, docVertex, fromRange);
// Target range:
org.eclipse.lsp4j.Range toRange = targetLocation.getRange();
- Document targetDocument = Repository.getInstance().enlistDocument(this.getContext(),
+ Document targetDocument = Repository.getInstance().enlistDocument(lsif,
targetLocation.getUri());
- Range targetRange = Repository.getInstance().enlistRange(this.getContext(), targetDocument, toRange);
+ Range targetRange = Repository.getInstance().enlistRange(lsif, targetDocument, toRange);
// Result set
- ResultSet resultSet = Repository.getInstance().enlistResultSet(this.getContext(), sourceRange);
+ ResultSet resultSet = Repository.getInstance().enlistResultSet(lsif, sourceRange);
// Link resultSet & definitionResult
DefinitionResult defResult = lsif.getVertexBuilder().definitionResult(targetRange.getId());
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DiagnosticVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DiagnosticVisitor.java
index 624a467..3380653 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DiagnosticVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DiagnosticVisitor.java
@@ -15,7 +15,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaModelMarker;
-import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers;
import org.eclipse.jface.text.BadLocationException;
@@ -35,19 +34,17 @@
public class DiagnosticVisitor extends ProtocolVisitor {
- private CompilationUnit cu;
-
- public DiagnosticVisitor(IndexerContext context, CompilationUnit cu) {
- this.setContext(context);
- this.cu = cu;
+ public DiagnosticVisitor(LsifService lsif, IndexerContext context) {
+ super(lsif, context);
}
public void enlist() {
- LsifService lsif = this.getContext().getLsif();
+ LsifService lsif = this.getLsif();
Document docVertex = this.getContext().getDocVertex();
- IResource resource = cu.getJavaElement().getResource();
+ IResource resource = this.getContext().getCompilationUnit().getJavaElement().getResource();
if (resource == null || !resource.exists()) {
- LanguageServerIndexerPlugin.logError("Cannot find resource for: " + cu.getJavaElement().getElementName());
+ LanguageServerIndexerPlugin.logError("Cannot find resource for: "
+ + this.getContext().getCompilationUnit().getJavaElement().getElementName());
return;
}
IMarker[] markers = null;
@@ -62,7 +59,8 @@ public void enlist() {
}
markers = Arrays.copyOf(javaMarkers, javaMarkers.length + taskMarkers.length);
System.arraycopy(taskMarkers, 0, markers, javaMarkers.length, taskMarkers.length);
- document = JsonRpcHelpers.toDocument(cu.getJavaElement().getOpenable().getBuffer());
+ document = JsonRpcHelpers
+ .toDocument(this.getContext().getCompilationUnit().getJavaElement().getOpenable().getBuffer());
} catch (Throwable ex) {
LanguageServerIndexerPlugin.logException("Exception when dumping diagnostic information ", ex);
return;
@@ -70,7 +68,8 @@ public void enlist() {
if (document == null) {
LanguageServerIndexerPlugin
- .logError("Cannot parse the document for: " + cu.getJavaElement().getElementName());
+ .logError("Cannot parse the document for: "
+ + this.getContext().getCompilationUnit().getJavaElement().getElementName());
return;
}
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DocumentVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DocumentVisitor.java
index 4f526c1..873f44b 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DocumentVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DocumentVisitor.java
@@ -19,7 +19,7 @@
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
-import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
+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.protocol.Document;
import com.microsoft.java.lsif.core.internal.protocol.DocumentSymbolResult;
@@ -29,15 +29,15 @@ public class DocumentVisitor extends ProtocolVisitor {
private Project projVertex;
- public DocumentVisitor(IndexerContext context, Project projVertex) {
- this.setContext(context);
+ public DocumentVisitor(LsifService lsif, Project projVertex) {
+ super(lsif, null /* DocumentVisitor does not need context information for parallel build */);
this.projVertex = projVertex;
}
public Document enlist(IJavaElement sourceFile) {
String uri = ResourceUtils.fixURI(sourceFile.getResource().getRawLocationURI());
- Document docVertex = Repository.getInstance().enlistDocument(this.getContext(), uri);
- LsifEmitter.getInstance().emit(this.getContext().getLsif().getEdgeBuilder().contains(projVertex, docVertex));
+ Document docVertex = Repository.getInstance().enlistDocument(this.getLsif(), uri);
+ LsifEmitter.getInstance().emit(this.getLsif().getEdgeBuilder().contains(projVertex, docVertex));
handleDocumentSymbol(docVertex);
return docVertex;
@@ -46,11 +46,11 @@ public Document enlist(IJavaElement sourceFile) {
// TODO: Refine the symbol to range-based
private void handleDocumentSymbol(Document docVertex) {
List symbols = this.handle(docVertex.getUri());
- DocumentSymbolResult documentSymbolResult = this.getContext().getLsif().getVertexBuilder()
+ DocumentSymbolResult documentSymbolResult = this.getLsif().getVertexBuilder()
.documentSymbolResult(symbols);
LsifEmitter.getInstance().emit(documentSymbolResult);
LsifEmitter.getInstance()
- .emit(this.getContext().getLsif().getEdgeBuilder().documentSymbols(docVertex, documentSymbolResult));
+ .emit(this.getLsif().getEdgeBuilder().documentSymbols(docVertex, documentSymbolResult));
}
private List handle(String uri) {
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/HoverVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/HoverVisitor.java
index 13aacf7..3b9baab 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/HoverVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/HoverVisitor.java
@@ -12,6 +12,7 @@
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
+import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.handlers.HoverHandler;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.MarkedString;
@@ -23,6 +24,7 @@
import com.microsoft.java.lsif.core.internal.LanguageServerIndexerPlugin;
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
+import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
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.protocol.Document;
@@ -32,7 +34,8 @@
public class HoverVisitor extends ProtocolVisitor {
- public HoverVisitor() {
+ public HoverVisitor(LsifService lsif, IndexerContext context) {
+ super(lsif, context);
}
@Override
@@ -48,10 +51,11 @@ public boolean visit(SimpleName node) {
}
private void emitHover(int startPosition, int length) {
- LsifService lsif = this.getContext().getLsif();
+ LsifService lsif = this.getLsif();
Document docVertex = this.getContext().getDocVertex();
try {
- org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getTypeRoot(), startPosition,
+ org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getCompilationUnit().getTypeRoot(),
+ startPosition,
length);
// Link resultSet & definitionResult
@@ -61,12 +65,12 @@ private void emitHover(int startPosition, int length) {
}
// Source range:
- Range sourceRange = Repository.getInstance().enlistRange(this.getContext(), docVertex, fromRange);
+ Range sourceRange = Repository.getInstance().enlistRange(lsif, docVertex, fromRange);
// Result set
- ResultSet resultSet = Repository.getInstance().enlistResultSet(this.getContext(), sourceRange);
+ ResultSet resultSet = Repository.getInstance().enlistResultSet(lsif, sourceRange);
- HoverResult hoverResult = Repository.getInstance().enlistHoverResult(this.getContext(), result);
+ HoverResult hoverResult = Repository.getInstance().enlistHoverResult(lsif, result);
LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().hover(resultSet, hoverResult));
} catch (Throwable ex) {
LanguageServerIndexerPlugin.logException("Exception when dumping hover information ", ex);
@@ -77,7 +81,7 @@ private Hover hover(int line, int character) {
TextDocumentPositionParams params = new TextDocumentPositionParams(
new TextDocumentIdentifier(this.getContext().getDocVertex().getUri()), new Position(line, character));
- HoverHandler proxy = new HoverHandler(this.getContext().getPreferenceManger());
+ HoverHandler proxy = new HoverHandler(JavaLanguageServerPlugin.getPreferencesManager());
return proxy.hover(params, new NullProgressMonitor());
}
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ImplementationsVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ImplementationsVisitor.java
index a4ae093..c517a15 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ImplementationsVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ImplementationsVisitor.java
@@ -16,6 +16,7 @@
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
+import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.handlers.ImplementationsHandler;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
@@ -25,6 +26,7 @@
import com.microsoft.java.lsif.core.internal.LanguageServerIndexerPlugin;
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
+import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
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.protocol.ImplementationResult;
@@ -33,7 +35,8 @@
public class ImplementationsVisitor extends ProtocolVisitor {
- public ImplementationsVisitor() {
+ public ImplementationsVisitor(LsifService lsif, IndexerContext context) {
+ super(lsif, context);
}
@Override
@@ -55,9 +58,9 @@ public boolean visit(SimpleType node) {
private void emitImplementation(int startPosition, int length) {
org.eclipse.lsp4j.Range fromRange;
try {
- fromRange = JDTUtils.toRange(this.getContext().getTypeRoot(), startPosition, length);
+ fromRange = JDTUtils.toRange(this.getContext().getCompilationUnit().getTypeRoot(), startPosition, length);
- LsifService lsif = this.getContext().getLsif();
+ LsifService lsif = this.getLsif();
List ranges = getImplementationRanges(fromRange.getStart().getLine(),
fromRange.getStart().getCharacter());
@@ -66,11 +69,11 @@ private void emitImplementation(int startPosition, int length) {
}
// Source range:
- Range sourceRange = Repository.getInstance().enlistRange(this.getContext(),
+ Range sourceRange = Repository.getInstance().enlistRange(lsif,
this.getContext().getDocVertex(), fromRange);
// Result set
- ResultSet resultSet = Repository.getInstance().enlistResultSet(this.getContext(), sourceRange);
+ ResultSet resultSet = Repository.getInstance().enlistResultSet(lsif, sourceRange);
// ImplementationResult
List> result = ranges.stream()
@@ -95,7 +98,7 @@ private List getImplementationRanges(int line, int character) {
return Collections.emptyList();
}
return locations.stream()
- .map(loc -> Repository.getInstance().enlistRange(this.getContext(), loc.getUri(), loc.getRange()))
+ .map(loc -> Repository.getInstance().enlistRange(this.getLsif(), loc.getUri(), loc.getRange()))
.filter(r -> r != null)
.collect(Collectors.toList());
}
@@ -104,7 +107,7 @@ private List extends Location> getImplementations(int line, int character) {
TextDocumentPositionParams params = new TextDocumentPositionParams(
new TextDocumentIdentifier(this.getContext().getDocVertex().getUri()), new Position(line, character));
- ImplementationsHandler proxy = new ImplementationsHandler(this.getContext().getPreferenceManger());
+ ImplementationsHandler proxy = new ImplementationsHandler(JavaLanguageServerPlugin.getPreferencesManager());
return proxy.findImplementations(params, new NullProgressMonitor());
}
}
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ProtocolVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ProtocolVisitor.java
index 9155a87..ba0d1a5 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ProtocolVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ProtocolVisitor.java
@@ -8,21 +8,46 @@
import org.eclipse.jdt.core.dom.ASTVisitor;
import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
+import com.microsoft.java.lsif.core.internal.indexer.LsifService;
public abstract class ProtocolVisitor extends ASTVisitor {
+ private LsifService lsif;
+
private IndexerContext context;
/**
* Constructor
*/
- public ProtocolVisitor() {
+ public ProtocolVisitor(LsifService lsif, IndexerContext context) {
+ this.setLsif(lsif);
+ this.setContext(context);
}
+ /**
+ * @return the service
+ */
+ public LsifService getLsif() {
+ return lsif;
+ }
+
+ /**
+ * @param service the service to set
+ */
+ public void setLsif(LsifService lsif) {
+ this.lsif = lsif;
+ }
+
+ /**
+ * @return the context
+ */
public IndexerContext getContext() {
- return this.context;
+ return context;
}
+ /**
+ * @param context the context to set
+ */
public void setContext(IndexerContext context) {
this.context = context;
}
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ReferencesVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ReferencesVisitor.java
index bd29cdc..bfebae3 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ReferencesVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ReferencesVisitor.java
@@ -12,6 +12,7 @@
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
+import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.ReferenceContext;
@@ -20,6 +21,7 @@
import com.microsoft.java.lsif.core.internal.LanguageServerIndexerPlugin;
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
+import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
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.protocol.Range;
@@ -29,7 +31,8 @@
public class ReferencesVisitor extends ProtocolVisitor {
- public ReferencesVisitor() {
+ public ReferencesVisitor(LsifService lsif, IndexerContext context) {
+ super(lsif, context);
}
@Override
@@ -47,14 +50,15 @@ public boolean visit(SimpleName node) {
public void emitReferences(int startPosition, int length) {
try {
- org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getTypeRoot(), startPosition,
+ org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getCompilationUnit().getTypeRoot(),
+ startPosition,
length);
if (fromRange == null) {
return;
}
- LsifService lsif = this.getContext().getLsif();
+ LsifService lsif = this.getLsif();
List ranges = getReferenceRanges(fromRange.getStart().getLine(),
fromRange.getStart().getCharacter());
@@ -63,11 +67,11 @@ public void emitReferences(int startPosition, int length) {
}
// Source range:
- Range sourceRange = Repository.getInstance().enlistRange(this.getContext(),
+ Range sourceRange = Repository.getInstance().enlistRange(lsif,
this.getContext().getDocVertex(), fromRange);
// Result set
- ResultSet resultSet = Repository.getInstance().enlistResultSet(this.getContext(), sourceRange);
+ ResultSet resultSet = Repository.getInstance().enlistResultSet(lsif, sourceRange);
// ReferenceResult
ReferenceResult refResult = lsif.getVertexBuilder().referenceResult();
@@ -86,7 +90,7 @@ public void emitReferences(int startPosition, int length) {
private List getReferenceRanges(int line, int character) {
List locations = getReferenceLocations(line, character);
return locations.stream()
- .map(loc -> Repository.getInstance().enlistRange(this.getContext(), loc.getUri(), loc.getRange()))
+ .map(loc -> Repository.getInstance().enlistRange(this.getLsif(), loc.getUri(), loc.getRange()))
.filter(r -> r != null)
.collect(Collectors.toList());
}
@@ -97,7 +101,7 @@ private List getReferenceLocations(int line, int character) {
params.setPosition(new Position(line, character));
org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler proxy = new org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler(
- this.getContext().getPreferenceManger());
+ JavaLanguageServerPlugin.getPreferencesManager());
List references = proxy.findReferences(params, new NullProgressMonitor());
return references;
}
diff --git a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/TypeDefinitionVisitor.java b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/TypeDefinitionVisitor.java
index cd036ed..fe7e78d 100644
--- a/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/TypeDefinitionVisitor.java
+++ b/com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/TypeDefinitionVisitor.java
@@ -19,6 +19,7 @@
import com.microsoft.java.lsif.core.internal.LanguageServerIndexerPlugin;
import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
+import com.microsoft.java.lsif.core.internal.indexer.IndexerContext;
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.protocol.Document;
@@ -28,7 +29,8 @@
public class TypeDefinitionVisitor extends ProtocolVisitor {
- public TypeDefinitionVisitor() {
+ public TypeDefinitionVisitor(LsifService lsif, IndexerContext context) {
+ super(lsif, context);
}
@Override
@@ -46,7 +48,8 @@ public boolean visit(SimpleType node) {
private void emitTypeDefinition(int startPosition, int length) {
try {
- org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getTypeRoot(), startPosition,
+ org.eclipse.lsp4j.Range fromRange = JDTUtils.toRange(this.getContext().getCompilationUnit().getTypeRoot(),
+ startPosition,
length);
if (fromRange == null) {
@@ -60,21 +63,21 @@ private void emitTypeDefinition(int startPosition, int length) {
return;
}
- LsifService lsif = this.getContext().getLsif();
+ LsifService lsif = this.getLsif();
Document docVertex = this.getContext().getDocVertex();
// Definition start position
// Source range:
- Range sourceRange = Repository.getInstance().enlistRange(this.getContext(), docVertex, fromRange);
+ Range sourceRange = Repository.getInstance().enlistRange(lsif, docVertex, fromRange);
// Target range:
org.eclipse.lsp4j.Range toRange = targetLocation.getRange();
- Document targetDocument = Repository.getInstance().enlistDocument(this.getContext(),
+ Document targetDocument = Repository.getInstance().enlistDocument(lsif,
targetLocation.getUri());
- Range targetRange = Repository.getInstance().enlistRange(this.getContext(), targetDocument, toRange);
+ Range targetRange = Repository.getInstance().enlistRange(lsif, targetDocument, toRange);
// Result set
- ResultSet resultSet = Repository.getInstance().enlistResultSet(this.getContext(), sourceRange);
+ ResultSet resultSet = Repository.getInstance().enlistResultSet(lsif, sourceRange);
// Link resultSet & typeDefinitionResult
TypeDefinitionResult defResult = lsif.getVertexBuilder().typeDefinitionResult(targetRange.getId());