diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/jdt/SpringBootJavaCompletionProposalComputer.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/jdt/SpringBootJavaCompletionProposalComputer.java index fddb5075f..adac58e61 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/jdt/SpringBootJavaCompletionProposalComputer.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/jdt/SpringBootJavaCompletionProposalComputer.java @@ -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 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 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