added a timeout to the proposal computing when invoked for a java source to avoid JDT disabling us on longer-running tasks
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -11,7 +11,12 @@
|
||||
package org.springframework.tooling.boot.java.ls.jdt;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
|
||||
@@ -25,6 +30,9 @@ import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor;
|
||||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
public class SpringBootJavaCompletionProposalComputer implements IJavaCompletionProposalComputer {
|
||||
|
||||
private static TimeUnit TIMEOUT_UNIT = TimeUnit.MILLISECONDS;
|
||||
private static long TIMEOUT_LENGTH = 2000;
|
||||
|
||||
private LSContentAssistProcessor lsContentAssistProcessor;
|
||||
|
||||
@@ -39,10 +47,16 @@ public class SpringBootJavaCompletionProposalComputer implements IJavaCompletion
|
||||
@Override
|
||||
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
|
||||
IProgressMonitor monitor) {
|
||||
System.out.println("Spring Boot Java Completion Proposal - compute completion proposals");
|
||||
|
||||
ICompletionProposal[] proposals = lsContentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset());
|
||||
return Arrays.asList(proposals);
|
||||
CompletableFuture<ICompletionProposal[]> future = CompletableFuture.supplyAsync(() -> {
|
||||
return lsContentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset());
|
||||
});
|
||||
|
||||
try {
|
||||
return Arrays.asList(future.get(TIMEOUT_LENGTH, TIMEOUT_UNIT));
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
e.printStackTrace();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user