EA-232631 Disable f-string-like completion in strings nodes outside of a string literal

String nodes are recognized by the lexer and, thus, can still appear even in
syntactic contexts where an expression is not expected. In these cases the parser
might wrap them in a PsiErrorElement instead of a PyStringLiteralExpression causing
the reported CCE.

GitOrigin-RevId: 161d88d6307e028ede462f707f01320df2169747
This commit is contained in:
Mikhail Golubev
2020-06-30 18:29:22 +00:00
committed by intellij-monorepo-bot
parent 1679f68e32
commit fadb131582
3 changed files with 9 additions and 1 deletions
@@ -39,7 +39,8 @@ public class PyFStringLikeCompletionContributor extends CompletionContributor {
private static final PsiElementPattern.Capture<PyPlainStringElement> INSIDE_NON_FORMATTED_STRING_ELEMENT =
psiElement(PyPlainStringElement.class)
.andNot(psiElement().inside(PyStringFormatCompletionContributor.FORMAT_STRING_CAPTURE));
.withParent(PyStringLiteralExpression.class)
.andNot(psiElement().inside(PyStringFormatCompletionContributor.FORMAT_STRING_CAPTURE));
public PyFStringLikeCompletionContributor() {
extend(CompletionType.BASIC, INSIDE_NON_FORMATTED_STRING_ELEMENT, new CompletionProvider<CompletionParameters>() {
@@ -0,0 +1,2 @@
my_expr = 42
def '{my_e<caret>'
@@ -472,6 +472,11 @@ public class Py3CompletionTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
}
// EA-232631
public void testFStringLikeCompletionNotAvailableInStringElementsInSyntacticallyIllegalPosition() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath() + "/completion";