Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration documentation is not displayed #623

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
import org.apache.xerces.impl.xs.XSComplexTypeDecl;
Expand All @@ -35,6 +37,8 @@ public class CMXSDAttributeDeclaration implements CMAttributeDeclaration {
private final XSAttributeUse attributeUse;
private String documentation;

private Map<String, String> valuesDocumentation;

public CMXSDAttributeDeclaration(XSAttributeUse attributeUse) {
this.attributeUse = attributeUse;
}
Expand Down Expand Up @@ -68,12 +72,17 @@ public String getDocumentation() {

@Override
public String getValueDocumentation(String value) {
if (valuesDocumentation == null) {
valuesDocumentation = new HashMap<>();
}
String documentation = valuesDocumentation.get(value);
if (documentation != null) {
return documentation;
}
// Try get xs:annotation from the element declaration or type
XSObjectList annotations = getValueAnnotations();
documentation = XSDAnnotationModel.getDocumentation(annotations, value);
valuesDocumentation.put(value, documentation);
return documentation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,36 @@ public void testHoverAttributeValueNonExistent() throws BadLocationException, Ma
null);
};

/**
* See https://github.com/redhat-developer/vscode-xml/issues/233
*
* @throws BadLocationException
* @throws MalformedURIException
*/
@Test
public void hoverCacheBug() throws BadLocationException, MalformedURIException {
String schemaURI = getXMLSchemaFileURI("money.xsd");

XMLLanguageService ls = new XMLLanguageService();

String xmlAttNameHover = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<money xmlns=\"http://money\" curr|ency=\"pounds\"\r\n" + // <- Hover
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xsi:schemaLocation=\"http://money xsd/money.xsd\"></money>";
XMLAssert.assertHover(ls, xmlAttNameHover, null, "src/test/resources/money.xml", "Currency name Hover" + //
System.lineSeparator() + //
System.lineSeparator() + "Source: [money.xsd](" + schemaURI + ")", null);

String xmlAttValueHover = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<money xmlns=\"http://money\" currency=\"po|unds\"\r\n" + // <- Hover
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xsi:schemaLocation=\"http://money xsd/money.xsd\"></money>";
XMLAssert.assertHover(ls, xmlAttValueHover, null, "src/test/resources/money.xml", "Pound Hover" + //
System.lineSeparator() + //
System.lineSeparator() + "Source: [money.xsd](" + schemaURI + ")", null);

}

private static void assertHover(String value, String expectedHoverLabel, Integer expectedHoverOffset)
throws BadLocationException {
XMLAssert.assertHover(new XMLLanguageService(), value, "src/test/resources/catalogs/catalog.xml", null,
Expand Down