Boot property for Jandex Index switch. Basic caching for JDTLS index
This commit is contained in:
@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.commons.jdtls;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -31,6 +32,8 @@ import org.springframework.ide.vscode.commons.protocol.java.TypeData;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -46,6 +49,8 @@ public class JdtLsIndex implements ClasspathIndex {
|
||||
private final URI projectUri;
|
||||
private final JdtLsJavadocProvider javadocProvider;
|
||||
|
||||
private Cache<String, Optional<IType>> cache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.SECONDS).build();
|
||||
|
||||
public JdtLsIndex(STS4LanguageClient client, URI projectUri) {
|
||||
this.client = client;
|
||||
this.projectUri = projectUri;
|
||||
@@ -64,16 +69,23 @@ public class JdtLsIndex implements ClasspathIndex {
|
||||
|
||||
@Override
|
||||
public IType findType(String fqName) {
|
||||
JavaDataParams params = new JavaDataParams(projectUri.toString(), "L" + fqName.replace('.', '/') + ";", false);
|
||||
try {
|
||||
TypeData data = client.javaType(params).get(500, TimeUnit.MILLISECONDS);
|
||||
if (data != null) {
|
||||
return toType(data);
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
log.error("", e);
|
||||
return cache.get(fqName, () -> {
|
||||
JavaDataParams params = new JavaDataParams(projectUri.toString(), "L" + fqName.replace('.', '/') + ";", false);
|
||||
try {
|
||||
TypeData data = client.javaType(params).get(500, TimeUnit.MILLISECONDS);
|
||||
if (data != null) {
|
||||
return Optional.ofNullable(toType(data));
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}).orElse(null);
|
||||
} catch (ExecutionException e) {
|
||||
log.error("{}", e);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,6 +43,11 @@
|
||||
<version>${dependencies.version}</version>
|
||||
</dependency>
|
||||
<!-- other -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- Local modified JSON lib packaged to support order in maps -->
|
||||
<groupId>org.springframework.ide.eclipse</groupId>
|
||||
|
||||
@@ -88,8 +88,8 @@ public class BootLanguagServerBootApp {
|
||||
}
|
||||
|
||||
@ConditionalOnMissingClass("org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness")
|
||||
@Bean BootLanguageServerParams serverParams(SimpleLanguageServer server, ValueProviderRegistry valueProviders) {
|
||||
return BootLanguageServerParams.createDefault(server, valueProviders);
|
||||
@Bean BootLanguageServerParams serverParams(SimpleLanguageServer server, ValueProviderRegistry valueProviders, BootLsConfigProperties configProperties) {
|
||||
return BootLanguageServerParams.createDefault(server, valueProviders, configProperties.isEnableJandexIndex());
|
||||
}
|
||||
|
||||
@ConditionalOnMissingClass("org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness")
|
||||
|
||||
@@ -87,11 +87,11 @@ public class BootLanguageServerParams {
|
||||
this.watchDogInterval = watchDogInterval;
|
||||
}
|
||||
|
||||
public static BootLanguageServerParams createDefault(SimpleLanguageServer server, ValueProviderRegistry valueProviders) {
|
||||
public static BootLanguageServerParams createDefault(SimpleLanguageServer server, ValueProviderRegistry valueProviders, boolean isJandexIndex) {
|
||||
// Initialize project finders, project caches and project observers
|
||||
JavaProjectsService jdtProjectCache = new JavaProjectsServiceWithFallback(
|
||||
server,
|
||||
new JdtLsProjectCache(server),
|
||||
new JdtLsProjectCache(server, isJandexIndex),
|
||||
() -> createFallbackProjectCache(server)
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.app;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties("languageserver.boot")
|
||||
public class BootLsConfigProperties {
|
||||
|
||||
/**
|
||||
* Enables/disables Jandex indexing of Java types. When disabled JDT LS will be
|
||||
* used for type and package searches, type finding for FQ name etc.
|
||||
*/
|
||||
private boolean enableJandexIndex = false;
|
||||
|
||||
public boolean isEnableJandexIndex() {
|
||||
return enableJandexIndex;
|
||||
}
|
||||
|
||||
public void setEnableJandexIndex(boolean enableJandexIndex) {
|
||||
this.enableJandexIndex = enableJandexIndex;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -43,15 +43,16 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
|
||||
private static final boolean IS_JANDEX_INDEX = Boolean.getBoolean("sts.lsp.jandex.index");
|
||||
private final boolean IS_JANDEX_INDEX;
|
||||
|
||||
private SimpleLanguageServer server;
|
||||
private Map<String, IJavaProject> table = new HashMap<String, IJavaProject>();
|
||||
private Logger log = LoggerFactory.getLogger(JdtLsProjectCache.class);
|
||||
private List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
public JdtLsProjectCache(SimpleLanguageServer server) {
|
||||
public JdtLsProjectCache(SimpleLanguageServer server, boolean isJandexIndex) {
|
||||
this.server = server;
|
||||
this.IS_JANDEX_INDEX = isJandexIndex;
|
||||
}
|
||||
|
||||
private FileObserver getFileObserver() {
|
||||
|
||||
Reference in New Issue
Block a user