show parameter description from epydoc in Ctrl-Q

This commit is contained in:
Dmitry Jemerov
2011-04-04 20:58:25 +02:00
parent 1cac4051fe
commit 82397ca780
6 changed files with 75 additions and 5 deletions

View File

@@ -44,7 +44,7 @@ public class EpydocString {
}
else {
String arg = tagValue.substring(0, pos).trim();
Map<String, String> argValues = myArgTagValues.get(arg);
Map<String, String> argValues = myArgTagValues.get(tagName);
if (argValues == null) {
argValues = Maps.newHashMap();
myArgTagValues.put(tagName, argValues);
@@ -77,6 +77,18 @@ public class EpydocString {
return removeInlineMarkup(value);
}
@Nullable
public String getParamDescription(String paramName) {
String value = getTagValue("param", paramName);
if (value == null) {
value = getTagValue("param", "*" + paramName);
}
if (value == null) {
value = getTagValue("param", "**" + paramName);
}
return value;
}
@Nullable
public static String removeInlineMarkup(String s) {
if (s == null) return null;

View File

@@ -372,6 +372,24 @@ public class PythonDocumentationProvider extends QuickDocumentationProvider impl
doc_cat.add(combUp(PyUtil.getReadableRepr(followed, false)));
}
}
if (followed instanceof PyNamedParameter) {
PyFunction function = PsiTreeUtil.getParentOfType(followed, PyFunction.class);
if (function != null) {
final String docString = PyUtil.strValue(function.getDocStringExpression());
EpydocString epydocString = new EpydocString(docString);
if (epydocString != null) {
final String name = ((PyNamedParameter)followed).getName();
final String type = epydocString.getParamType(name);
if (type != null) {
doc_cat.add(": ").add(type);
}
final String desc = epydocString.getParamDescription(name);
if (desc != null) {
epilog_cat.add(BR).add(desc);
}
}
}
}
if (doc_cat.isEmpty() && epilog_cat.isEmpty()) return null; // got nothing substantial to say!
else return cat.toString();
}

View File

@@ -0,0 +1 @@
<html><body><code>name: str</code><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>

View File

@@ -0,0 +1,13 @@
def foo(name):
"""
Convert a string like a variable name into a slightly more human-friendly
string with spaces and capitalized letters.
@type name: C{str}
@param name: 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.
@rtype: C{str}
"""
print <the_ref>name

View File

@@ -30,4 +30,28 @@ public class EpydocStringTest extends TestCase {
EpydocString.removeInlineMarkup("The y intercept of the line. The X{y intercept} of a line is the point at which it crosses the y axis (M{x=0})."));
}
public void testMultipleTags() {
EpydocString docString = new EpydocString(" \"\"\"\n" +
" Run the given function wrapped with seteuid/setegid calls.\n" +
"\n" +
" This will try to minimize the number of seteuid/setegid calls, comparing\n" +
" current and wanted permissions\n" +
"\n" +
" @param euid: effective UID used to call the function.\n" +
" @type euid: C{int}\n" +
"\n" +
" @param egid: effective GID used to call the function.\n" +
" @type egid: C{int}\n" +
"\n" +
" @param function: the function run with the specific permission.\n" +
" @type function: any callable\n" +
"\n" +
" @param *args: arguments passed to function\n" +
" @param **kwargs: keyword arguments passed to C{function}\n" +
" \"\"\"");
assertEquals("effective UID used to call the function.", docString.getParamDescription("euid"));
assertEquals("effective GID used to call the function.", docString.getParamDescription("egid"));
assertEquals("arguments passed to function", docString.getParamDescription("args"));
}
}

View File

@@ -16,9 +16,7 @@ import java.io.IOException;
import java.util.Map;
/**
* TODO: Add description
* User: dcheryasov
* Date: Jun 7, 2009 12:31:07 PM
* @author dcheryasov
*/
public class PyQuickDocTest extends LightMarkedTestCase {
private PythonDocumentationProvider myProvider;
@@ -76,7 +74,7 @@ public class PyQuickDocTest extends LightMarkedTestCase {
Map<String, PsiElement> marks = loadTest();
final PsiElement original_elt = marks.get("<the_ref>");
PsiElement ref_elt = original_elt.getParent(); // ident -> expr
final PyDocStringOwner doc_owner = (PyDocStringOwner)((PyReferenceExpression)ref_elt).getReference().resolve();
final PsiElement doc_owner = ((PyReferenceExpression)ref_elt).getReference().resolve();
checkByHTML(myProvider.generateDoc(doc_owner, original_elt));
}
@@ -185,6 +183,10 @@ public class PyQuickDocTest extends LightMarkedTestCase {
checkHTMLOnly();
}
public void testParam() {
checkHTMLOnly();
}
public void testHoverOverClass() {
checkHover();
}