diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDAttributeDeclaration.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDAttributeDeclaration.java index 970b6e158..5b6443b8c 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDAttributeDeclaration.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDAttributeDeclaration.java @@ -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; @@ -35,6 +37,8 @@ public class CMXSDAttributeDeclaration implements CMAttributeDeclaration { private final XSAttributeUse attributeUse; private String documentation; + private Map valuesDocumentation; + public CMXSDAttributeDeclaration(XSAttributeUse attributeUse) { this.attributeUse = attributeUse; } @@ -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; } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaHoverExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaHoverExtensionsTest.java index ccc4dafc5..6266c94e5 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaHoverExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaHoverExtensionsTest.java @@ -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 = "\r\n" + // + ""; + XMLAssert.assertHover(ls, xmlAttNameHover, null, "src/test/resources/money.xml", "Currency name Hover" + // + System.lineSeparator() + // + System.lineSeparator() + "Source: [money.xsd](" + schemaURI + ")", null); + + String xmlAttValueHover = "\r\n" + // + ""; + 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,