-
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
00509d7
commit 4ebac6a
Showing
14 changed files
with
389 additions
and
84 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
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
81 changes: 81 additions & 0 deletions
81
...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,81 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
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; | ||
|
||
/** | ||
* XSD highlight participant | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class XSDHighlightingParticipant implements IHighlightingParticipant { | ||
|
||
@Override | ||
public void findDocumentHighlights(DOMNode node, Position position, int offset, List<DocumentHighlight> highlights, | ||
CancelChecker cancelChecker) { | ||
// XSD highlight applicable only for XSD file | ||
DOMDocument document = node.getOwnerDocument(); | ||
if (!DOMUtils.isXSD(document)) { | ||
return; | ||
} | ||
// Highlight works ony when attribute is selected (orign or target attribute) | ||
DOMAttr attr = node.findAttrAt(offset); | ||
if (attr == null) { | ||
return; | ||
} | ||
// Try to get the binding from the origin attribute | ||
BindingType bindingType = XSDUtils.getBindingType(attr); | ||
if (bindingType != BindingType.NONE) { | ||
// It's an origin attribute, highlight the origin and target attribute | ||
DOMAttr originAttr = attr; | ||
highlights | ||
.add(new DocumentHighlight(XMLPositionUtility.createRange(originAttr.getNodeAttrValue().getStart(), | ||
originAttr.getNodeAttrValue().getEnd(), document), DocumentHighlightKind.Read)); | ||
// Search target attributes | ||
XSDUtils.searchXSTargetAttributes(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())) { | ||
// It's an target attribute, highlight all origin attributes linked to this | ||
// target attribute | ||
DOMAttr targetAttr = attr; | ||
highlights.add(new DocumentHighlight( | ||
XMLPositionUtility.createRange(targetAttr.getNodeAttrValue().getStart(), | ||
targetAttr.getNodeAttrValue().getEnd(), targetAttr.getOwnerDocument()), | ||
DocumentHighlightKind.Write)); | ||
XSDUtils.searchXSOriginAttributes(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
Oops, something went wrong.