PT #164216122: JDT LS search performance improvement 1
This commit is contained in:
@@ -17,7 +17,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -37,6 +36,7 @@ import reactor.core.Disposable;
|
||||
import reactor.core.Disposables;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
/**
|
||||
* Classpath with Jandex Java index for searching types
|
||||
@@ -101,8 +101,8 @@ public final class JandexClasspath implements ClasspathIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, boolean includeBinaries, boolean includeSystemLibs, Predicate<IType> typeFilter) {
|
||||
return javaIndex.get().fuzzySearchTypes(searchTerm, typeFilter);
|
||||
public Flux<Tuple2<String, Double>> fuzzySearchTypes(String searchTerm, boolean includeBinaries, boolean includeSystemLibs) {
|
||||
return javaIndex.get().fuzzySearchTypes(searchTerm).map(m -> Tuples.of(m.getT2().name().toString(), m.getT3()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 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
|
||||
@@ -13,7 +13,6 @@ package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
@@ -29,7 +28,6 @@ import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
public class JandexIndex extends BasicJandexIndex {
|
||||
|
||||
@@ -83,12 +81,6 @@ public class JandexIndex extends BasicJandexIndex {
|
||||
return Wrappers.wrap(this, match.getT1(), match.getT2(), javadocProvider);
|
||||
}
|
||||
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter) {
|
||||
return fuzzySearchTypes(searchTerm)
|
||||
.map(match -> Tuples.of(createType(Tuples.of(match.getT1(), match.getT2())), match.getT3()))
|
||||
.filter(t -> typeFilter == null || typeFilter.test(t.getT1()));
|
||||
}
|
||||
|
||||
public Flux<IType> allSubtypesOf(IType type) {
|
||||
DotName name = DotName.createSimple(type.getFullyQualifiedName());
|
||||
return allSubtypesOf(name, type.isInterface()).map(match -> createType(match));
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
@@ -19,7 +17,7 @@ import reactor.util.function.Tuple2;
|
||||
public interface ClasspathIndex extends Disposable {
|
||||
|
||||
IType findType(String fqName);
|
||||
Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, boolean includeBinaries, boolean includeSystemLibs, Predicate<IType> typeFilter);
|
||||
Flux<Tuple2<String, Double>> fuzzySearchTypes(String searchTerm, boolean includeBinaries, boolean includeSystemLibs);
|
||||
Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm, boolean includeBinaries, boolean includeSystemLibs);
|
||||
Flux<IType> allSubtypesOf(IType type);
|
||||
Flux<IType> allSuperTypesOf(IType type);
|
||||
|
||||
@@ -123,4 +123,8 @@ public class JavaUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String typeBindingKeyToFqName(String bindingKey) {
|
||||
return bindingKey == null ? null : bindingKey.substring(1, bindingKey.length() - 1).replace('/', '.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.java.ClasspathIndex;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaModuleData;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.java.JavaUtils;
|
||||
import org.springframework.ide.vscode.commons.javadoc.JdtLsJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.protocol.STS4LanguageClient;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.JavaDataParams;
|
||||
@@ -63,7 +63,7 @@ public class JdtLsIndex implements ClasspathIndex {
|
||||
|
||||
private IType toType(TypeData data) {
|
||||
String declaringTypeBindingKey = data.getDeclaringType();
|
||||
String declaringTypeFqName = declaringTypeBindingKey == null ? null : declaringTypeBindingKey.substring(1, declaringTypeBindingKey.length() - 1).replace('/', '.');
|
||||
String declaringTypeFqName = JavaUtils.typeBindingKeyToFqName(declaringTypeBindingKey);
|
||||
return Wrappers.wrap(data, Suppliers.memoize(() -> declaringTypeFqName == null ? null : findType(declaringTypeFqName)), javadocProvider);
|
||||
}
|
||||
|
||||
@@ -89,14 +89,12 @@ public class JdtLsIndex implements ClasspathIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, boolean includeBinaries, boolean includeSystemLibs, Predicate<IType> typeFilter) {
|
||||
public Flux<Tuple2<String, Double>> fuzzySearchTypes(String searchTerm, boolean includeBinaries, boolean includeSystemLibs) {
|
||||
JavaSearchParams searchParams = new JavaSearchParams(projectUri.toString(), searchTerm, includeBinaries, includeSystemLibs);
|
||||
return Mono.fromFuture(client.javaSearchTypes(searchParams))
|
||||
.flatMapMany(results -> Flux.fromIterable(results).publishOn(Schedulers.parallel()))
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::toType)
|
||||
.filter(t -> typeFilter == null || typeFilter.test(t))
|
||||
.map(type -> Tuples.of(type, FuzzyMatcher.matchScore(searchTerm, type.getFullyQualifiedName())))
|
||||
.map(type -> Tuples.of(type, FuzzyMatcher.matchScore(searchTerm, type)))
|
||||
.filter(tuple -> tuple.getT2() != 0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,9 @@ public class JdtLsIndexTest {
|
||||
return gson.fromJson(new FileReader(jsonFile), TypeData.class);
|
||||
}
|
||||
|
||||
private List<TypeData> loadJsonSearchTypeResults(String fileName) throws Exception {
|
||||
private List<String> loadJsonSearchTypeResults(String fileName) throws Exception {
|
||||
File jsonFile = new File(JdtLsIndexTest.class.getResource("/java-data-json/" + fileName).toURI());
|
||||
Type listType = new TypeToken<List<TypeData>>(){}.getType();
|
||||
Type listType = new TypeToken<List<String>>(){}.getType();
|
||||
return gson.fromJson(new FileReader(jsonFile), listType);
|
||||
}
|
||||
|
||||
@@ -138,9 +138,9 @@ public class JdtLsIndexTest {
|
||||
}));
|
||||
// Some valid URI necessary for URI#toString() to succeed
|
||||
JdtLsIndex index = new JdtLsIndex(client, URI.create(System.getProperty("java.io.tmpdir")));
|
||||
List<Tuple2<IType, Double>> results = index.fuzzySearchTypes("util.Map", true, false, null).collectSortedList((o1, o2) -> o2.getT2().compareTo(o1.getT2())).block();
|
||||
IType type = results.get(0).getT1();
|
||||
assertEquals("io.netty.util.Mapping", type.getFullyQualifiedName());
|
||||
List<Tuple2<String, Double>> results = index.fuzzySearchTypes("util.Map", true, false).collectSortedList((o1, o2) -> o2.getT2().compareTo(o1.getT2())).block();
|
||||
String type = results.get(0).getT1();
|
||||
assertEquals("io.netty.util.Mapping", type);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user