Fix indentation bug with relaxed completions in application.yml editor

This commit is contained in:
Kris De Volder
2018-01-19 15:11:32 -08:00
parent 1e7ae17ae7
commit 2da50fddd4
5 changed files with 118 additions and 9 deletions

View File

@@ -0,0 +1,59 @@
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=false
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=false
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_type_arguments=false
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=false
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_lambda=true
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true

View File

@@ -31,6 +31,8 @@ import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguage
import org.springframework.ide.vscode.commons.util.StringUtil;
import org.springframework.ide.vscode.languageserver.testharness.Editor;
import static org.springframework.ide.vscode.languageserver.testharness.Editor.*;
/**
* This class is a placeholder where we will attempt to copy and port
* as many tests a possible from
@@ -42,6 +44,39 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
////////////////////////////////////////////////////////////////////////////////////////
@Test public void bug_153144391() throws Exception {
//See: https://www.pivotaltracker.com/story/show/153144391
useProject(createPredefinedMavenProject("empty-boot-1.3.0-app"));
Editor editor = newEditor(
"spring:\n" +
" application:\n" +
" name: chatter-web-ui\n" +
" cloud:\n" +
" stream:\n" +
" bindings:\n" +
" output:\n" +
" destination: chat\n" +
" input:\n" +
" destination: chat\n" +
"jackloca<*>"
);
editor.assertCompletions(INDENTED_COMPLETION,
"spring:\n" +
" application:\n" +
" name: chatter-web-ui\n" +
" cloud:\n" +
" stream:\n" +
" bindings:\n" +
" output:\n" +
" destination: chat\n" +
" input:\n" +
" destination: chat\n" +
" jackson:\n" +
" locale: <*>"
);
}
@Test public void linterRunsOnDocumentOpenAndChange() throws Exception {
Editor editor = newEditor(
"somemap: val\n"+
@@ -3630,7 +3665,7 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
//See: https://www.pivotaltracker.com/story/show/150005676
defaultTestData();
Editor editor = newEditor(
"server:\n" +
"server:\n" +
" port: \"@application-port@\"\n" +
"bogus: bad" //token error to ensure reconciler is really working
);
@@ -3643,7 +3678,7 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
//Not implemented, this test fails. The choice not to implement this was deliberate!
defaultTestData();
Editor editor = newEditor(
"server:\n" +
"server:\n" +
" port: @application-port@\n" +
"bogus: bad" //token error to ensure reconciler is really working
);

View File

@@ -47,8 +47,6 @@ public class DocumentEdits implements ProposalApplier {
private static final Pattern NON_WS_CHAR = Pattern.compile("\\S");
private boolean isRelativeIndent = false;
// Note: for small number of edits this implementation is okay.
// for large number of edits it is potentially slow because of the
// way it transforms edit coordinates (a growing chain of
@@ -484,4 +482,8 @@ public class DocumentEdits implements ProposalApplier {
public void freezeCursor() {
this.grabCursor = false;
}
public boolean hasRelativeIndents() {
return true;
}
}

View File

@@ -234,11 +234,19 @@ public class YamlCompletionEngine implements ICompletionEngine {
@Override public DocumentEdits transformEdit(DocumentEdits originalEdit) {
// originalEdit.indentFirstEdit(indentStr);
YamlIndentUtil indenter = new YamlIndentUtil("\n");
originalEdit.transformFirstNonWhitespaceEdit((Integer offset, String insertText) -> {
String prefix = insertText.substring(0, offset);
String target = insertText.substring(offset);
return prefix + indentStr + indenter.applyIndentation(target, indentStr);
});
if (originalEdit.hasRelativeIndents()) {
originalEdit.transformFirstNonWhitespaceEdit((Integer offset, String insertText) -> {
String prefix = insertText.substring(0, offset);
String target = insertText.substring(offset);
return prefix + indentStr + indenter.applyIndentation(target, indentStr);
});
} else {
originalEdit.transformFirstNonWhitespaceEdit((Integer offset, String insertText) -> {
String prefix = insertText.substring(0, offset);
String target = insertText.substring(offset);
return prefix + indentStr + target;
});
}
return originalEdit;
}
};

View File

@@ -41,6 +41,11 @@ public class YamlPathEdits extends DocumentEdits {
this.indentUtil = new YamlIndentUtil(doc);
}
@Override
public boolean hasRelativeIndents() {
return false;
}
/**
* Create the necessary edits to ensure that a given property
* path exists, placing cursor in the right place also to start