Skip to content

Commit

Permalink
Ignore linked editing range when there are no referenced node to update
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
azerr authored and datho7561 committed Jan 13, 2023
1 parent a9473d4 commit b19068b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Expand Up @@ -15,7 +15,6 @@

import org.eclipse.lemminx.extensions.references.XMLReferencesPlugin;
import org.eclipse.lemminx.extensions.references.search.SearchEngine;
import org.eclipse.lemminx.extensions.references.search.SearchNode;
import org.eclipse.lemminx.extensions.references.search.SearchQuery;
import org.eclipse.lemminx.extensions.references.search.SearchQueryFactory;
import org.eclipse.lemminx.services.extensions.ILinkedEditingRangesParticipant;
Expand Down Expand Up @@ -57,11 +56,17 @@ public void findLinkedEditingRanges(ILinkedEditingRangesRequest request, List<Ra
query.setMatchNode(true);
query.setSearchInIncludedFiles(false);

int previousSize = ranges.size();
SearchEngine.getInstance().search(query,
(fromSearchNode, toSearchNode, expression) -> {
ranges.add(fromSearchNode.createRange(true));
},
cancelChecker);
if (ranges.size() == previousSize) {
// There are no referenced nodes, ignore the linked editing range
return;
}

// Insert at first, the text edit for the node which was updated
ranges.add(query.getSearchNode().createRange(true));
}
Expand Down
Expand Up @@ -141,6 +141,26 @@ public void noLinkedEditingRangeForDocument() throws BadLocationException {
testLinkedEditingFor(xml, "file:///test/docbook.xml", null);
}

@Test
public void noLinkedEditingRangeForNoneReferencedNodes() throws BadLocationException {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
// + "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.4//EN\"
// \"http://www.docbook.org/xml/4.4/docbookx.dtd\">\r\n"
+ "<book>\r\n"
+ " <chapter id=\"chapt|er-1\">\r\n"
+ "\r\n"
//+ " <xref linkend=\"chapter-1\" />\r\n" // <-- // highlighting here should highlight
// chapter/@id="chapter-1"
+ "\r\n"
+ " </chapter>\r\n"
+ "\r\n"
+ " <chapter id=\"chapter-2\">\r\n"
+ "\r\n"
+ " </chapter>\r\n"
+ "</book>";
testLinkedEditingFor(xml, "file:///test/docbook.xml", null);
}

@Test
public void webOnServletMapping() throws BadLocationException {
String xml = "<web-app xmlns=\"http://xmlns.jcp.org/xml/ns/javaee\"\r\n"
Expand Down

0 comments on commit b19068b

Please sign in to comment.