Fix disappearing green arrow on the gutter

Sometimes the green arrow disappears, because the marker contributor
isn't executed on IfStatement. Seems that it is always executed on
IF token, though.
This commit is contained in:
Dmitry Trofimov
2017-07-11 15:06:21 +02:00
parent 92bbb1ddf6
commit 626a684bfd
@@ -22,8 +22,10 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.psi.PyIfStatement;
import com.jetbrains.python.psi.PyUtil;
import org.jetbrains.annotations.NotNull;
@@ -43,6 +45,15 @@ public class PyRunLineMarkerContributor extends RunLineMarkerContributor {
}
private static boolean isMainClauseOnTopLevel(@NotNull PsiElement element) {
return element instanceof PyIfStatement && element.getParent() instanceof PsiFile && PyUtil.isIfNameEqualsMain(((PyIfStatement)element));
if (element.getNode().getElementType() == PyTokenTypes.IF_KEYWORD) {
element = PsiTreeUtil.getParentOfType(element, PyIfStatement.class);
return element != null &&
element.getParent() instanceof PsiFile &&
PyUtil.isIfNameEqualsMain(((PyIfStatement)element));
}
else {
return false;
}
}
}