Change timeout composition on JDTLSProjectCache init

... so now the timeout is measured from the time that
the server is being initialized through LSP protocol
rather than from the time when the server beans are
being created and autowired.
This commit is contained in:
Kris De Volder
2019-08-09 11:11:17 -07:00
parent 39267c74b3
commit 53af53ed16
2 changed files with 10 additions and 4 deletions

View File

@@ -31,6 +31,7 @@ import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import reactor.core.Disposable;
import reactor.core.publisher.Mono;
public class JavaProjectsServiceWithFallback implements JavaProjectsService {
@@ -80,7 +81,9 @@ public class JavaProjectsServiceWithFallback implements JavaProjectsService {
this.mainServiceInitialized = this.server
.onInitialized(main.initialize())
.timeout(Duration.ofSeconds(5))
.doOnError(error -> {
log.warn("JDT-based JavaProject service not available, will use fallback service", error);
})
.toFuture();
this.server.onShutdown(() -> {

View File

@@ -16,6 +16,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -214,7 +215,7 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
@Override
public Mono<Disposable> initialize() {
return server.addClasspathListener(new ClasspathListener() {
return Mono.defer(() -> server.addClasspathListener(new ClasspathListener() {
@Override
public void changed(Event event) {
log.debug("claspath event received {}", event);
@@ -254,7 +255,9 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
}
});
}
}).doOnError(t -> {
})
.timeout(Duration.ofSeconds(5))
.doOnError(t -> {
if (isNoJdtError(t)) {
log.info("JDT Language Server not available. Fallback classpath provider will be used instead.");
} else if (isOldJdt(t)) {
@@ -262,7 +265,7 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
} else {
log.error("Unexpected error registering classpath listener with JDT. Fallback classpath provider will be used instead.", t);
}
});
}));
}
@Override