Skip to content

Commit df3b6a8

Browse files
author
Nathan Hawes
committed
[SourceKit/CodeFormat] Don't modify multiline string indentation regardless of it being column-aligned or not.
Resolves rdar://problem/61463947
1 parent 4264b39 commit df3b6a8

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/IDE/Formatting.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,12 @@ class CodeFormatter {
25672567
std::pair<LineRange, std::string> indent(unsigned LineIndex,
25682568
FormatContext &FC,
25692569
StringRef Text) {
2570+
if (FC.IsInStringLiteral()) {
2571+
return std::make_pair(
2572+
LineRange(LineIndex, 1),
2573+
swift::ide::getTextForLine(LineIndex, Text, /*Trim*/ false).str());
2574+
}
2575+
25702576
if (FC.isExact()) {
25712577
StringRef Line = swift::ide::getTextForLine(LineIndex, Text, /*Trim*/true);
25722578
StringBuilder Builder;
@@ -2575,12 +2581,6 @@ class CodeFormatter {
25752581
return std::make_pair(LineRange(LineIndex, 1), Builder.str().str());
25762582
}
25772583

2578-
if (FC.IsInStringLiteral()) {
2579-
return std::make_pair(
2580-
LineRange(LineIndex, 1),
2581-
swift::ide::getTextForLine(LineIndex, Text, /*Trim*/ false).str());
2582-
}
2583-
25842584
// Take the current indent position of the context, then add the number of
25852585
// indents specified.
25862586
auto LineAndColumn = FC.indentLineAndColumn();

test/swift-indent/basic.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ let s = """
287287
c
288288
"""
289289

290+
print("""
291+
foo {
292+
bar()
293+
}
294+
""")
295+
290296

291297
// Interpolations shouldn't change how multiline strings are handled.
292298
//

0 commit comments

Comments
 (0)