fixed PY-10248 Suggestion does not suggest "in" keyword after "for x "
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Wed, 30 Oct 2013 09:48:06 +0000 (13:48 +0400)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Wed, 30 Oct 2013 09:48:06 +0000 (13:48 +0400)
python/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java
python/testSrc/com/jetbrains/python/PythonKeywordCompletionTest.java

index 48bafdcf782cc9e730e6138695ccf650f6d4ee24..44ef899aeff93e49b4687cf5acc8bd78a533e6db 100644 (file)
@@ -644,22 +644,24 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
     addExprElse();
     addRaiseFrom();
     addYieldFrom();
-    addToComprehensions();
+    addForToComprehensions();
+    addInToFor();
   }
 
-  private void addToComprehensions() {
+  private void addForToComprehensions() {
     extend(CompletionType.BASIC,
            psiElement()
              .withLanguage(PythonLanguage.getInstance())
              .inside(psiElement(PySequenceExpression.class))
              .andNot(psiElement().afterLeaf(or(psiElement(PyTokenTypes.LBRACE), psiElement(PyTokenTypes.LBRACKET), psiElement(PyTokenTypes.LPAR)))),
            new PyKeywordCompletionProvider("for"));
+  }
 
+  private void addInToFor() {
     extend(CompletionType.BASIC,
            psiElement()
              .withLanguage(PythonLanguage.getInstance())
-             .and(psiElement().inside(psiElement(PyComprehensionElement.class)))
-             .afterLeaf(psiElement().inside(psiElement(PyComprehensionElement.class)).and(psiElement().afterLeaf("for"))),
+             .and(psiElement()).afterLeaf(psiElement().afterLeaf("for")),
            new PyKeywordCompletionProvider("in"));
 
   }
index 8280eff89e2256d6de6c5fb7d91787690d06eb3e..a4397270e20dd13866cd36116023c2993e57d269 100644 (file)
@@ -188,4 +188,10 @@ public class PythonKeywordCompletionTest extends PyTestCase {
     assertDoesntContain(doTestByText("L = [x <caret> for]"), "in");
     assertDoesntContain(doTestByText("L = [x <caret>]"), "in");
   }
+
+  public void testInInFor() {  // PY-10248
+    assertContainsElements(doTestByText("for x <caret>]"), "in");
+    assertContainsElements(doTestByText("for x i<caret>]"), "in");
+    assertContainsElements(doTestByText("for x i<caret>n y:\n  pass]"), "in");
+  }
 }