swiftlang / swift-syntax

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

Code action to convert between computed property and stored property #2712

Closed antigluten closed 2 months ago

antigluten commented 3 months ago

Resolves swiftlang/sourcekit-lsp#1245

antigluten commented 3 months ago

Thanks for review, @ahoppen!

antigluten commented 3 months ago

Need help with the testToStoredWithReturnStatementAndTrailingCommentOnNewLine, I have no idea how to handle the trailing trivia that contains comments, so to not break another test

Test: testToStoredWithReturnStatementAndTrailingCommentOnNewLine

let baseline: DeclSyntax = """
  var defaultColor: Color {
    return Color()
    /* some text */
  }
  """

let expected: DeclSyntax = """
  let defaultColor: Color = Color()
  /* some text */
  """

Test: testToStoredWithReturnStatementAndTrailingComment

let baseline: DeclSyntax = """
  var defaultColor: Color {
    return Color() /* some text */
  }
  """

let expected: DeclSyntax = """
  let defaultColor: Color = Color() /* some text */
  """
ahoppen commented 3 months ago

How about adding the trivia of the dropped braces to the initializer?

Ie something like

initializer.leadingTrivia = accessorBlock.leftBrace.leadingTrivia + accessorBlock.leftBrace.trailing + initializer.leadingTrivia
initializer.trailingTrivia += accessorBlock.rightBrace.leadingTrivia + accessorBlock.rightBrace.trailing
antigluten commented 3 months ago

@ahoppen, done

ahoppen commented 2 months ago

@swift-ci Please test

kimdv commented 2 months ago

@swift-ci please test

kimdv commented 2 months ago

@swift-ci please test windows

ahoppen commented 2 months ago

@swift-ci Please test Linux