Skip to content

Commit

Permalink
Prepare hover for attribuet name/value (see #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Aug 10, 2018
1 parent b4e5c37 commit bd4e983
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4xml.contentmodel.model.CMAttributeDeclaration;
import org.eclipse.lsp4xml.contentmodel.model.CMElementDeclaration;
import org.eclipse.lsp4xml.contentmodel.model.ContentModelManager;
import org.eclipse.lsp4xml.model.Node;
Expand All @@ -25,11 +26,11 @@
public class ContentModelHoverParticipant extends HoverParticipantAdapter {

@Override
public Hover onTag(IHoverRequest request) throws Exception {
Node node = request.getNode();
CMElementDeclaration cmlElement = ContentModelManager.getInstance().findCMElement(node);
if (cmlElement != null) {
String doc = cmlElement.getDocumentation();
public Hover onTag(IHoverRequest completionRequest) throws Exception {
Node node = completionRequest.getNode();
CMElementDeclaration cmElement = ContentModelManager.getInstance().findCMElement(node);
if (cmElement != null) {
String doc = cmElement.getDocumentation();
if (doc != null && doc.length() > 0) {
MarkupContent content = new MarkupContent();
content.setValue(doc);
Expand All @@ -40,7 +41,21 @@ public Hover onTag(IHoverRequest request) throws Exception {
}

@Override
public Hover onAttributeValue(IHoverRequest request) throws Exception {
public Hover onAttributeName(IHoverRequest completionRequest) throws Exception {
Node element = completionRequest.getNode();
CMElementDeclaration cmElement = ContentModelManager.getInstance().findCMElement(element);
if (cmElement != null) {
String attributeName = completionRequest.getCurrentAttributeName();
CMAttributeDeclaration cmAttribute = cmElement.findCMAttribute(attributeName);
if (cmAttribute != null) {
String doc = cmAttribute.getDocumentation();
if (doc != null && doc.length() > 0) {
MarkupContent content = new MarkupContent();
content.setValue(doc);
return new Hover(content);
}
}
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
public class HoverParticipantAdapter implements IHoverParticipant {

@Override
public Hover onTag(IHoverRequest request) throws Exception {
public Hover onTag(IHoverRequest request) throws Exception {
return null;
}

@Override
public Hover onAttributeValue(IHoverRequest request) throws Exception {
public Hover onAttributeName(IHoverRequest request) throws Exception {
return null;
}

@Override
public Hover onAttributeValue(IHoverRequest request) throws Exception {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface IHoverParticipant {

Hover onTag(IHoverRequest request) throws Exception;

Hover onAttributeName(IHoverRequest request) throws Exception;

Hover onAttributeValue(IHoverRequest request) throws Exception;

}

0 comments on commit bd4e983

Please sign in to comment.