Skip to content

Commit 88c65ce

Browse files
Give ResponseStore for code actions a minimum history size of 8.
1 parent 8b9892c commit 88c65ce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeActionHandler.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.concurrent.ForkJoinPool;
2626
import java.util.stream.Collectors;
2727

28+
import javax.tools.Diagnostic;
29+
2830
import org.apache.commons.lang3.StringUtils;
2931
import org.eclipse.core.runtime.CoreException;
3032
import org.eclipse.core.runtime.IProgressMonitor;
@@ -50,6 +52,7 @@
5052
import org.eclipse.jdt.ls.core.internal.corrections.QuickFixProcessor;
5153
import org.eclipse.jdt.ls.core.internal.corrections.RefactorProcessor;
5254
import org.eclipse.jdt.ls.core.internal.corrections.proposals.NewCUProposal;
55+
import org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.CodeActionData;
5356
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
5457
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
5558
import org.eclipse.jdt.ls.core.internal.text.correction.AssignToVariableAssistCommandProposal;
@@ -67,18 +70,19 @@
6770
import org.eclipse.lsp4j.CodeActionOptions;
6871
import org.eclipse.lsp4j.CodeActionParams;
6972
import org.eclipse.lsp4j.Command;
70-
import org.eclipse.lsp4j.Diagnostic;
7173
import org.eclipse.lsp4j.DiagnosticSeverity;
72-
import org.eclipse.lsp4j.Range;
7374
import org.eclipse.lsp4j.WorkspaceEdit;
7475
import org.eclipse.lsp4j.jsonrpc.messages.Either;
7576

7677
import com.google.gson.JsonArray;
7778
import com.google.gson.JsonElement;
7879

7980
public class CodeActionHandler {
81+
// Store a few of the latest Code Action results because any one of them might be resolved further.
82+
// Multiple Code Actions are computed in parallel through ForkJoinPool's common pool leading to a race condition where
83+
// the last Code Action request to finish processing is not the client's latest request. History size must scale with pool size.
8084
public static final ResponseStore<Either<ChangeCorrectionProposalCore, CodeActionProposal>> codeActionStore
81-
= new ResponseStore<>(ForkJoinPool.commonPool().getParallelism());
85+
= new ResponseStore<>(Math.max(ForkJoinPool.getCommonPoolParallelism(), 8));
8286
public static final String COMMAND_ID_APPLY_EDIT = "java.apply.workspaceEdit";
8387

8488
public static CodeActionOptions createOptions(PreferenceManager preferenceManager) {

0 commit comments

Comments
 (0)