Try to shorten labels for boot property completions
See: https://github.com/spring-projects/sts4/issues/361
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -41,12 +42,15 @@ import org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigato
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.LazyProposalApplier;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.TransformedCompletion;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.PrefixFinder;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.CollectionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMap;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMap.Match;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
|
||||
import org.springframework.ide.vscode.commons.util.Streams;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
import org.springframework.ide.vscode.commons.util.text.DocumentRegion;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
import org.springframework.ide.vscode.java.properties.antlr.parser.AntlrParser;
|
||||
@@ -359,10 +363,23 @@ public class PropertiesCompletionProposalsCalculator {
|
||||
log.error("{}", e);
|
||||
}
|
||||
});
|
||||
return proposals;
|
||||
return elideCommonPrefix(prefix, proposals);
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private Collection<ICompletionProposal> elideCommonPrefix(String basePrefix, ArrayList<ICompletionProposal> proposals) {
|
||||
String prefix = StringUtil.commonPrefix(Stream.concat(Stream.of(basePrefix), proposals.stream().map(ICompletionProposal::getLabel)));
|
||||
int lastDot = prefix.lastIndexOf('.');
|
||||
if (lastDot>=0) {
|
||||
for (int i = 0; i < proposals.size(); i++) {
|
||||
ICompletionProposal p = proposals.get(i);
|
||||
proposals.set(i, p.dropLabelPrefix(lastDot+1));
|
||||
}
|
||||
}
|
||||
return proposals;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -85,6 +85,57 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
editor.assertProblems("no-bool|boolean");
|
||||
}
|
||||
|
||||
@Test public void abbreviateLongPrefixCompletions() throws Exception {
|
||||
//See: https://github.com/spring-projects/sts4/issues/361
|
||||
Editor editor;
|
||||
|
||||
data("spring.data.jpa.very.long.foobar", "java.lang.String", null, null);
|
||||
data("spring.data.jpa.very.long.barbar", "java.lang.String", null, null);
|
||||
data("spring.data.jpa.very.long.foofoo", "java.lang.String", null, null);
|
||||
data("spring.data.jpa.very.long.barfoo", "java.lang.String", null, null);
|
||||
data("spring.data.jpa.very.long.foobar.more", "java.lang.String", null, null);
|
||||
data("spring.data.jpa.very.long.barbar.more", "java.lang.String", null, null);
|
||||
data("spring.data.jpa.very.long.foofoo.more", "java.lang.String", null, null);
|
||||
data("spring.data.jpa.very.long.barfoo.more", "java.lang.String", null, null);
|
||||
|
||||
|
||||
editor = newEditor(
|
||||
"spring.data.jpa.very.bar<*>"
|
||||
);
|
||||
editor.assertCompletions(
|
||||
"spring.data.jpa.very.long.barbar=<*>",
|
||||
"spring.data.jpa.very.long.barfoo=<*>",
|
||||
"spring.data.jpa.very.long.foobar=<*>",
|
||||
"spring.data.jpa.very.long.barbar.more=<*>",
|
||||
"spring.data.jpa.very.long.barfoo.more=<*>",
|
||||
"spring.data.jpa.very.long.foobar.more=<*>"
|
||||
);
|
||||
|
||||
editor.assertCompletionLabels(
|
||||
"long.barbar",
|
||||
"long.barfoo",
|
||||
"long.foobar",
|
||||
"long.barbar.more",
|
||||
"long.barfoo.more",
|
||||
"long.foobar.more"
|
||||
);
|
||||
|
||||
editor = newEditor(
|
||||
"spring.data.jpa.vr<*>"
|
||||
);
|
||||
editor.assertCompletionLabels(
|
||||
"very.long.barbar",
|
||||
"very.long.barfoo",
|
||||
"very.long.foobar",
|
||||
"very.long.foofoo",
|
||||
"very.long.barbar.more",
|
||||
"very.long.barfoo.more",
|
||||
"very.long.foobar.more",
|
||||
"very.long.foofoo.more"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReconcileCatchesParseError() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user