mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
PY-11375 Suggested "yield" keyword in completion for "yield expression" context
This commit is contained in:
+11
-1
@@ -278,7 +278,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
|
||||
private static final PsiElementPattern.Capture<PsiElement> IN_IF_BODY =
|
||||
psiElement().inside(psiElement(PyStatementList.class).inside(psiElement(PyIfPart.class)));
|
||||
|
||||
private static final PsiElementPattern.Capture<PsiElement> IN_LOOP =
|
||||
private static final PsiElementPattern.Capture<PsiElement> IN_LOOP =
|
||||
psiElement().inside(false, psiElement(PyLoopStatement.class), or(psiElement(PyFunction.class), psiElement(PyClass.class)));
|
||||
|
||||
// not exactly a beauty
|
||||
@@ -645,6 +645,15 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
|
||||
new PyKeywordCompletionProvider(PyNames.FROM));
|
||||
}
|
||||
|
||||
private void addYieldExpression() {
|
||||
extend(CompletionType.BASIC,
|
||||
psiElement()
|
||||
.withLanguage(PythonLanguage.getInstance())
|
||||
.inside(false, psiElement(PyAssignmentStatement.class), psiElement(PyTargetExpression.class))
|
||||
.afterLeaf("=", "("),
|
||||
new PyKeywordCompletionProvider(PyNames.YIELD));
|
||||
}
|
||||
|
||||
private void addYieldFrom() {
|
||||
extend(CompletionType.BASIC,
|
||||
psiElement()
|
||||
@@ -671,6 +680,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
|
||||
//addExprIf();
|
||||
addExprElse();
|
||||
addRaiseFrom();
|
||||
addYieldExpression();
|
||||
addYieldFrom();
|
||||
addForToComprehensions();
|
||||
addInToFor();
|
||||
|
||||
@@ -199,6 +199,13 @@ public class PythonKeywordCompletionTest extends PyTestCase {
|
||||
assertContainsElements(doTestByText("for x i<caret>n y:\n pass]"), "in");
|
||||
}
|
||||
|
||||
// PY-11375
|
||||
public void testYieldExpression() {
|
||||
assertContainsElements(doTestByText("def gen(): x = <caret>"), "yield");
|
||||
assertDoesntContain(doTestByText("def gen(): x = 1 + <caret>"), "yield");
|
||||
assertContainsElements(doTestByText("def gen(): x = 1 + (<caret>"), "yield");
|
||||
}
|
||||
|
||||
public void testExceptAfterElse() {
|
||||
assertDoesntContain(doTestByText("try:\n" +
|
||||
" pass\n" +
|
||||
|
||||
Reference in New Issue
Block a user