From febdc1ae36aa1f839a5bd3577a5b2a6e2df2da5a Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Mon, 30 Sep 2019 11:52:07 +0700 Subject: [PATCH] Fix PY-13111 GitOrigin-RevId: 3b4c03eabb6b4ae26343afc58d598a379e9a80bf --- .../completion/PyKeywordCompletionContributor.java | 13 +++++++++---- .../noForAndYieldInCommentContext.py | 6 ++++++ .../python/PythonKeywordCompletionTest.java | 12 ++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 python/testData/keywordCompletion/noForAndYieldInCommentContext.py diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java index 93fa1cf91561..d2f62097e82b 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java +++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java @@ -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)); } diff --git a/python/testData/keywordCompletion/noForAndYieldInCommentContext.py b/python/testData/keywordCompletion/noForAndYieldInCommentContext.py new file mode 100644 index 000000000000..19fa0a368262 --- /dev/null +++ b/python/testData/keywordCompletion/noForAndYieldInCommentContext.py @@ -0,0 +1,6 @@ +MIDDLEWARE_CLASSES = ( + 'django.middleware.1', # + 'django.middleware.2', + 'django.middleware.3', + 'django.middleware.4', +) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonKeywordCompletionTest.java b/python/testSrc/com/jetbrains/python/PythonKeywordCompletionTest.java index da6a5d8a6c8f..9c711284f12d 100644 --- a/python/testSrc/com/jetbrains/python/PythonKeywordCompletionTest.java +++ b/python/testSrc/com/jetbrains/python/PythonKeywordCompletionTest.java @@ -27,6 +27,13 @@ public class PythonKeywordCompletionTest extends PyTestCase { return myFixture.getLookupElementStrings(); } + private List 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 ... ")); myFixture.checkResult("from ... import "); } + + // PY-13111 + public void testNoForAndYieldInCommentContext() { + assertDoesntContain(doTestByTestName(), "for", "yield"); + } }