mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-8520 Refill Paragraph should not move first line in docstring to the line with quotes
do not move docstring if it is from the beginning at the first string (or the last) with quotes
This commit is contained in:
@@ -2,6 +2,7 @@ package com.jetbrains.python.actions;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.fillParagraph.ParagraphFillHandler;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -15,6 +16,8 @@ import com.jetbrains.python.psi.PyStringLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User : ktisha
|
||||
*/
|
||||
@@ -25,12 +28,22 @@ public class PyFillParagraphHandler extends ParagraphFillHandler {
|
||||
final PyStringLiteralExpression stringLiteralExpression =
|
||||
PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class);
|
||||
if (stringLiteralExpression != null) {
|
||||
final String text = stringLiteralExpression.getText();
|
||||
final Pair<String,String> quotes =
|
||||
PythonStringUtil.getQuotes(stringLiteralExpression.getText());
|
||||
PythonStringUtil.getQuotes(text);
|
||||
final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class);
|
||||
if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) {
|
||||
String indent = getIndent(stringLiteralExpression);
|
||||
return quotes != null? quotes.getFirst()+ indent : "\"" + indent;
|
||||
if (quotes != null) {
|
||||
final List<String> strings = StringUtil.split(text, "\n");
|
||||
if (strings.get(0).trim().equals(quotes.getFirst())) {
|
||||
return quotes.getFirst() + indent;
|
||||
}
|
||||
else {
|
||||
return quotes.getFirst();
|
||||
}
|
||||
}
|
||||
return "\"" + indent;
|
||||
}
|
||||
else
|
||||
return quotes != null? quotes.getFirst() : "\"";
|
||||
@@ -57,12 +70,22 @@ public class PyFillParagraphHandler extends ParagraphFillHandler {
|
||||
final PyStringLiteralExpression stringLiteralExpression =
|
||||
PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class);
|
||||
if (stringLiteralExpression != null) {
|
||||
final String text = stringLiteralExpression.getText();
|
||||
final Pair<String,String> quotes =
|
||||
PythonStringUtil.getQuotes(stringLiteralExpression.getText());
|
||||
PythonStringUtil.getQuotes(text);
|
||||
final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class);
|
||||
if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) {
|
||||
String indent = getIndent(stringLiteralExpression);
|
||||
return quotes != null? indent + quotes.getSecond() : indent + "\"";
|
||||
if (quotes != null) {
|
||||
final List<String> strings = StringUtil.split(text, "\n");
|
||||
if (strings.get(strings.size()-1).trim().equals(quotes.getSecond())) {
|
||||
return indent + quotes.getSecond();
|
||||
}
|
||||
else {
|
||||
return quotes.getSecond();
|
||||
}
|
||||
}
|
||||
return indent + "\"";
|
||||
}
|
||||
else
|
||||
return quotes != null? quotes.getSecond() : "\"";
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
def foo():
|
||||
"""A M<caret>ap from key to total # of views by that key. This can be expensive to
|
||||
the big fetch with blackjack and whores, so we generally want to fetch this only for keys that have a large
|
||||
absolute number of views, a small number of days between views, etc."""
|
||||
@@ -0,0 +1,6 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
def foo():
|
||||
"""A Map from key to total # of views by that key. This can be expensive to the big fetch with blackjack and
|
||||
whores, so we generally want to fetch this only for keys that have a large absolute number of views,
|
||||
a small number of days between views, etc. """
|
||||
@@ -36,6 +36,10 @@ public class PyFillParagraphTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPrefixPostfix() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
String baseName = "/fillParagraph/" + getTestName(true);
|
||||
myFixture.configureByFile(baseName + ".py");
|
||||
|
||||
Reference in New Issue
Block a user