Skip to content

Conversation

@stmontgomery
Copy link
Contributor

This adds fix-its to the diagnostic emitted by the @Test macro when it has been applied to a function which includes parameters but does not specify arguments: ....

Motivation:

When transforming a non-parameterized @Test function into a parameterized one, it's common to begin by adding one or more parameters to the function's signature. Immediately after doing that, the @Test macro emits an error diagnostic if arguments: is not passed to @Test. Since this is a common workflow and it may not always be obvious to new users where to add arguments:, it would be beneficial for this diagnostic to include a fix-it.

Modifications:

  • Add a couple of styles of fix-it to this diagnostic, with variations for single- and multiple-parameter functions.
  • Enhance a utility on EditorPlaceholderExprSyntax to prefer typed placeholders (see code comment).

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

Resolves rdar://128396593

@stmontgomery
Copy link
Contributor Author

@swift-ci please test


extension EditorPlaceholderExprSyntax {
/// Initialize an instance of this type with the given placeholder string.
/// Initialize an instance of this type with the given display name string and
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat!

let additionalArguments = parameters.indices.map { index in
let label = index == parameters.startIndex ? "arguments" : nil
let argumentsCollectionType = "[\(parameters[index].baseTypeName)]"
return LabeledExprSyntax(
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using our built-in Argument type instead, which when cast to LabeledExprSyntax ought to always do the right thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still would suggest using Argument here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've attempted to do this but found that as it stands currently, the Argument helper type still requires me to do the same book-keeping for trailing trivia like commaToken on the LabeledExprSyntax nodes. I'm not quite sure what the benefit of this type is in this circumstance.

I'm open to it, but would ask for a bit more specific guidance on how you recommend applying it (once you're available again). In the mean time I'm planning to proceed with merging this since we've gone through a couple rounds and I think the PR is in good shape overall at this point

Copy link
Contributor

@grynspan grynspan left a comment

Choose a reason for hiding this comment

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

Please add a new parameterized test that covers all the code paths for the new Fix-It code.

@grynspan
Copy link
Contributor

grynspan commented Jun 4, 2024

@swift-ci please test Windows

@stmontgomery stmontgomery requested a review from grynspan June 13, 2024 04:43
@stmontgomery
Copy link
Contributor Author

Please add a new parameterized test that covers all the code paths for the new Fix-It code.

I've now added a comprehensive unit test to validate the fix-its on this diagnostic under various scenarios

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit bd9249e into swiftlang:main Jun 17, 2024
@stmontgomery stmontgomery deleted the arguments-fix-it branch June 17, 2024 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants