PT_137299017 fix and tests (extra space added in front of value completion)

This commit is contained in:
Kris De Volder
2017-01-13 14:56:52 -08:00
parent 72d17c9f46
commit 6c893cfc13
3 changed files with 54 additions and 1 deletions

View File

@@ -149,8 +149,12 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
for (YValueHint value : values) {
double score = FuzzyMatcher.matchScore(query, value.getValue());
if (score!=0 && !value.equals(query)) {
int queryStart = offset-query.length();
DocumentEdits edits = new DocumentEdits(doc.getDocument());
edits.delete(offset-query.length(), offset);
edits.delete(queryStart, offset);
if (!Character.isWhitespace(doc.getChar(queryStart))) {
edits.insert(offset, " ");
}
edits.insert(offset, value.getValue());
completions.add(completionFactory().valueProposal(value.getValue(), query, value.getLabel(), type, score, edits, typeUtil));
}

View File

@@ -3592,6 +3592,39 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
"com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT"
);
}
@Test public void PT_137299017_extra_space_wth_bean_property_value_completion() throws Exception {
useProject(createPredefinedMavenProject("enums-boot-1.3.2-app"));
data("color", "demo.ColorData", null, "colorful stuff");
assertCompletions(
"color:\n" +
" next:<*>"
, //==>
"color:\n" +
" next: blue<*>"
, // ==
"color:\n" +
" next: green<*>"
, // ==
"color:\n" +
" next: red<*>"
);
}
@Test public void PT_137299017_extra_space_wth_index_property_value_completion() throws Exception {
defaultTestData();
assertCompletions(
"flyway:\n"+
" enabled:<*>"
, // ==>
"flyway:\n"+
" enabled: false<*>"
, // ==
"flyway:\n"+
" enabled: true<*>"
);
}
///////////////// cruft ////////////////////////////////////////////////////////

View File

@@ -501,6 +501,22 @@ public class ManifestYamlEditorTest {
);
}
@Test public void PT_137299017_extra_space_with_completion() throws Exception {
assertCompletions(
"applications:\n" +
"- name: foo\n" +
" random-route:<*>"
, // ==>
"applications:\n" +
"- name: foo\n" +
" random-route: false<*>"
, // --
"applications:\n" +
"- name: foo\n" +
" random-route: true<*>"
);
}
//////////////////////////////////////////////////////////////////////////////
private void assertCompletions(String textBefore, String... textAfter) throws Exception {