PY-39406 Make multiline string with prefix be folded with the prefix

GitOrigin-RevId: e1fa6861d85916a0862fefc7342a34d3b0905281
This commit is contained in:
Mikhail Khorkov
2021-01-17 14:10:47 +00:00
committed by intellij-monorepo-bot
parent cfa826f9b6
commit d34338e85d
3 changed files with 17 additions and 3 deletions
@@ -207,15 +207,16 @@ public class PythonFoldingBuilder extends CustomFoldingBuilder implements DumbAw
}
if (node.getElementType() == PyElementTypes.STRING_LITERAL_EXPRESSION) {
PyStringLiteralExpression stringLiteralExpression = (PyStringLiteralExpression)node.getPsi();
String prefix = stringLiteralExpression.getStringElements().get(0).getPrefix();
if (stringLiteralExpression.isDocString()) {
final String stringValue = stringLiteralExpression.getStringValue().trim();
final String[] lines = LineTokenizer.tokenize(stringValue, true);
if (lines.length > 2 && lines[1].trim().length() == 0) {
return "\"\"\"" + lines[0].trim() + "...\"\"\"";
return prefix + "\"\"\"" + lines[0].trim() + "...\"\"\"";
}
return "\"\"\"...\"\"\"";
return prefix + "\"\"\"...\"\"\"";
} else {
return getLanguagePlaceholderForString(stringLiteralExpression);
return prefix + getLanguagePlaceholderForString(stringLiteralExpression);
}
}
return "...";
@@ -0,0 +1,8 @@
def foo():<fold text='...'>
<fold text='r"""..."""'>r"""
foo/bar
"""</fold>
pass</fold>
mline = <fold text='u"..."'>u"\n\n\n\n\n\n\n\n" \
"\n\n\n\n\n\n\n\"</fold>
@@ -112,4 +112,9 @@ public class PyFoldingTest extends PyTestCase {
}
}
}
// PY-39406
public void testStringPrefixFolding() {
doTest();
}
}