PY-19917 Support type ignore comments

(cherry picked from commit 693b7f2bf037ac9fd464e330390c76ee5268c023)

IJ-MR-5695

GitOrigin-RevId: 354a4ba98e0ff01787ae0718c8643772b118fc9f
This commit is contained in:
andrey.matveev
2021-01-18 20:23:06 +07:00
committed by intellij-monorepo-bot
parent 4ca740f0e6
commit 3322cedc0d
9 changed files with 301 additions and 23 deletions

View File

@@ -662,4 +662,21 @@ public final class PyPsiUtils {
return element.getText();
}
}
@Nullable
public static PsiComment findSameLineComment(@NotNull PsiElement elem) {
// If `elem` is a compound multi-line element, stick to its first line nonetheless
PsiElement next = PsiTreeUtil.getDeepestFirst(elem);
do {
if (next instanceof PsiComment) {
return (PsiComment)next;
}
if (next != elem && next.textContains('\n')) {
break;
}
next = PsiTreeUtil.nextLeaf(next);
}
while (next != null);
return null;
}
}