fixed PY-11884 Missing completion for finally keyword after else statement

This commit is contained in:
Ekaterina Tuzova
2014-01-23 13:27:22 +04:00
parent 1697889d5f
commit 100bad79db
4 changed files with 26 additions and 3 deletions

View File

@@ -308,6 +308,9 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
private static final PsiElementPattern.Capture<PsiElement> IN_EXCEPT_BODY =
psiElement().inside(psiElement(PyStatementList.class).inside(psiElement(PyExceptPart.class)));
private static final PsiElementPattern.Capture<PsiElement> IN_ELSE_BODY_OF_TRY =
psiElement().inside(psiElement(PyStatementList.class).inside(psiElement(PyElsePart.class).inside(PyTryExceptStatement.class)));
private static final PsiElementPattern.Capture<PsiElement> AFTER_IF = afterStatement(psiElement(PyIfStatement.class).withLastChild(
psiElement(PyIfPart.class)));
private static final PsiElementPattern.Capture<PsiElement> AFTER_TRY = afterStatement(psiElement(PyTryExceptStatement.class));
@@ -479,7 +482,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor {
CompletionType.BASIC, psiElement()
.withLanguage(PythonLanguage.getInstance())
.and(FIRST_ON_LINE)
.andOr(IN_TRY_BODY, IN_EXCEPT_BODY, AFTER_TRY)
.andOr(IN_TRY_BODY, IN_EXCEPT_BODY, AFTER_TRY, IN_ELSE_BODY_OF_TRY)
//.andNot(RIGHT_AFTER_COLON)
.andNot(AFTER_QUALIFIER).andNot(IN_STRING_LITERAL)
,

View File

@@ -0,0 +1,8 @@
def f():
try:
a = 1
except:
b = 1
else:
c = 1
finally:

View File

@@ -0,0 +1,8 @@
def f():
try:
a = 1
except:
b = 1
else:
c = 1
fin<caret>

View File

@@ -124,8 +124,8 @@ public class PythonKeywordCompletionTest extends PyTestCase {
public void testNoElseBeforeExcept() {
final List<String> lookupElementStrings = doTestByText("try:\n" +
" a = 1\n" +
"<caret>");
" a = 1\n" +
"<caret>");
assertNotNull(lookupElementStrings);
assertDoesntContain(lookupElementStrings, "else");
}
@@ -169,6 +169,10 @@ public class PythonKeywordCompletionTest extends PyTestCase {
"el<caret>").contains("else"));
}
public void testFinallyInElse() { // PY-6755
doTest();
}
public void testForInComprehension() { // PY-3687
assertContainsElements(doTestByText("L = [x fo<caret>]"), "for");
assertContainsElements(doTestByText("L = [x <caret>]"), "for");