Skip to content

Commit

Permalink
Revert "Use a custom ForkJoinWorkerThreadFactory in AsyncCompletionPr…
Browse files Browse the repository at this point in the history
…oposalPopup (eclipse-platform#185)"

This reverts commit 783721b.
  • Loading branch information
Christopher-Hermann authored and iloveeclipse committed May 4, 2023
1 parent e93878e commit 52976b6
Showing 1 changed file with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -44,7 +42,6 @@
import org.eclipse.core.runtime.SafeRunner;

import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
import org.eclipse.jface.util.SafeRunnable;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent;
Expand Down Expand Up @@ -375,38 +372,26 @@ protected List<CompletableFuture<List<ICompletionProposal>>> buildCompletionFutu
}
List<CompletableFuture<List<ICompletionProposal>>> futures = new ArrayList<>(processors.size());
for (IContentAssistProcessor processor : processors) {
// Use a custom ForkJoinWorkerThreadFactory, to prevent issues with a
// potential SecurityManager. Threads created by ForkJoinPool.commonPool(),
// which is used in CompletableFuture.supplyAsync(), get no permissions.
ForkJoinPool commonPool= new ForkJoinPool(ForkJoinPool.getCommonPoolParallelism(),
pool -> new ForkJoinWorkerThread(pool) {
// anonymous subclass to access protected constructor
}, null, false);
futures.add(CompletableFuture.supplyAsync(() -> this.getCompletionProposals(processor, invocationOffset), commonPool));
}
return futures;
}

private List<ICompletionProposal> getCompletionProposals(IContentAssistProcessor processor, int invocationOffset) {
AtomicReference<List<ICompletionProposal>> result= new AtomicReference<>();
SafeRunner.run(new SafeRunnable() {
@Override
public void run() throws Exception {
ICompletionProposal[] proposals= processor.computeCompletionProposals(fViewer, invocationOffset);
if (proposals == null) {
result.set(Collections.emptyList());
} else {
result.set(Arrays.asList(proposals));
futures.add(CompletableFuture.supplyAsync(() -> {
AtomicReference<List<ICompletionProposal>> result= new AtomicReference<>();
SafeRunner.run(() -> {
ICompletionProposal[] proposals= processor.computeCompletionProposals(fViewer, invocationOffset);
if (proposals == null) {
result.set(Collections.emptyList());
} else {
result.set(Arrays.asList(proposals));
}
});
List<ICompletionProposal> proposals= result.get();
if (proposals == null) { // an error occurred during computeCompletionProposal,
// possible improvement: give user feedback by returning an error "proposal" shown
// in completion popup and providing details
return Collections.emptyList();
}
}
});
List<ICompletionProposal> proposals= result.get();
if (proposals == null) { // an error occurred during computeCompletionProposal,
// possible improvement: give user feedback by returning an error "proposal" shown
// in completion popup and providing details
return Collections.emptyList();
return proposals;
}));
}
return proposals;
return futures;
}

private String getTokenContentType(int invocationOffset) throws BadLocationException {
Expand Down

0 comments on commit 52976b6

Please sign in to comment.