PY-15469 Properly place backslashes in various places inside function header

This commit is contained in:
Mikhail Golubev
2015-04-08 14:16:43 +03:00
parent 90f415fdba
commit aced4ab039
2 changed files with 48 additions and 2 deletions

View File

@@ -66,7 +66,7 @@ public class PythonEnterHandler extends EnterHandlerDelegateAdapter {
PyListLiteralExpression.class,
PyArgumentList.class,
PyParameterList.class,
PyFunction.class,
PyDecoratorList.class,
PySliceExpression.class,
PySubscriptionExpression.class,
PyGeneratorExpression.class
@@ -248,7 +248,10 @@ public class PythonEnterHandler extends EnterHandlerDelegateAdapter {
if (wrappableBefore instanceof PsiComment || wrappableAfter instanceof PsiComment) {
return false;
}
return wrappableAfter == null || wrappableBefore != wrappableAfter;
if (wrappableAfter == null) {
return !(wrappableBefore instanceof PyDecoratorList);
}
return wrappableBefore != wrappableAfter;
}
private static void insertDocStringStub(Editor editor, PsiElement element) {

View File

@@ -29,6 +29,7 @@ import com.intellij.psi.PsiFile;
import com.jetbrains.python.documentation.DocStringFormat;
import com.jetbrains.python.documentation.PyDocumentationSettings;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.psi.LanguageLevel;
/**
* @author yole
@@ -319,6 +320,48 @@ public class PyEditingTest extends PyTestCase {
" ')'");
}
public void testEnterAfterDefKeywordInFunction() {
doTestEnter("def <caret>func():\n" +
" pass",
"def \\\n" +
" func():\n" +
" pass");
}
public void testEnterBeforeColonInFunction() {
doTestEnter("def func()<caret>:\n" +
" pass",
"def func()\\\n" +
" :\n" +
" pass");
}
// PY-15469
public void testEnterBeforeArrowInFunction() {
runWithLanguageLevel(LanguageLevel.PYTHON30, new Runnable() {
public void run() {
doTestEnter("def func() <caret>-> int:\n" +
" pass",
"def func() \\\n" +
" -> int:\n" +
" pass");
}
});
}
// PY-15469
public void testEnterAfterArrowInFunction() {
runWithLanguageLevel(LanguageLevel.PYTHON30, new Runnable() {
public void run() {
doTestEnter("def func() -><caret> int:\n" +
" pass",
"def func() ->\\\n" +
" int:\n" +
" pass");
}
});
}
private void doTestEnter(String before, final String after) {
int pos = before.indexOf("<caret>");
before = before.replace("<caret>", "");