PY-30359 Render raised exceptions in Quick Documentation sections

This commit is contained in:
Mikhail Golubev
2018-06-09 15:59:40 +03:00
parent 34d1e91b17
commit 87091da823
8 changed files with 44 additions and 3 deletions
@@ -803,6 +803,7 @@ QDOC.local.sdk.not.found=You need a configured local Python SDK to render docstr
QDOC.assigned.to=Assigned to:
QDOC.documentation.is.copied.from=Documentation is copied from:
QDOC.accessor.kind=Accessor kind:
QDOC.raises=Raises:
runcfg.tests.cant_rerun=Can't rerun tests since test IDs can't be resolved. Try to delete run configuration, and create new one using right click.
@@ -388,6 +388,17 @@ public class PyDocumentationBuilder {
if (returnDescription != null) {
mySectionsMap.get(CodeInsightBundle.message("javadoc.returns")).addItem(returnDescription);
}
final String exceptionList = StreamEx.of(structured.getRaisedExceptions())
.map(name -> {
final String description = structured.getRaisedExceptionDescription(name);
return "<p>" + name + (StringUtil.isNotEmpty(description) ? " &ndash; " + description : "") + "</p>";
})
.joining();
if (!exceptionList.isEmpty()) {
mySectionsMap.get(PyBundle.message("QDOC.raises")).addItem(exceptionList);
}
}
private boolean isAttribute() {
@@ -195,13 +195,17 @@ public class DocStringUtil {
}
public static boolean isLikeSphinxDocString(@NotNull String text) {
return text.contains(":param ") ||
text.contains(":return:") || text.contains(":returns:") ||
return text.contains(":param ") ||
text.contains(":return:") || text.contains(":returns:") ||
text.contains(":raise ") || text.contains(":raises ") || text.contains(":except ") || text.contains(":exception ") ||
text.contains(":rtype") || text.contains(":type");
}
public static boolean isLikeEpydocDocString(@NotNull String text) {
return text.contains("@param ") || text.contains("@return:") || text.contains("@rtype") || text.contains("@type");
return text.contains("@param ") ||
text.contains("@raise ") || text.contains("@raises ") || text.contains("@except ") || text.contains("@exception ") ||
text.contains("@return:") ||
text.contains("@rtype") || text.contains("@type");
}
public static boolean isLikeGoogleDocString(@NotNull String text) {
@@ -0,0 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#ExceptionDescriptionGoogle">ExceptionDescriptionGoogle</a><br>def <b>func</b>() -&gt; None</pre></div><div class='content'>Unittest placehoder</div><table class='sections'><tr><td valign='top' class='section'><p>Raises:</td><td valign='top'><p>Exception1</p><p>Exception2 &ndash; foo</p></td></table></body></html>
@@ -0,0 +1,6 @@
def fu<the_ref>nc():
"""
Raises:
Exception1:
Exception2: foo
"""
@@ -0,0 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#ExceptionDescriptionRest">ExceptionDescriptionRest</a><br>def <b>func</b>() -&gt; None</pre></div><div class='content'>Unittest placehoder</div><table class='sections'><tr><td valign='top' class='section'><p>Raises:</td><td valign='top'><p>Exception1</p><p>Exception2 &ndash; bar</p><p>Exception3</p><p>Exception4 &ndash; foo</p></td></table></body></html>
@@ -0,0 +1,9 @@
def fu<the_ref>nc():
"""
:raises Exception1
:raise Exception2: bar
:except Exception3:
:exception Exception4: foo
"""
pass
@@ -499,6 +499,14 @@ public class PyQuickDocTest extends LightMarkedTestCase {
checkHTMLOnly();
}
public void testExceptionDescriptionRest() {
checkHTMLOnly();
}
public void testExceptionDescriptionGoogle() {
checkHTMLOnly();
}
public void testPackage() {
myFixture.copyDirectoryToProject(getTestName(false), "");
final VirtualFile file = myFixture.findFileInTempDir("pkg/__init__.py");