File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -413,8 +413,15 @@ open class BasicFormat: SyntaxRewriter {
413
413
anchorPoints [ token] = currentIndentationLevel
414
414
}
415
415
416
- // Add an indentation in the line for the initial token,
417
- // if the token is present and its leadingTrivia does not contain the indentation.
416
+ // If we are formatting a subtree and the line that the initial token occurs on is indented,
417
+ // use that line indentation for the first token in the subtree to format.
418
+ // For example, when formatting only the code block in the following,
419
+ // then the opening `{` should be indented by four spaces.
420
+ // ```
421
+ // func test() {
422
+ // print(1)
423
+ // }
424
+ // ``
418
425
if isInitialToken && token. presence == . present {
419
426
let indentationOfLine = token. indentationOfLine
420
427
if token. leadingTrivia. pieces. suffix ( indentationOfLine. pieces. count) != indentationOfLine. pieces {
You can’t perform that action at this time.
0 commit comments