Skip to content

Commit

Permalink
Fix Single < has code action to close with />
Browse files Browse the repository at this point in the history
Fixes redhat-developer/vscode-xml#373

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
azerr authored and datho7561 committed Dec 8, 2020
1 parent 8fe6908 commit db71cb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -112,13 +112,14 @@ private void doCodeActionsForStartTagUnclosed(DOMElement element, DOMDocument do
} else {
// ex : <foo
// ex : <foo attr="
// Close with '/>'
CodeAction autoCloseAction = CodeActionFactory.insert("Close with '/>'", diagnosticRange.getEnd(), "/>",
document.getTextDocument(), diagnostic);
codeActions.add(autoCloseAction);
// Close with '></foo>' if element has tag name
// if element has tag name
String tagName = element.getTagName();
if (tagName != null) {
// Close with '/>'
CodeAction autoCloseAction = CodeActionFactory.insert("Close with '/>'", diagnosticRange.getEnd(),
"/>", document.getTextDocument(), diagnostic);
codeActions.add(autoCloseAction);
// Close with '></foo>'
String insertText = "></" + tagName + ">";
CodeAction closeEndTagAction = CodeActionFactory.insert("Close with '" + insertText + "'",
diagnosticRange.getEnd(), insertText, document.getTextDocument(), diagnostic);
Expand Down
Expand Up @@ -463,6 +463,7 @@ public void testMarkupEntityMismatch3() throws Exception {
String xml = "<";
Diagnostic d = d(0, 0, 0, 1, XMLSyntaxErrorCode.MarkupEntityMismatch);
testDiagnosticsFor(xml, d);
testCodeActionsFor(xml, d); // no code actions
}

@Test
Expand Down

0 comments on commit db71cb9

Please sign in to comment.