PY-29717 Wrap both prolog and body in <div class="definition"> block

This commit is contained in:
Mikhail Golubev
2018-06-09 15:59:36 +03:00
parent c3246e9286
commit 065ce992dc
11 changed files with 28 additions and 23 deletions
@@ -69,9 +69,9 @@ import static com.jetbrains.python.documentation.DocumentationBuilderKit.*;
public class PyDocumentationBuilder {
private final PsiElement myElement;
private final PsiElement myOriginalElement;
private ChainIterable<String> myResult;
private final ChainIterable<String> myProlog; // sequence for reassignment info, etc
private final ChainIterable<String> myBody; // sequence for doc string
private final ChainIterable<String> myContent;
private final ChainIterable<String> mySections;
private final ChainIterable<String> myEpilog; // sequence for doc "copied from" notices and such
@@ -82,15 +82,11 @@ public class PyDocumentationBuilder {
public PyDocumentationBuilder(PsiElement element, PsiElement originalElement) {
myElement = element;
myOriginalElement = originalElement;
myResult = new ChainIterable<>();
myProlog = new ChainIterable<>();
myBody = new ChainIterable<>();
myContent = new ChainIterable<>();
mySections = new ChainIterable<>();
myEpilog = new ChainIterable<>();
myResult.add(myProlog).add(myBody).add(mySections).add(myEpilog); // pre-assemble; then add stuff to individual cats as needed
myResult = wrapInTag("html", wrapInTag("body", myResult));
}
@Nullable
@@ -144,11 +140,24 @@ public class PyDocumentationBuilder {
myEpilog.addItem("<a href=\"").addItem(url).addItem("\">").addItem(url).addItem("</a>");
}
if (myBody.isEmpty() && myEpilog.isEmpty()) {
if (myBody.isEmpty() && myContent.isEmpty() && myEpilog.isEmpty()) {
return null; // got nothing substantial to say!
}
else {
return myResult.toString();
ChainIterable<String> result = new ChainIterable<>();
if (!myProlog.isEmpty() || !myBody.isEmpty()) {
result.addItem(DocumentationMarkup.DEFINITION_START)
.add(myProlog)
.add(myBody)
.addItem(DocumentationMarkup.DEFINITION_END);
}
if (!myContent.isEmpty()) {
result.addItem(DocumentationMarkup.CONTENT_START)
.add(myContent)
.addItem(DocumentationMarkup.CONTENT_END);
}
result.add(mySections).add(myEpilog); // pre-assemble; then add stuff to individual cats as needed
return wrapInTag("html", wrapInTag("body", result)).toString();
}
}
@@ -297,7 +306,6 @@ public class PyDocumentationBuilder {
content = formatDocString(myElement, docStringExpression.getStringValue());
}
final TypeEvalContext context = TypeEvalContext.userInitiated(elementDefinition.getProject(), elementDefinition.getContainingFile());
myBody.addItem(DocumentationMarkup.DEFINITION_START);
if (elementDefinition instanceof PyClass) {
pyClass = (PyClass)elementDefinition;
@@ -340,11 +348,8 @@ public class PyDocumentationBuilder {
myBody.add(PythonDocumentationProvider.describeTarget(target, context));
}
myBody.addItem(DocumentationMarkup.DEFINITION_END);
if (content != null && !content.isEmpty()) {
myBody.addItem(DocumentationMarkup.CONTENT_START);
myBody.add(content);
myBody.addItem(DocumentationMarkup.CONTENT_END);
myContent.add(content);
}
}
+1 -1
View File
@@ -1 +1 @@
<html><body>Class attribute <b><code>the_attr</code></b> of class <a href="psi_element://#class#"><code>C</code></a><br><div class='definition'><pre>the_attr: <a href="psi_element://#typename#str">str</a></pre></div><div class='content'>The&nbsp;documentation&nbsp;for&nbsp;the&nbsp;attribute.&nbsp;</div></body></html>
<html><body><div class='definition'><pre>Class attribute <b><code>the_attr</code></b> of class <a href="psi_element://#class#"><code>C</code></a><br>the_attr: <a href="psi_element://#typename#str">str</a></pre></div><div class='content'>The&nbsp;documentation&nbsp;for&nbsp;the&nbsp;attribute.&nbsp;</div></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>Instance attribute <b><code>foo</code></b> of class <a href="psi_element://#class#"><code>C</code></a><br><div class='definition'><pre>foo: <a href="psi_element://#typename#str">str</a></pre></div><div class='content'>The&nbsp;docstring&nbsp;for&nbsp;the&nbsp;attribute&nbsp;foo.&nbsp;</div></body></html>
<html><body><div class='definition'><pre>Instance attribute <b><code>foo</code></b> of class <a href="psi_element://#class#"><code>C</code></a><br>foo: <a href="psi_element://#typename#str">str</a></pre></div><div class='content'>The&nbsp;docstring&nbsp;for&nbsp;the&nbsp;attribute&nbsp;foo.&nbsp;</div></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>Module <b>Module</b><div class='definition'><pre></pre></div><div class='content'><br>Module's&nbsp;doc.</div></body></html>
<html><body><div class='definition'><pre>Module <b>Module</b></pre></div><div class='content'><br>Module's&nbsp;doc.</div></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>Parameter&nbsp;name: <a href="psi_element://#param#">str</a><br>The name to convert to a label. This must be a string which could be used as a Python identifier. Strings which do not take this form will result in unpredictable behavior.</body></html>
<html><body><div class='definition'><pre>Parameter&nbsp;name: <a href="psi_element://#param#">str</a></pre></div><br>The name to convert to a label. This must be a string which could be used as a Python identifier. Strings which do not take this form will result in unpredictable behavior.</body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<br><br><div class='definition'><pre>@<i>x.deleter</i><br>def&nbsp;<b>x</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Deletes&nbsp;X</div><small><br><br>Deleter of property</small><br></body></html>
<html><body><div class='definition'><pre>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<br><br>@<i>x.deleter</i><br>def&nbsp;<b>x</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Deletes&nbsp;X</div><small><br><br>Deleter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br><div class='definition'><pre>@<i>property</i><br>def&nbsp;<b>x</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a></pre></div><div class='content'>Does&nbsp;things&nbsp;to&nbsp;X</div></code><small><br><br>Getter of property</small><br></body></html>
<html><body><div class='definition'><pre>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><br>@<i>property</i><br>def&nbsp;<b>x</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a></pre></div><div class='content'>Does&nbsp;things&nbsp;to&nbsp;X</div><small><br><br>Getter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<br><br><div class='definition'><pre>@<i>x.setter</i><br>def&nbsp;<b>x</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Sets&nbsp;X</div><small><br><br>Setter of property</small><br></body></html>
<html><body><div class='definition'><pre>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<br><br>@<i>x.setter</i><br>def&nbsp;<b>x</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Sets&nbsp;X</div><small><br><br>Setter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><br><div class='definition'><pre>def&nbsp;<b>__getX</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any</pre></div><div class='content'>Doc&nbsp;of&nbsp;getter</div><small><br><br>Deleter of property</small><br></body></html>
<html><body><div class='definition'><pre>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><br>def&nbsp;<b>__getX</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any</pre></div><div class='content'>Doc&nbsp;of&nbsp;getter</div><small><br><br>Deleter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><br><div class='definition'><pre>def&nbsp;<b>__getX</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any</pre></div><div class='content'>Doc&nbsp;of&nbsp;getter</div><small><br><br>Getter of property</small><br></body></html>
<html><body><div class='definition'><pre>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><br>def&nbsp;<b>__getX</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any</pre></div><div class='content'>Doc&nbsp;of&nbsp;getter</div><small><br><br>Getter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><br><div class='definition'><pre>def&nbsp;<b>__getX</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;x:&nbsp;Any)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Doc&nbsp;of&nbsp;getter</div><small><br><br>Setter of property</small><br></body></html>
<html><body><div class='definition'><pre>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><br>def&nbsp;<b>__getX</b>(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;x:&nbsp;Any)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Doc&nbsp;of&nbsp;getter</div><small><br><br>Setter of property</small><br></body></html>