Fix PY-13111

GitOrigin-RevId: 3b4c03eabb6b4ae26343afc58d598a379e9a80bf
This commit is contained in:
andrey.matveev
2019-09-30 05:31:39 +00:00
committed by intellij-monorepo-bot
parent 7171e99dbd
commit febdc1ae36
3 changed files with 27 additions and 4 deletions
@@ -706,7 +706,10 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
psiElement()
.inside(false, psiElement(PyAugAssignmentStatement.class), psiElement(PyTargetExpression.class))
.afterLeaf(psiElement().withElementType(PyTokenTypes.AUG_ASSIGN_OPERATIONS)),
psiElement().inside(true, psiElement(PyParenthesizedExpression.class))).andNot(IN_STRING_LITERAL),
psiElement()
.inside(true, psiElement(PyParenthesizedExpression.class)))
.andNot(IN_STRING_LITERAL)
.andNot(IN_COMMENT),
new PyKeywordCompletionProvider(PyNames.YIELD));
}
@@ -745,9 +748,11 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
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)))),
.withLanguage(PythonLanguage.getInstance())
.inside(psiElement(PySequenceExpression.class))
.andNot(psiElement()
.afterLeaf(or(psiElement(PyTokenTypes.LBRACE), psiElement(PyTokenTypes.LBRACKET), psiElement(PyTokenTypes.LPAR))))
.andNot(IN_COMMENT),
new PyKeywordCompletionProvider(PyNames.FOR));
}
@@ -0,0 +1,6 @@
MIDDLEWARE_CLASSES = (
'django.middleware.1', #<caret>
'django.middleware.2',
'django.middleware.3',
'django.middleware.4',
)
@@ -27,6 +27,13 @@ public class PythonKeywordCompletionTest extends PyTestCase {
return myFixture.getLookupElementStrings();
}
private List<String> doTestByTestName() {
final String testName = "keywordCompletion/" + getTestName(true);
myFixture.configureByFile(testName + ".py");
myFixture.completeBasic();
return myFixture.getLookupElementStrings();
}
public void testKeywordAfterComment() { // PY-697
doTest();
}
@@ -228,4 +235,9 @@ public class PythonKeywordCompletionTest extends PyTestCase {
assertNull(doTestByText("from ... <caret>"));
myFixture.checkResult("from ... import ");
}
// PY-13111
public void testNoForAndYieldInCommentContext() {
assertDoesntContain(doTestByTestName(), "for", "yield");
}
}