Skip to content

Commit

Permalink
No hover message if no docs
Browse files Browse the repository at this point in the history
If a declared element doesn't have associated `xs:documentation`
or `xs:appinfo`, then no hover information is displayed.
This also applies to the documentation displayed by the completion as
well.

Closes redhat-developer/vscode-xml#258

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed May 29, 2020
1 parent 03ca396 commit 1a0f069
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.lemminx.utils.XMLBuilder;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.MarkupKind;
import org.jsoup.helper.StringUtil;

/**
* XML generator used to generate an XML fragment with formatting from a given
Expand Down Expand Up @@ -226,12 +227,14 @@ public static String generateAttributeValue(String defaultValue, Collection<Stri
* @return
*/
public static String generateDocumentation(String documentation, String schemaURI, boolean html) {
StringBuilder doc = new StringBuilder(documentation != null ? documentation : "");
if (StringUtil.isBlank(documentation)) {
return null;
}
StringBuilder doc = new StringBuilder(documentation);

if (schemaURI != null) {
if (doc.length() != 0) {
doc.append(System.lineSeparator());
doc.append(System.lineSeparator());
}
doc.append(System.lineSeparator());
doc.append(System.lineSeparator());
if (html) {
doc.append("<p>");
}
Expand All @@ -247,7 +250,7 @@ public static String generateDocumentation(String documentation, String schemaUR
doc.append("</p>");
}
}
return doc.length() > 0 ? doc.toString() : null;
return doc.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ public void issue214WithMarkdown() throws BadLocationException, MalformedURIExce
" |";
testCompletionMarkdownSupportFor(xml,
c("Annotation", te(6, 1, 6, 1, "<Annotation Term=\"\"></Annotation>"), "Annotation",
"Source: [edm.xsd](" + edmURI + ")", MarkupKind.MARKDOWN), //
null, null), //
c("edmx:Include", te(6, 1, 6, 1, "<edmx:Include Namespace=\"\"></edmx:Include>"), "edmx:Include",
"Source: [edmx.xsd](" + edmxURI + ")", MarkupKind.MARKDOWN), //
null, null), //
c("edmx:IncludeAnnotations", "<edmx:IncludeAnnotations TermNamespace=\"\" />"));

xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
Expand Down Expand Up @@ -850,11 +850,10 @@ public void xsAnyDuplicate() throws IOException, BadLocationException {
" | ";
// testCompletionFor checks the duplicate label
XMLAssert.testCompletionFor(xml, null, "src/test/resources/tns.xml", null,
c("Page", te(2, 1, 2, 1, "<Page></Page>"), "Page", "Source: tns.xsd", MarkupKind.PLAINTEXT),
c("Page", te(2, 1, 2, 1, "<Page></Page>"), "Page", null, null),
c("AbsoluteLayout", te(2, 1, 2, 1, "<AbsoluteLayout></AbsoluteLayout>"), "AbsoluteLayout",
"Source: tns.xsd", MarkupKind.PLAINTEXT),
c("DockLayout", te(2, 1, 2, 1, "<DockLayout></DockLayout>"), "DockLayout", "Source: tns.xsd",
MarkupKind.PLAINTEXT));
null, null),
c("DockLayout", te(2, 1, 2, 1, "<DockLayout></DockLayout>"), "DockLayout", null, null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ public void testHoverMultipleBothPlainText() throws BadLocationException, Malfor
assertElementMultipleBothHover(null, SchemaDocumentationType.none, false);
};

public void testHoverNoAnnotation() throws BadLocationException, MalformedURIException {
assertElementHoverNoAnnotation(SchemaDocumentationType.all, true);
assertElementHoverNoAnnotation(SchemaDocumentationType.appinfo, true);
assertElementHoverNoAnnotation(SchemaDocumentationType.documentation, true);
assertElementHoverNoAnnotation(SchemaDocumentationType.none, true);
assertElementHoverNoAnnotation(SchemaDocumentationType.all, false);
assertElementHoverNoAnnotation(SchemaDocumentationType.appinfo, false);
assertElementHoverNoAnnotation(SchemaDocumentationType.documentation, false);
assertElementHoverNoAnnotation(SchemaDocumentationType.none, false);
}

private void assertAttributeNameDocHover(String expected, SchemaDocumentationType docSource,
boolean markdownSupported) throws BadLocationException {
String xml =
Expand Down Expand Up @@ -301,6 +312,17 @@ private void assertElementMultipleBothHover(String expected, SchemaDocumentation
assertHover(xml, expected, docSource, markdownSupported);
}

private void assertElementHoverNoAnnotation(SchemaDocumentationType docSource, boolean markdownSupported) throws BadLocationException {
String xml =
"<root\n" + //
" xmlns=\"http://docAppinfo\"\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + //
" xsi:schemaLocation=\"http://docAppinfo xsd/" + schemaName + "\"\n" + //
" <e|lementNoAnnotation></elementNoAnnotation>\n" + //
"</root>\n";
assertHover(xml, null, docSource, markdownSupported);
}

private void assertHover(String xml, String expected, SchemaDocumentationType docSource, boolean markdownSupported) throws BadLocationException {
String currSource = markdownSupported ? source : plainTextSource;

Expand All @@ -310,8 +332,6 @@ private void assertHover(String xml, String expected, SchemaDocumentationType do
content.append(System.lineSeparator());
content.append(currSource);
expected = content.toString();
} else {
expected = currSource;
}

XMLAssert.assertHover(new XMLLanguageService(), xml, null, schemaPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public void completionWithSourceDocumentation() throws BadLocationException {
"|";
testCompletionFor(xml,
c("xs:annotation", te(2, 0, 2, 0, "<xs:annotation></xs:annotation>"), "xs:annotation",
"Source: XMLSchema.xsd", MarkupKind.PLAINTEXT),
null, null),
c("xs:attribute", te(2, 0, 2, 0, "<xs:attribute name=\"\"></xs:attribute>"), "xs:attribute",
"Source: XMLSchema.xsd", MarkupKind.PLAINTEXT));
null, null));
}

@Test
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.lemminx/src/test/resources/xsd/docAppinfo.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<xs:appinfo>third element appinfo</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name='elementNoAnnotation'></xs:element>
</xs:sequence>

<xs:attribute name='attributeNameOnlyDocumentation' type='attributeValue' use='required'>
Expand Down

0 comments on commit 1a0f069

Please sign in to comment.