PY-48665 Disable f-string-like completion in literal string patterns

Since f-strings are not supported inside patterns.

GitOrigin-RevId: f96b8b6e999c893930203f933c6f55aec6e60869
This commit is contained in:
Mikhail Golubev
2021-06-17 20:08:03 +00:00
committed by intellij-monorepo-bot
parent 9247e2eb84
commit 09c9fc2898
3 changed files with 12 additions and 2 deletions
@@ -35,13 +35,14 @@ import static com.jetbrains.python.psi.PyUtil.as;
*/
public class PyFStringLikeCompletionContributor extends CompletionContributor {
private static final PsiElementPattern.Capture<PyPlainStringElement> INSIDE_NON_FORMATTED_STRING_ELEMENT =
private static final PsiElementPattern.Capture<PyPlainStringElement> APPLICABLE_STRING_ELEMENT =
psiElement(PyPlainStringElement.class)
.withParent(PyStringLiteralExpression.class)
.andNot(psiElement().withSuperParent(2, PyLiteralPattern.class))
.andNot(psiElement().inside(PyStringFormatCompletionContributor.FORMAT_STRING_CAPTURE));
public PyFStringLikeCompletionContributor() {
extend(CompletionType.BASIC, INSIDE_NON_FORMATTED_STRING_ELEMENT, new CompletionProvider<>() {
extend(CompletionType.BASIC, APPLICABLE_STRING_ELEMENT, new CompletionProvider<>() {
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
@NotNull ProcessingContext context,
@@ -0,0 +1,4 @@
my_expr = 42
match my_expr:
case '{my_e<caret>':
pass
@@ -474,6 +474,11 @@ public class Py3CompletionTest extends PyTestCase {
assertContainsElements(myFixture.getLookupElementStrings(), "city");
}
// PY-48665
public void testFStringLikeCompletionNotAvailableInLiteralPatterns() {
doNegativeTest();
}
// PY-46056
public void testImportCompletionHintForSameDirectoryModuleInOrdinaryPackage() {
doTestVariantTailText("ordinaryPackage/sample.py", "logging", null);