Skip to content
This repository was archived by the owner on Jun 15, 2026. It is now read-only.
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 @@ -33,7 +33,7 @@ public void start() {
* .lsif.core.internal.protocol.Element)
*/
@Override
public void emit(Element element) {
public synchronized void emit(Element element) {
if (!isFirst) {
LanguageServerIndexerPlugin.println(",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void start() {
* .lsif.core.internal.protocol.Element)
*/
@Override
public void emit(Element element) {
public synchronized void emit(Element element) {
LanguageServerIndexerPlugin.println(JsonParser.toJson(element));

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.microsoft.java.lsif.core.internal.indexer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
Expand All @@ -22,6 +25,7 @@
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.Emitter;
import com.microsoft.java.lsif.core.internal.emitter.JsonEmitter;
import com.microsoft.java.lsif.core.internal.emitter.LineEmitter;
Expand Down Expand Up @@ -109,14 +113,27 @@ private void buildIndex(IPath path, IProgressMonitor monitor, Emitter emitter, L
.enlist(sourceFile);
currentContext.setDocVertex(docVertex);

List<CompletableFuture<Void>> completableFutures = new ArrayList<>();
for (ProtocolVisitor vis : this.visitors) {
vis.setContext(currentContext);
cu.accept(vis);
completableFutures.add(CompletableFuture.runAsync(() -> {
cu.accept(vis);
}));
}

// Dump diagnostic information
DiagnosticVisitor diagnosticVisitor = new DiagnosticVisitor(currentContext, cu);
diagnosticVisitor.enlist();
completableFutures.add(CompletableFuture.runAsync(() -> {
diagnosticVisitor.enlist();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is different from other visitor? Should make them consistent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking: #14

}));
try {
CompletableFuture
.allOf(completableFutures
.toArray(new CompletableFuture[completableFutures.size()]))
.get();
} catch (InterruptedException | ExecutionException e) {
LanguageServerIndexerPlugin.logException("Exception occurs when indexing: ",
e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

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

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.microsoft.java.lsif.core.internal.protocol.Document;
import com.microsoft.java.lsif.core.internal.protocol.HoverResult;
Expand All @@ -17,21 +17,21 @@ public class Repository {

// Key: document URI
// Value: Document object
private Map<String, Document> documentMap = new HashMap<>();
private Map<String, Document> documentMap = new ConcurrentHashMap<>();

// Key: document URI
// Value: ranges among the documents
// Key: LSP range
// LSIF: range
private Map<String, Map<org.eclipse.lsp4j.Range, Range>> rangeMap = new HashMap<>();
private Map<String, Map<org.eclipse.lsp4j.Range, Range>> rangeMap = new ConcurrentHashMap<>();

// Key: Range
// Value: ResultSet that range refers to
private Map<Range, ResultSet> resultSetMap = new HashMap<>();
private Map<Range, ResultSet> resultSetMap = new ConcurrentHashMap<>();

// Key: Hash Code of the Hover Content
// Value: HoverResult
private Map<Integer, HoverResult> hoverResultMap = new HashMap<>();
private Map<Integer, HoverResult> hoverResultMap = new ConcurrentHashMap<>();

private static Repository instance = new Repository();

Expand All @@ -48,7 +48,7 @@ public void addDocument(Document doc) {

public void addRange(Document owner, org.eclipse.lsp4j.Range lspRange, Range range) {
Map<org.eclipse.lsp4j.Range, Range> ranges = this.rangeMap.computeIfAbsent(owner.getUri(),
s -> new HashMap<>());
s -> new ConcurrentHashMap<>());
ranges.putIfAbsent(lspRange, range);
}

Expand Down