From 71f9a00ff9ba1a2ffe293a16d48b51f796573a85 Mon Sep 17 00:00:00 2001 From: azerr Date: Tue, 13 Dec 2022 14:07:23 +0100 Subject: [PATCH] Surround with tags with adjust don't show the allowed elements in completion Signed-off-by: azerr --- .../commands/SurroundWithCommand.java | 6 +-- .../commands/SurroundWithTagsCommandTest.java | 49 ++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithCommand.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithCommand.java index cf080a397..5f640cf4f 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithCommand.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithCommand.java @@ -140,7 +140,7 @@ protected Object executeCommand(DOMDocument document, ExecuteCommandParams param } break; default: - List tags = getTags(node, prefix, offset); + List tags = getTags(node, prefix, offset, adjusted); String tag = tags.isEmpty() ? "" : tags.get(0); // Start tag @@ -176,8 +176,8 @@ protected Object executeCommand(DOMDocument document, ExecuteCommandParams param return new SurroundWithResponse(start, end); } - private List getTags(DOMNode node, String prefix, int offset) { - DOMElement parentElement = node.isElement() ? (DOMElement) node : node.getParentElement(); + private List getTags(DOMNode node, String prefix, int offset, boolean adjusted) { + DOMElement parentElement = node.isElement() && !adjusted ? (DOMElement) node : node.getParentElement(); Collection cmDocuments = parentElement != null ? contentModelManager.findCMDocument(parentElement) : contentModelManager.findCMDocument(node.getOwnerDocument(), null); if (parentElement == null) { diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithTagsCommandTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithTagsCommandTest.java index bf0b53b5d..5b8ebe651 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithTagsCommandTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/commands/SurroundWithTagsCommandTest.java @@ -111,7 +111,7 @@ public void surroundEmptySelectionInStartTag() throws Exception { } @Test - public void surroundEmptySelectionInStartTag2() throws Exception { + public void surroundEmptySelectionInNestedStartTag() throws Exception { String xml = "\r\n" + // " \r\n" + // ""; @@ -133,7 +133,7 @@ public void surroundEmptySelectionInEndTag() throws Exception { } @Test - public void surroundEmptySelectionInEndTag2() throws Exception { + public void surroundEmptySelectionInNestedEndTag() throws Exception { String xml = "\r\n" + // " \r\n" + // ""; @@ -175,6 +175,51 @@ public void surroundEmptySelectionInEmptyDocumentWithTwoSchema() throws Exceptio assertSurroundWith(xml, SurroundWithKind.tags, true, expected); } + @Test + public void surroundSelectionWithRNG() throws Exception { + String xml = "\r\n" + + " \r\n" + + " \r\n" + + " |\r\n" + + " |\r\n" + + " \r\n" + + "\r\n" + + ""; + String expected = "\r\n" + + " \r\n" + + " \r\n" + + " <${1|attribute,choice,data,element,empty,externalRef,grammar,group,interleave,list,mixed,notAllowed,oneOrMore,optional,parentRef,ref,text,value,zeroOrMore|}>\r\n" + + " $0\r\n" + + " \r\n" + + "\r\n" + + ""; + assertSurroundWith(xml, SurroundWithKind.tags, true, expected); + } + + @Test + public void surroundEmptySelectionInStartTagWithRNG() throws Exception { + String xml = "\r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + "\r\n" + + ""; + String expected = "\r\n" + + " \r\n" + + " \r\n" + + " <${1|attribute,choice,data,element,empty,externalRef,grammar,group,interleave,list,mixed,notAllowed,oneOrMore,optional,parentRef,ref,text,value,zeroOrMore|}>$0\r\n" + + " \r\n" + + " \r\n" + + "\r\n" + + ""; + assertSurroundWith(xml, SurroundWithKind.tags, true, expected); + } private static XMLFileAssociation[] createXSDAssociationsNoNamespaceSchemaLocationLike(String baseSystemId) { XMLFileAssociation resources = new XMLFileAssociation(); resources.setPattern("**/*resources*.xml");