Tweak value hint providers in application.properties

See https://www.pivotaltracker.com/story/show/161964105
This commit is contained in:
Kris De Volder
2018-11-15 10:41:55 -08:00
parent 706a870fae
commit f39b845964
5 changed files with 51 additions and 8 deletions

View File

@@ -22,7 +22,6 @@ import org.eclipse.lsp4j.Unregistration;
import org.eclipse.lsp4j.UnregistrationParams;
import org.springframework.ide.vscode.commons.languageserver.json.DidChangeWatchedFilesRegistrationOptions;
import org.springframework.ide.vscode.commons.languageserver.json.FileSystemWatcher;
import org.springframework.ide.vscode.commons.util.Assert;
import org.springframework.ide.vscode.commons.util.BasicFileObserver;
/**

View File

@@ -15,6 +15,7 @@ import java.util.Collection;
import java.util.Map;
import java.util.SortedMap;
import java.util.function.Function;
import java.util.function.Predicate;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry.ValueProviderStrategy;
import org.springframework.ide.vscode.boot.metadata.hints.StsValueHint;
@@ -47,7 +48,7 @@ public class LoggerNameProvider extends CachingValueProvider {
public final Function<Map<String, Object>, ValueProviderStrategy> FACTORY = (params) -> this;
Collection<String> loggerNames(IJavaProject jp) {
Collection<String> loggerGroupNames(IJavaProject jp) {
Builder<String> builder = ImmutableSet.builder();
if (adhocProperties!=null) {
SortedMap<String, PropertyInfo> index = adhocProperties.getIndex(jp).getTreeMap();
@@ -69,7 +70,7 @@ public class LoggerNameProvider extends CachingValueProvider {
@Override
protected Flux<StsValueHint> getValuesAsync(IJavaProject javaProject, String query) {
return Flux.concat(
Flux.fromIterable(loggerNames(javaProject))
Flux.fromIterable(loggerGroupNames(javaProject))
.map(loggerName -> Tuples.of(StsValueHint.create(loggerName), FuzzyMatcher.matchScore(query, loggerName)))
.filter(t -> t.getT2()!=0.0),
javaProject.getIndex()
@@ -81,7 +82,8 @@ public class LoggerNameProvider extends CachingValueProvider {
)
.collectSortedList((o1, o2) -> o2.getT2().compareTo(o1.getT2()))
.flatMapIterable(l -> l)
.map(t -> t.getT1());
.map(t -> t.getT1())
.distinct(h -> h.getValue());
}
}

View File

@@ -50,6 +50,11 @@ public class HintProviders {
public List<TypedProperty> getPropertyHints(String query) {
return ImmutableList.of();
}
@Override
public String toString() {
return "HintProvider.NULL";
}
};
/**

View File

@@ -14,6 +14,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -149,15 +150,22 @@ public abstract class AbstractPropsEditorTest {
private CompletionItem assertCompletionWithLabel(String expectLabel, List<CompletionItem> completions) {
StringBuilder found = new StringBuilder();
List<CompletionItem> matching = new ArrayList<CompletionItem>();
for (CompletionItem c : completions) {
String actualLabel = c.getLabel();
found.append(actualLabel+"\n");
if (actualLabel.equals(expectLabel)) {
return c;
matching.add(c);
}
}
fail("No completion found with label '"+expectLabel+"' in:\n"+found);
return null; //unreachable, but compiler doesn't know that.
if (matching.isEmpty()) {
fail("No completion found with label '"+expectLabel+"' in:\n"+found);
} else if (matching.size() > 1) {
fail("Multiple completion found with identical label '"+expectLabel+"' in:\n"+found);
} else {
return matching.get(0);
}
return null;
}
public void assertCompletionCount(int expected, String editorText) throws Exception {

View File

@@ -10,6 +10,7 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.ide.vscode.boot.properties.reconcile.ApplicationPropertiesProblemType.PROP_DUPLICATE_KEY;
@@ -1150,7 +1151,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
);
}
@Test public void userDefinedLoggerGroups() throws Exception {
@Test public void userDefinedLoggingGroups() throws Exception {
useProject(createPredefinedMavenProject("empty-boot-2.1.0-app"));
adHocProperties.add("logging.group.foobar");
@@ -1184,6 +1185,34 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
}
@Test public void userDefinedLoggingGroupsValueCompletions() throws Exception {
useProject(createPredefinedMavenProject("empty-boot-2.1.0-app"));
assertCompletionWithLabel(
"logging.group.whatever=demo<*>"
, //==============
"com.example.demo",
//=>
"logging.group.whatever=com.example.demo<*>"
);
assertCompletionWithLabel(
"logging.group.whatever=stuff,demo<*>"
, //==============
"com.example.demo",
//=>
"logging.group.whatever=stuff,com.example.demo<*>"
);
assertCompletionWithLabel(
"logging.group.whatever[0]=demo<*>"
, //==============
"com.example.demo",
//=>
"logging.group.whatever[0]=com.example.demo<*>"
);
}
@Test public void testPropertyMapKeyCompletions() throws Exception {
useProject(createPredefinedMavenProject("empty-boot-2.1.0-app"));
assertCompletionWithLabel(