Skip to content

Commit

Permalink
improve getCurrentAttribute method for AbstractPositionReqest
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiphon committed Oct 24, 2019
1 parent 68d9292 commit 70ca73b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4xml.commons.BadLocationException;
import org.eclipse.lsp4xml.dom.DOMAttr;
import org.eclipse.lsp4xml.dom.DOMDocument;
import org.eclipse.lsp4xml.dom.DOMElement;
import org.eclipse.lsp4xml.dom.DOMNode;
Expand Down Expand Up @@ -101,6 +102,9 @@ public String getCurrentTag() {

@Override
public String getCurrentAttributeName() {
if (node != null && node.isAttribute() && ((DOMAttr) node).getName() != null) {
return ((DOMAttr) node).getName();
}
return currentAttributeName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.eclipse.lsp4xml.extensions.contentmodel.settings.ContentModelSettings;
import org.eclipse.lsp4xml.extensions.contentmodel.settings.XMLValidationSettings;
import org.eclipse.lsp4xml.services.XMLLanguageService;
import org.eclipse.lsp4xml.services.extensions.IHoverRequest;
import org.eclipse.lsp4xml.services.extensions.diagnostics.IXMLErrorCode;
import org.eclipse.lsp4xml.services.extensions.save.AbstractSaveContext;
import org.eclipse.lsp4xml.settings.SharedSettings;
Expand Down Expand Up @@ -578,6 +579,10 @@ public static void assertHover(XMLLanguageService xmlLanguageService, String val
}
}

public static void assertHoverAttributeName(IHoverRequest request) {
Assert.assertNotNull(request.getCurrentAttributeName());
}

private static String getHoverLabel(Hover hover) {
Either<List<Either<String, MarkedString>>, MarkupContent> contents = hover != null ? hover.getContents() : null;
if (contents == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public String onTag(IHoverRequest request) throws Exception {

@Override
public String onAttributeName(IHoverRequest request) throws Exception {
XMLAssert.assertHoverAttributeName(request);
return TEST_FOR_ATTRIBUTENAME_HOVER;
}
}
Expand Down

0 comments on commit 70ca73b

Please sign in to comment.