Skip to content

Commit

Permalink
Generate end tag with xml.completion.autoCloseTags set to false
Browse files Browse the repository at this point in the history
Signed-off-by: Jessica He <jhe@redhat.com>
  • Loading branch information
JessicaJHee authored and datho7561 committed Jan 25, 2023
1 parent 5e7cda6 commit 1d51ef6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ private int generate(CMElementDeclaration elementDeclaration, String prefix, boo
if (generatedElements.contains(elementDeclaration)) {
return snippetIndex;
}
boolean autoCloseTags = this.autoCloseTags && generateEndTag;
generatedElements.add(elementDeclaration);
if (level > 0) {
xml.linefeed();
Expand Down Expand Up @@ -211,7 +210,7 @@ private int generate(CMElementDeclaration elementDeclaration, String prefix, boo
xml.addContent(SnippetsBuilder.tabstops(snippetIndex));
}
}
if (autoCloseTags) {
if (generateEndTag) {
xml.endElement(prefix, elementDeclaration.getLocalName());
}
} else if (elementDeclaration.isEmpty() && autoCloseTags) {
Expand All @@ -236,7 +235,7 @@ private int generate(CMElementDeclaration elementDeclaration, String prefix, boo
snippetIndex++;
xml.addContent(SnippetsBuilder.tabstops(snippetIndex));
}
if (autoCloseTags) {
if (generateEndTag) {
xml.endElement(prefix, elementDeclaration.getLocalName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.lemminx.AbstractCacheBasedTest;
import org.eclipse.lemminx.extensions.relaxng.xml.validator.RelaxNGErrorCode;
import org.eclipse.lemminx.settings.SharedSettings;
import org.eclipse.lsp4j.Diagnostic;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -219,6 +220,39 @@ public void incomplete_element_required_element_missing_optional_element_zeroOrM
"\t\t</email>\r\n\t")));
}

//https://github.com/eclipse/lemminx/issues/1458
@Test
public void incomplete_element_required_element_missing_optional_element_zeroOrMore_autoCloseTags()
throws Exception {
String xml = "<?xml-model href=\"src/test/resources/relaxng/addressBook_v5.rng\" ?>\r\n" + //
"<addressBook>\r\n" + //
" <card>\r\n" + //
" </card>\r\n" + //
"</addressBook>";
Diagnostic d = d(2, 2, 2, 6, RelaxNGErrorCode.incomplete_element_required_element_missing);
SharedSettings settings = new SharedSettings();
settings.getCompletionSettings().setAutoCloseTags(false);
settings.getFormattingSettings().setTabSize(4);
settings.getFormattingSettings().setInsertSpaces(false);
testDiagnosticsFor(xml, d);
testCodeActionsFor(xml, d, settings,
// insert only required - emailContent is optional in schema - indicated by
// <zeroOrMore>
ca(d, te(2, 7, 3, 1, //
"\r\n" + //
"\t\t<name></name>\r\n" + //
"\t\t<email>\r\n" + //
"\t\t\t<emailContent></emailContent>\r\n" + //
"\t\t</email>\r\n\t")),
ca(d, te(2, 7, 3, 1, //
"\r\n" + //
"\t\t<name></name>\r\n" + //
"\t\t<email>\r\n" + //
"\t\t\t<emailContent></emailContent>\r\n" + //
"\t\t\t<emailOptional></emailOptional>\r\n" + //
"\t\t</email>\r\n\t")));
}

@Test
public void incomplete_element_required_element_missing_choice() throws Exception {
String xml = "<?xml-model href=\"src/test/resources/relaxng/article.rng\" ?>\r\n" + //
Expand Down

0 comments on commit 1d51ef6

Please sign in to comment.