diff --git a/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java b/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java index 9ee79e05469c..c834b116fcf4 100644 --- a/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java @@ -7,6 +7,7 @@ import com.intellij.codeInsight.codeFragment.Position; import com.intellij.codeInsight.controlflow.ConditionalInstruction; import com.intellij.codeInsight.controlflow.Instruction; import com.intellij.psi.PsiElement; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.containers.HashSet; import com.jetbrains.python.PyBundle; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; @@ -83,6 +84,10 @@ public class PyCodeFragmentUtil { if (nextElement instanceof PyExceptPart){ continue; } + // We allow raise statements in code + if (nextElement == null && PsiTreeUtil.getParentOfType(element, PyRaiseStatement.class) != null){ + continue; + } if (!CodeFragmentUtil.elementFit(nextElement, start, end)){ outerInstructions.add(next); } diff --git a/python/testData/codeInsight/codefragment/raise2102.test b/python/testData/codeInsight/codefragment/raise2102.test new file mode 100644 index 000000000000..a9f49a6fdb23 --- /dev/null +++ b/python/testData/codeInsight/codefragment/raise2102.test @@ -0,0 +1,17 @@ +foo() + +for i in range(l): + if foo: + if tag is None: + if bar: + do + else: + if baz: + raise ValueError(i) + else: + bzzzz + +bar() + +In: +Out: \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyCodeFragmentTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyCodeFragmentTest.java index 353069f54939..8f46ff540429 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyCodeFragmentTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyCodeFragmentTest.java @@ -159,5 +159,10 @@ public class PyCodeFragmentTest extends LightMarkedTestCase { public void testForIfReturn() throws Exception { doTest(); } + + public void testRaise2102() throws Exception { + doTest(); + } + }