PY-16870, PY-16972 Complete actual name of PyClass inside docstrings, not its toString()
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Mon, 21 Sep 2015 12:44:04 +0000 (15:44 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Tue, 22 Sep 2015 08:31:30 +0000 (11:31 +0300)
See com.intellij.codeInsight.completion.CompletionData#objectToLookupItem

python/src/com/jetbrains/python/codeInsight/completion/PyDocstringCompletionContributor.java
python/testData/completion/classNameInDocstring.after.py [new file with mode: 0644]
python/testData/completion/classNameInDocstring.py [new file with mode: 0644]
python/testSrc/com/jetbrains/python/PythonCompletionTest.java

index 594c64754b7c5bc3ad66afc71d80d60bb1a1c856..d5d386a622ad7f12b3cedf3eb39a0e66e37629c6 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleUtilCore;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiNamedElement;
 import com.intellij.psi.PsiReference;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.util.ProcessingContext;
@@ -84,7 +85,12 @@ public class PyDocstringCompletionContributor extends CompletionContributor {
       }
       else if (reference instanceof DocStringTypeReference) {
         for (Object variant : ((DocStringTypeReference)reference).collectTypeVariants()) {
-          result.addElement(LookupElementBuilder.create(variant));
+          if (variant instanceof PsiNamedElement) {
+            result.addElement(LookupElementBuilder.createWithIcon((PsiNamedElement)variant));
+          }
+          else {
+            result.addElement(LookupElementBuilder.create(variant));
+          }
         }
       }
     }
diff --git a/python/testData/completion/classNameInDocstring.after.py b/python/testData/completion/classNameInDocstring.after.py
new file mode 100644 (file)
index 0000000..428167b
--- /dev/null
@@ -0,0 +1,8 @@
+class MyClass:
+    pass
+
+def f(x):
+    """
+    @param x:
+    @type x: MyClass
+    """
\ No newline at end of file
diff --git a/python/testData/completion/classNameInDocstring.py b/python/testData/completion/classNameInDocstring.py
new file mode 100644 (file)
index 0000000..8c51992
--- /dev/null
@@ -0,0 +1,8 @@
+class MyClass:
+    pass
+
+def f(x):
+    """
+    @param x:
+    @type x: MyC<caret>
+    """
\ No newline at end of file
index ef19da7f5ccbcc277c742ee2c238d4efcaeba9f7..f0fade3aebab789940951e1265a3629abf14fe20 100644 (file)
@@ -462,6 +462,16 @@ public class PythonCompletionTest extends PyTestCase {
     });
   }
 
+  // PY-16870, PY-16972
+  public void testClassNameInDocstring() {
+    runWithDocStringFormat(DocStringFormat.EPYTEXT, new Runnable() {
+      @Override
+      public void run() {
+        doTest();
+      }
+    });
+  }
+
   public void testPep328Completion() {  // PY-3409
     myFixture.copyDirectoryToProject("pep328", "pep328");
     myFixture.configureByFile("pep328/package/subpackage1/moduleX.py");