PY-11375 Fix 'yield' keyword completion in yield expressions

This commit is contained in:
Mikhail Golubev
2014-09-08 14:31:19 +04:00
parent 44cc8ed7d9
commit f13682a2e7
2 changed files with 11 additions and 2 deletions
@@ -649,8 +649,13 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
extend(CompletionType.BASIC,
psiElement()
.withLanguage(PythonLanguage.getInstance())
.inside(false, psiElement(PyAssignmentStatement.class), psiElement(PyTargetExpression.class))
.afterLeaf("=", "("),
.andOr(psiElement()
.inside(false, psiElement(PyAssignmentStatement.class), psiElement(PyTargetExpression.class))
.afterLeaf(psiElement().withElementType(PyTokenTypes.EQ)),
psiElement()
.inside(false, psiElement(PyAugAssignmentStatement.class), psiElement(PyTargetExpression.class))
.afterLeaf(psiElement().withElementType(PyTokenTypes.AUG_ASSIGN_OPERATIONS)),
psiElement().inside(true, psiElement(PyParenthesizedExpression.class))),
new PyKeywordCompletionProvider(PyNames.YIELD));
}
@@ -204,6 +204,10 @@ public class PythonKeywordCompletionTest extends PyTestCase {
assertContainsElements(doTestByText("def gen(): x = <caret>"), "yield");
assertDoesntContain(doTestByText("def gen(): x = 1 + <caret>"), "yield");
assertContainsElements(doTestByText("def gen(): x = 1 + (<caret>"), "yield");
assertContainsElements(doTestByText("def gen(): x **= <caret>"), "yield");
assertDoesntContain(doTestByText("def gen(): func(<caret>)"), "yield");
assertContainsElements(doTestByText("def gen(): func((<caret>"), "yield");
assertDoesntContain(doTestByText("def gen(): x = y<caret> = 42"), "yield");
}
public void testExceptAfterElse() {