From bd4e9831b592c1b18a567e475aa3b61bb859de99 Mon Sep 17 00:00:00 2001 From: angelozerr Date: Fri, 10 Aug 2018 22:06:41 +0200 Subject: [PATCH] Prepare hover for attribuet name/value (see #12) --- .../ContentModelHoverParticipant.java | 27 ++++++++++++++----- .../extensions/HoverParticipantAdapter.java | 9 +++++-- .../extensions/IHoverParticipant.java | 2 ++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/extensions/org.eclipse.lsp4xml.contentmodel/src/main/java/org/eclipse/lsp4xml/contentmodel/participants/ContentModelHoverParticipant.java b/extensions/org.eclipse.lsp4xml.contentmodel/src/main/java/org/eclipse/lsp4xml/contentmodel/participants/ContentModelHoverParticipant.java index ea29ad894..f2047886d 100644 --- a/extensions/org.eclipse.lsp4xml.contentmodel/src/main/java/org/eclipse/lsp4xml/contentmodel/participants/ContentModelHoverParticipant.java +++ b/extensions/org.eclipse.lsp4xml.contentmodel/src/main/java/org/eclipse/lsp4xml/contentmodel/participants/ContentModelHoverParticipant.java @@ -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; @@ -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); @@ -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; } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/HoverParticipantAdapter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/HoverParticipantAdapter.java index 651ee1949..6cfdc7c28 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/HoverParticipantAdapter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/HoverParticipantAdapter.java @@ -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; } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/IHoverParticipant.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/IHoverParticipant.java index 3e96721a6..7d170d8b1 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/IHoverParticipant.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/IHoverParticipant.java @@ -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; }