Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

antigluten
Copy link
Contributor

@antigluten antigluten commented Jun 29, 2024

@antigluten
Copy link
Contributor Author

Thanks for review, @ahoppen!

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the adjustments. I have a few comments, mostly regarding trivia handling. The overall shape looks good. It would also be good to add test cases for the examples that I mentioned.

@antigluten antigluten force-pushed the code-action-computed-properties branch from 7ee1cf2 to 107417a Compare July 2, 2024 15:44
@antigluten
Copy link
Contributor Author

antigluten commented Jul 2, 2024

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
Copy link
Member

ahoppen commented Jul 2, 2024

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 antigluten force-pushed the code-action-computed-properties branch from 107417a to d5b3c15 Compare July 6, 2024 08:15
@antigluten
Copy link
Contributor Author

@ahoppen, done

@antigluten antigluten force-pushed the code-action-computed-properties branch from eac08a4 to ebf4299 Compare July 6, 2024 19:00
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The results are looking great!

@antigluten antigluten force-pushed the code-action-computed-properties branch 2 times, most recently from 098e9b3 to 33d4cee Compare July 16, 2024 20:23
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great. Let’s get this merged.

@ahoppen
Copy link
Member

ahoppen commented Jul 16, 2024

@swift-ci Please test

@antigluten antigluten force-pushed the code-action-computed-properties branch from 33d4cee to c10ac8a Compare July 17, 2024 04:06
@kimdv
Copy link
Contributor

kimdv commented Jul 17, 2024

@swift-ci please test

@kimdv
Copy link
Contributor

kimdv commented Jul 17, 2024

@swift-ci please test windows

@ahoppen
Copy link
Member

ahoppen commented Jul 18, 2024

@swift-ci Please test Linux

@ahoppen ahoppen enabled auto-merge July 18, 2024 17:28
@ahoppen ahoppen merged commit 15b8ace into swiftlang:main Jul 18, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code action to convert between computed property and stored property
3 participants