Small tweak to auto-dash insertion

This commit is contained in:
Kris De Volder
2017-04-26 11:41:29 -07:00
parent 9e0513663c
commit 17ce903577
2 changed files with 25 additions and 13 deletions

View File

@@ -338,20 +338,20 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
new TransformedCompletion(c) {
@Override
protected DocumentEdits transformEdit(DocumentEdits textEdit) {
if (needNewline(textEdit)) {
textEdit.indentFirstEdit("\n"+Strings.repeat(" ", node.getIndent())+"- ");
} else {
textEdit.transformFirstNonWhitespaceEdit((Integer offset, String insertText) -> {
if (offset > 2) {
String prefix = insertText.substring(offset-2, offset);
if (" ".equals(prefix)) {
//special case don't add the "- " in front, but replace the inserted spaces instead.
return insertText.substring(0, offset-2)+"- "+insertText.substring(offset);
}
textEdit.transformFirstNonWhitespaceEdit((Integer offset, String insertText) -> {
if (needNewline(textEdit)) {
return insertText.substring(0, offset)
+ "\n" +Strings.repeat(" ", node.getIndent())+"- "
+ insertText.substring(offset);
} else if (offset > 2) {
String prefix = insertText.substring(offset-2, offset);
if (" ".equals(prefix)) {
//special case don't add the "- " in front, but replace the inserted spaces instead.
return insertText.substring(0, offset-2)+"- "+insertText.substring(offset);
}
return insertText.substring(0, offset) + "- "+insertText.substring(offset);
});
}
}
return insertText.substring(0, offset) + "- "+insertText.substring(offset);
});
return textEdit;
}

View File

@@ -1148,6 +1148,18 @@ public class ManifestYamlEditorTest {
when(service.getName()).thenReturn("my-service");
when(service.getPlan()).thenReturn("cheap-plan");
editor = harness.newEditor(
"applications:\n" +
"- name: foo\n" +
" services:<*>\n"
);
editor.assertCompletions(
"applications:\n" +
"- name: foo\n" +
" services: \n"+
" - my-service<*>\n"
);
editor = harness.newEditor(
"applications:\n" +
"- name: foo\n" +