PY-25779 Show documentation for method if caret is placed inside parameters list

This commit is contained in:
Ekaterina Tuzova
2017-09-01 13:30:04 +03:00
parent 8116bf7c1c
commit 048e421e55
5 changed files with 35 additions and 4 deletions
@@ -31,9 +31,11 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.QualifiedName;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonDialectsTokenSetProvider;
import com.jetbrains.python.codeInsight.stdlib.PyStdlibDocumentationLinkProvider;
import com.jetbrains.python.console.PydevConsoleRunner;
@@ -547,9 +549,23 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
public PsiElement getCustomDocumentationElement(@NotNull Editor editor,
@NotNull PsiFile file,
@Nullable PsiElement contextElement) {
if (contextElement != null &&
PythonDialectsTokenSetProvider.INSTANCE.getKeywordTokens().contains(contextElement.getNode().getElementType())) {
return contextElement;
if (contextElement != null) {
final IElementType elementType = contextElement.getNode().getElementType();
if (PythonDialectsTokenSetProvider.INSTANCE.getKeywordTokens().contains(elementType)) {
return contextElement;
}
if (PyTokenTypes.LPAR == elementType || PyTokenTypes.RPAR == elementType) {
final PyCallExpression expression = PsiTreeUtil.getParentOfType(contextElement, PyCallExpression.class);
if (expression != null) {
final PyExpression callee = expression.getCallee();
if (callee != null) {
final PsiReference reference = callee.getReference();
if (reference != null) {
return reference.resolve();
}
}
}
}
}
return super.getCustomDocumentationElement(editor, file, contextElement);
}
@@ -0,0 +1 @@
<html><body><code>def <b>foo</b>()<br>Inferred&nbsp;type:&nbsp;()&nbsp;-&gt;&nbsp;None<br><br>Doc&nbsp;of&nbsp;foo.</code></body></html>
+6
View File
@@ -0,0 +1,6 @@
# directly in function
def foo():
"<the_doc>Doc of foo."
pass
foo(<the_ref>)
+1 -1
View File
@@ -1 +1 @@
<html><body><code>def <b>len</b>(o:&nbsp;Sized)<br>Inferred&nbsp;type:&nbsp;(o:&nbsp;Sized)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a><br><br><br>len(object)&nbsp;-&gt;&nbsp;integer<br><br>Return&nbsp;the&nbsp;number&nbsp;of&nbsp;items&nbsp;of&nbsp;a&nbsp;sequence&nbsp;or&nbsp;collection.<br></code><br><b>External documentation:</b><br><a href="http://docs.python.org/2.7 Mock SDK/library/__builtin__.html#__builtin__.len">http://docs.python.org/2.7 Mock SDK/library/__builtin__.html#__builtin__.len</a></body></html>
<html><body><code>def <b>len</b>(o:&nbsp;Sized)<br>Inferred&nbsp;type:&nbsp;(o:&nbsp;Sized)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a><br><br><br>len(object)&nbsp;-&gt;&nbsp;integer<br><br>Return&nbsp;the&nbsp;number&nbsp;of&nbsp;items&nbsp;of&nbsp;a&nbsp;sequence&nbsp;or&nbsp;collection.<br></code></body></html>
@@ -292,6 +292,14 @@ public class PyQuickDocTest extends LightMarkedTestCase {
checkHTMLOnly();
}
public void testArgumentList() {
Map<String, PsiElement> marks = loadTest();
final PsiElement originalElement = marks.get("<the_ref>");
final PsiElement element = myProvider.getCustomDocumentationElement(myFixture.getEditor(), myFile, originalElement);
checkByHTML(myProvider.generateDoc(element, originalElement));
}
public void testReferenceToMethodQualifiedWithInstance() {
checkHTMLOnly();
}