Add support for 'group' parameter in logger-name hint provider

See: https://github.com/spring-projects/sts4/issues/102
This commit is contained in:
Kris De Volder
2018-11-19 11:15:53 -08:00
parent 00e1192f17
commit cf64f9ea60
6 changed files with 33 additions and 6 deletions

View File

@@ -83,7 +83,7 @@ public class BootLanguagServerBootApp {
@Bean InitializingBean initializeValueProviders(ValueProviderRegistry r, @Qualifier("adHocProperties") ProjectBasedPropertyIndexProvider adHocProperties) {
return () -> {
r.def("logger-name", new LoggerNameProvider(adHocProperties).FACTORY);
r.def("logger-name", LoggerNameProvider.factory(adHocProperties));
r.def("class-reference", ClassReferenceProvider.FACTORY);
};
}

View File

@@ -56,5 +56,4 @@ class ConfigurationMetadataItem extends ConfigurationMetadataProperty {
public void setSourceMethod(String sourceMethod) {
this.sourceMethod = sourceMethod;
}
}

View File

@@ -39,18 +39,23 @@ import reactor.util.function.Tuples;
public class LoggerNameProvider extends CachingValueProvider {
private static final String LOGGING_GROUPS_PREFIX = "logging.group.";
private final ProjectBasedPropertyIndexProvider adhocProperties;
private final boolean includeGroups;
public LoggerNameProvider(ProjectBasedPropertyIndexProvider adhocProperties) {
public LoggerNameProvider(ProjectBasedPropertyIndexProvider adhocProperties, boolean includeGroups) {
this.adhocProperties = adhocProperties;
this.includeGroups = includeGroups;
}
public final Function<Map<String, Object>, ValueProviderStrategy> FACTORY = (params) -> this;
public static final Function<Map<String, Object>, ValueProviderStrategy> factory(ProjectBasedPropertyIndexProvider adhocProperties) {
return (params) -> {
return new LoggerNameProvider(adhocProperties, (boolean) params.getOrDefault("group", true));
};
}
Collection<String> loggerGroupNames(IJavaProject jp) {
Builder<String> builder = ImmutableSet.builder();
if (adhocProperties!=null) {
if (adhocProperties!=null && includeGroups) {
SortedMap<String, PropertyInfo> index = adhocProperties.getIndex(jp).getTreeMap();
index = index.subMap(LOGGING_GROUPS_PREFIX, LOGGING_GROUPS_PREFIX+Character.MAX_VALUE);
for (String prop : index.keySet()) {

View File

@@ -21,6 +21,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.TextDocumentIdentifier;
@@ -136,6 +137,14 @@ public abstract class AbstractPropsEditorTest {
assertCompletions(text /*NONE*/);
}
public void assertNoCompletionWithLabel(String textBefore, String expectLabel) throws Exception {
Editor editor = newEditor(textBefore);
List<CompletionItem> completions = editor.getCompletions().stream().filter(c -> c.getLabel().equals(expectLabel)).collect(Collectors.toList());
if (!completions.isEmpty()) {
fail("Expecting no completions with label '"+expectLabel+"', but found some");
}
}
/**
* Checks that completions contains a completion with a given display string (and check that
* it applies as expected).

View File

@@ -1183,6 +1183,10 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
"logging.level.indexed=<*>"
);
//Check whether the added parameter to disable group name hints is obeyed:
assertNoCompletionWithLabel("logging.group.whatever=<*>", "foobar");
assertNoCompletionWithLabel("logging.group.whatever=<*>", "user-defined");
assertNoCompletionWithLabel("logging.group.whatever=<*>", "indexed");
}
@Test public void userDefinedLoggingGroupsValueCompletions() throws Exception {

View File

@@ -296,6 +296,16 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
" group:\n"+
" whatever: stuff,com.example.demo<*>"
);
//Check whether the added parameter to disable group name hints is obeyed:
assertNoCompletionWithLabel(
"logging:\n" +
" group:\n"+
" whatever: <*>"
,
"foobar"
);
}
///////////////////// ported tests from old STS code base ////////////////////////////////////////////////