-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
textDocument/documentHighlight
for XML Schema types
Fix #470 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
0d20197
commit e7635ce
Showing
7 changed files
with
132 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...main/java/org/eclipse/lsp4xml/extensions/xsd/participants/XSDHighlightingParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.eclipse.lsp4xml.extensions.xsd.participants; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.lsp4j.DocumentHighlight; | ||
import org.eclipse.lsp4j.DocumentHighlightKind; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
import org.eclipse.lsp4xml.dom.DOMAttr; | ||
import org.eclipse.lsp4xml.dom.DOMDocument; | ||
import org.eclipse.lsp4xml.dom.DOMNode; | ||
import org.eclipse.lsp4xml.extensions.xsd.utils.XSDUtils; | ||
import org.eclipse.lsp4xml.extensions.xsd.utils.XSDUtils.BindingType; | ||
import org.eclipse.lsp4xml.services.extensions.IHighlightingParticipant; | ||
import org.eclipse.lsp4xml.utils.DOMUtils; | ||
import org.eclipse.lsp4xml.utils.XMLPositionUtility; | ||
|
||
public class XSDHighlightingParticipant implements IHighlightingParticipant { | ||
|
||
@Override | ||
public void findDocumentHighlights(DOMNode node, Position position, int offset, List<DocumentHighlight> highlights, | ||
CancelChecker cancelChecker) { | ||
DOMDocument document = node.getOwnerDocument(); | ||
if (!DOMUtils.isXSD(document)) { | ||
return; | ||
} | ||
DOMAttr attr = node.findAttrAt(offset); | ||
if (attr == null) { | ||
return; | ||
} | ||
BindingType bindingType = XSDUtils.getBindingType(attr); | ||
if (bindingType != BindingType.NONE) { | ||
DOMAttr originAttr = attr; | ||
highlights | ||
.add(new DocumentHighlight(XMLPositionUtility.createRange(originAttr.getNodeAttrValue().getStart(), | ||
originAttr.getNodeAttrValue().getEnd(), document), DocumentHighlightKind.Read)); | ||
XSDUtils.collectXSTypes(originAttr, bindingType, true, (targetNamespacePrefix, targetAttr) -> { | ||
highlights.add(new DocumentHighlight( | ||
XMLPositionUtility.createRange(targetAttr.getNodeAttrValue().getStart(), | ||
targetAttr.getNodeAttrValue().getEnd(), targetAttr.getOwnerDocument()), | ||
DocumentHighlightKind.Write)); | ||
}); | ||
|
||
} else if (XSDUtils.isXSTargetElement(attr.getOwnerElement())) { | ||
|
||
DOMAttr targetAttr = attr; | ||
highlights.add(new DocumentHighlight( | ||
XMLPositionUtility.createRange(targetAttr.getNodeAttrValue().getStart(), | ||
targetAttr.getNodeAttrValue().getEnd(), targetAttr.getOwnerDocument()), | ||
DocumentHighlightKind.Write)); | ||
XSDUtils.collectXSReferenceTypes(targetAttr, | ||
(origin, target) -> highlights.add(new DocumentHighlight( | ||
XMLPositionUtility.createRange(origin.getNodeAttrValue().getStart(), | ||
origin.getNodeAttrValue().getEnd(), origin.getOwnerDocument()), | ||
DocumentHighlightKind.Read)), | ||
cancelChecker); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...p4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/IHighlightingParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.eclipse.lsp4xml.services.extensions; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.lsp4j.DocumentHighlight; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
import org.eclipse.lsp4xml.dom.DOMNode; | ||
|
||
public interface IHighlightingParticipant { | ||
|
||
void findDocumentHighlights(DOMNode node, Position position, int offset, List<DocumentHighlight> highlights, | ||
CancelChecker cancelChecker); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters