swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.
Apache License 2.0
3.23k stars 410 forks source link

Too much indentation in formatting of `AccessorDeclSyntax` #1819

Open ahoppen opened 1 year ago

ahoppen commented 1 year ago

In the following two cases, we appear to add too much indentation in front of the return.

let source: AccessorDeclSyntax = """
    get {
      return 1
    }
  """

assertFormatted(
  tree: source,
  expected: """
      get {
            return 1
      }
    """
)

let source: AccessorDeclSyntax = """
    get {
        return 1
    }
  """

assertFormatted(
  tree: source,
  expected: """
      get {
                return 1
      }
    """
)
ahoppen commented 1 year ago

Tracked in Apple’s issue tracker as rdar://111032264

Matejkob commented 1 year ago

Hey there,

Just trying to wrap my head around the correct formatting for these test cases.

For the first one, we've got 2 spaces before the get and 4 spaces hanging out before the return. Kinda like this:

\u{0020}\u{0020}get {
\u{0020}\u{0020}\u{0020}\u{0020}return 1
\u{0020}\u{0020}}

Given that we're using BasicFormat(indentationWidth: .spaces(4)), I am assuming that the correctly formatted version would look something like this:

get {
\u{0020}\u{0020}\u{0020}\u{0020}return 1
}

Is my understanding correct? If not, could you please specify what the expected output should be in this case?

ahoppen commented 1 year ago

Oh, I should have been clearer in the issue: In both of theses cases, I think BasicFormat should just pick up the user-defined indentation and thus BasicFormat shouldn’t change the indentation.