mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-45459 Make f-string like completion available after "{" on explicit invocation
GitOrigin-RevId: fe609b6a572f2ac971b2cf34eb92afe529708628
This commit is contained in:
committed by
intellij-monorepo-bot
parent
04431f29bd
commit
9590c3643e
+6
-1
@@ -65,7 +65,12 @@ public class PyFStringLikeCompletionContributor extends CompletionContributor {
|
||||
return;
|
||||
}
|
||||
String completionPrefix = stringElemText.substring(braceOffset + 1, relOffset);
|
||||
if (!PyNames.isIdentifier(completionPrefix)) {
|
||||
boolean autoPopupAfterOpeningBrace = completionPrefix.isEmpty() && parameters.isAutoPopup();
|
||||
if (autoPopupAfterOpeningBrace) {
|
||||
return;
|
||||
}
|
||||
boolean impossibleReferencePrefix = !completionPrefix.isEmpty() && !PyNames.isIdentifier(completionPrefix);
|
||||
if (impossibleReferencePrefix) {
|
||||
return;
|
||||
}
|
||||
PyExpression fString = PyUtil.createExpressionFromFragment("f" + stringElemText, stringLiteral.getParent());
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
my_expr = 42
|
||||
s = 'foo{<caret>'
|
||||
@@ -7,6 +7,7 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.inspections.PyMethodParametersInspection;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
@@ -477,6 +478,17 @@ public class Py3CompletionTest extends PyTestCase {
|
||||
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
|
||||
}
|
||||
|
||||
// PY-45459
|
||||
public void testFStringLikeCompletionAvailableRightAfterOpeningBrace() {
|
||||
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
|
||||
myFixture.configureByFile(getTestName(true) + ".py");
|
||||
LookupElement[] variants = myFixture.completeBasic();
|
||||
assertNotNull(variants);
|
||||
assertTrue(variants.length > 0);
|
||||
assertTrue(ContainerUtil.exists(variants, v -> v.getLookupString().equals("my_expr")));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/completion";
|
||||
|
||||
Reference in New Issue
Block a user