mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-25779 Show documentation for method if caret is placed inside parameters list
This commit is contained in:
@@ -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 type: () -> None<br><br>Doc of foo.</code></body></html>
|
||||
@@ -0,0 +1,6 @@
|
||||
# directly in function
|
||||
def foo():
|
||||
"<the_doc>Doc of foo."
|
||||
pass
|
||||
|
||||
foo(<the_ref>)
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>len</b>(o: Sized)<br>Inferred type: (o: Sized) -> <a href="psi_element://#typename#int">int</a><br><br><br>len(object) -> integer<br><br>Return the number of items of a sequence or 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: Sized)<br>Inferred type: (o: Sized) -> <a href="psi_element://#typename#int">int</a><br><br><br>len(object) -> integer<br><br>Return the number of items of a sequence or 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user