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

[Function builders] Fix-Its and code completion improvements #33972

Merged
merged 8 commits into from
Sep 17, 2020

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Sep 16, 2020

Extend diagnostics and code completion to help guide developers toward implementing function builders. Specifically:

  • When the function builder transformation cannot be applied because of a missing build method, e.g., because the body uses if-else but the function builder doesn't provide buildEither(first:) and buildEither(second:), add a note + Fix-It to the error message that adds stubs for the functions needed to support those statements.
  • When code-completing with the definition of a function builder type, provide a full set of completions for all of the build functions that function builders support.
  • Add an educational note outlining the builder functions that a function builder can provide.

Fixes SR-13536 / rdar://problem/68732123

When a use of a function builder involves a statement kind that the
function builder doesn't support (e.g., if-else), add a note to the
diagnostic that specifies what methods need to be added to the
function builder to support that statement, including Fix-Its with
stub implementations.
When performing code completion inside the declaration of a type with
the function builder attribute, also include completions for all of
the possible "build" functions.
Add brief documentation comments to each of the code completions
produced for a build* function in a code completion.
include/swift/AST/DiagnosticsSema.def Outdated Show resolved Hide resolved
lib/IDE/CodeCompletion.cpp Outdated Show resolved Hide resolved
test/IDE/complete_function_builder.swift Outdated Show resolved Hide resolved
Introduce an educational note with a synopsis of the build* function
declarations one can add to a function builder, and associate it with
the diagnostics indicating incorrect or missing build* functions.
…Availability

The lack of these functions in a function builder is diagnosed in
different places in the type checker. Extend these diagnostics to
provide stubs in the function builder.

Thanks to Suyash for the suggestion!
@DougGregor
Copy link
Member Author

@swift-ci smoke test

@DougGregor
Copy link
Member Author

Fix-It matching with newlines doesn't work with Windows because of CRLF. Sigh.

Testing newlines in Fix-Its does not work well with Windows, so
separate out the Fix-It tests for function builder stubs.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor
Copy link
Member Author

DougGregor commented Sep 17, 2020

@swift-ci please smoke test macOS

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3b8656d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3b8656d

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.

5 participants