diff --git a/python/src/com/jetbrains/python/codeInsight/PyKeywordCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/PyKeywordCompletionContributor.java index 5f83b9bf8f5c..b463b3df1479 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyKeywordCompletionContributor.java +++ b/python/src/com/jetbrains/python/codeInsight/PyKeywordCompletionContributor.java @@ -6,6 +6,7 @@ import com.intellij.codeInsight.lookup.TailTypeDecorator; import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.patterns.ElementPattern; import com.intellij.patterns.PsiElementPattern; import com.intellij.patterns.StandardPatterns; import com.intellij.psi.*; @@ -608,17 +609,13 @@ public class PyKeywordCompletionContributor extends PySeeingOriginalCompletionCo ); } - // FIXME: conditions must be severely reworked - private void addExprElse() { extend( CompletionType.BASIC, psiElement() .withLanguage(PythonLanguage.getInstance()) - .and(INSIDE_EXPR_AFTER_IF) - .andNot(IN_IMPORT_STMT) // expressions there are not logical anyway - //.andNot(IN_PARAM_LIST) - .andNot(IN_DEFINITION) - .andNot(AFTER_QUALIFIER) + .afterLeafSkipping(psiElement().whitespace(), + psiElement().inside(psiElement(PyConditionalExpression.class)) + .and(psiElement().afterLeaf("if"))) , new CompletionProvider() { protected void addCompletions(@NotNull final CompletionParameters parameters, @@ -647,7 +644,7 @@ public class PyKeywordCompletionContributor extends PySeeingOriginalCompletionCo addImportInFrom(); addPy3kLiterals(); //addExprIf(); - //addExprElse(); + addExprElse(); } private static class PyKeywordCompletionProvider extends CompletionProvider { diff --git a/python/testData/completion/elseInCondExpr.after.py b/python/testData/completion/elseInCondExpr.after.py new file mode 100644 index 000000000000..40cfc1f0de30 --- /dev/null +++ b/python/testData/completion/elseInCondExpr.after.py @@ -0,0 +1 @@ +a = 1 if True else \ No newline at end of file diff --git a/python/testData/completion/elseInCondExpr.py b/python/testData/completion/elseInCondExpr.py new file mode 100644 index 000000000000..647fb0fbd5bd --- /dev/null +++ b/python/testData/completion/elseInCondExpr.py @@ -0,0 +1 @@ +a = 1 if True el \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java index 7b3a5b047710..cab62cac2555 100644 --- a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java +++ b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java @@ -239,4 +239,8 @@ public class PythonCompletionTest extends PyLightFixtureTestCase { public void testSuperMethod() { // PY-170 doTest(); } + + public void testElseInCondExpr() { // PY-2397 + doTest(); + } }