Skip to content

Commit

Permalink
Surround with tags with adjust don't show the allowed elements in
Browse files Browse the repository at this point in the history
completion

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
azerr authored and datho7561 committed Dec 13, 2022
1 parent 0fd1c08 commit 71f9a00
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Expand Up @@ -140,7 +140,7 @@ protected Object executeCommand(DOMDocument document, ExecuteCommandParams param
}
break;
default:
List<String> tags = getTags(node, prefix, offset);
List<String> tags = getTags(node, prefix, offset, adjusted);
String tag = tags.isEmpty() ? "" : tags.get(0);

// Start tag
Expand Down Expand Up @@ -176,8 +176,8 @@ protected Object executeCommand(DOMDocument document, ExecuteCommandParams param
return new SurroundWithResponse(start, end);
}

private List<String> getTags(DOMNode node, String prefix, int offset) {
DOMElement parentElement = node.isElement() ? (DOMElement) node : node.getParentElement();
private List<String> getTags(DOMNode node, String prefix, int offset, boolean adjusted) {
DOMElement parentElement = node.isElement() && !adjusted ? (DOMElement) node : node.getParentElement();
Collection<CMDocument> cmDocuments = parentElement != null ? contentModelManager.findCMDocument(parentElement)
: contentModelManager.findCMDocument(node.getOwnerDocument(), null);
if (parentElement == null) {
Expand Down
Expand Up @@ -111,7 +111,7 @@ public void surroundEmptySelectionInStartTag() throws Exception {
}

@Test
public void surroundEmptySelectionInStartTag2() throws Exception {
public void surroundEmptySelectionInNestedStartTag() throws Exception {
String xml = "<foo>\r\n" + //
" <b|ar></bar>\r\n" + //
"</foo>";
Expand All @@ -133,7 +133,7 @@ public void surroundEmptySelectionInEndTag() throws Exception {
}

@Test
public void surroundEmptySelectionInEndTag2() throws Exception {
public void surroundEmptySelectionInNestedEndTag() throws Exception {
String xml = "<foo>\r\n" + //
" <bar></b|ar>\r\n" + //
"</foo>";
Expand Down Expand Up @@ -175,6 +175,51 @@ public void surroundEmptySelectionInEmptyDocumentWithTwoSchema() throws Exceptio
assertSurroundWith(xml, SurroundWithKind.tags, true, expected);
}

@Test
public void surroundSelectionWithRNG() throws Exception {
String xml = "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\"\r\n"
+ " datatypeLibrary=\"http://www.w3.org/2001/XMLSchema-datatypes\">\r\n"
+ " \r\n"
+ " <start>\r\n"
+ " |<ref name=\"foo\" />\r\n"
+ " <ref name=\"bar\" />|\r\n"
+ " </start>\r\n"
+ "\r\n"
+ "</grammar>";
String expected = "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\"\r\n"
+ " datatypeLibrary=\"http://www.w3.org/2001/XMLSchema-datatypes\">\r\n"
+ " \r\n"
+ " <start>\r\n"
+ " <${1|attribute,choice,data,element,empty,externalRef,grammar,group,interleave,list,mixed,notAllowed,oneOrMore,optional,parentRef,ref,text,value,zeroOrMore|}><ref name=\"foo\" />\r\n"
+ " <ref name=\"bar\" /></${1:attribute}>$0\r\n"
+ " </start>\r\n"
+ "\r\n"
+ "</grammar>";
assertSurroundWith(xml, SurroundWithKind.tags, true, expected);
}

@Test
public void surroundEmptySelectionInStartTagWithRNG() throws Exception {
String xml = "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\"\r\n"
+ " datatypeLibrary=\"http://www.w3.org/2001/XMLSchema-datatypes\">\r\n"
+ " \r\n"
+ " <start>\r\n"
+ " <re|f name=\"foo\" />\r\n"
+ " <ref name=\"bar\" />\r\n"
+ " </start>\r\n"
+ "\r\n"
+ "</grammar>";
String expected = "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\"\r\n"
+ " datatypeLibrary=\"http://www.w3.org/2001/XMLSchema-datatypes\">\r\n"
+ " \r\n"
+ " <start>\r\n"
+ " <${1|attribute,choice,data,element,empty,externalRef,grammar,group,interleave,list,mixed,notAllowed,oneOrMore,optional,parentRef,ref,text,value,zeroOrMore|}><ref name=\"foo\" /></${1:attribute}>$0\r\n"
+ " <ref name=\"bar\" />\r\n"
+ " </start>\r\n"
+ "\r\n"
+ "</grammar>";
assertSurroundWith(xml, SurroundWithKind.tags, true, expected);
}
private static XMLFileAssociation[] createXSDAssociationsNoNamespaceSchemaLocationLike(String baseSystemId) {
XMLFileAssociation resources = new XMLFileAssociation();
resources.setPattern("**/*resources*.xml");
Expand Down

0 comments on commit 71f9a00

Please sign in to comment.