Commit Graph

22 Commits

Author SHA1 Message Date
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Rintaro Ishizaki
17be66c3d6 [PlaceholderExpansion] Omit return type in closure signature
Return type in the closure signature is often redundant when expanding
placeholders, because the type of the clossures are usually inferred
from the context (i.e. calling function), users don't need to write the
return type explicitly.

They are not only redundant, but also sometimes harmful when the return
type is a generic parameter or its requirement. Actually, there is no
correct spelling in such cases.

So omit the return type and the parentheses around the parameter clause.

rdar://problem/63607976
2020-07-09 14:37:17 -07:00
Ben Langmuir
2bf014dc74 [expand-placeholder] Add support for multiple-trailing closures
Since placeholder expansion works with a single placeholder, which is
somewhat at odds with multiple-trailing closures, we eagerly attempt to
expand all consecutive placeholders of closure type. That is, if the API
has multiple closure parameters at the end, expanding any one of them
will transform all of them to the new syntax.

Example

```
foo(a: <#T##()->()#>, b: <#T##()->()#>)
```

expanding *either* parameter will produce the following:

```
foo {
  <#code#>
} b: {
  <#code#>
}
```

(caveat: the indentation is not part of placeholder expansion, but it's
added here for clarity)

At least for now we do not attempt to corral an existing closure into
the new syntax, so for

```
foo(a: { bar() }, b: <#T##()->()#>)
```

The exansion will be

```
foo(a: { bar() }) {
  <#code#>
}
```

as it was before.

rdar://59688632
2020-05-06 01:56:41 -04:00
Ben Langmuir
feaaf39206 [sourcekitd-test] Make expand-placeholder iterative
Instead of getting all edits up front using the same source code, apply
each replacement before calculating the next. Placeholder expansion is
sensitive the surrounding code, so expanding multiple closures
separately can give different results from doing so in order. To allow
testing that, add a magic placeholder identifier __skip__ to skip
expansion during testing.

This is also required for handling multiple trailing closures.
2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
0e8010d8b9 Revert "Merge pull request #27592 from rintaro/syntaxparse-exprtuple"
This reverts commit cdfd1ab2cf, reversing
changes made to eb02f20f99.
2019-10-14 12:15:48 -07:00
Rintaro Ishizaki
bb08667bf5 [SyntaxParse] Parse tuple/paren expression syntax 2019-10-09 14:48:47 -07:00
Nathan Hawes
0d59bffd81 [SourceKit] Fix placeholder expansion not working inside #if
Update the PlaceholderFinder ASTWalker to walk into the clauses of
IfConfigDecls. It wasn't previously, resulting in any placeholders there not
being expanded.

Also update CallExprFinder (used to determine if expansions should use trailing
closure syntax) to walk into inactive if-config clauses. Previously it only
walked into active regions, so expansions never used trailing closure syntax in
inactive regions.

Resolves rdar://problem/51995648
2019-07-09 14:18:40 -07:00
Rintaro Ishizaki
1c2c5c5114 [placeholder-expansion] Function builder: add basic expansion test
rdar://problem/50074177
2019-06-11 17:34:45 -07:00
Ben Langmuir
6377199e2f [placeholder-expansion] Expand trailing closure in statements correctly
In addition to brace statements (previously handled), several other
statements allow a trailing closure (return, yield, throw). Also fix the
handling of statements nested within expressions for closures - both
single-expression bodies and brace statements.

This also fixes a particular regression caused by single-expression
function bodies where we would fail to expand to a trailing closure when
a function body only contained a single expression.

rdar://50227500
2019-04-26 11:58:52 -07:00
Ben Langmuir
27b12bfe89 Merge pull request #23978 from AnthonyLatsis/expand-closure-check-braces
SourceKit: Account for existing braces when expanding closure placeholders
2019-04-25 15:00:40 -07:00
Nate Chandler
3139d3e061 Tweaked remaining failing tests.
Modified so that single-expression implicit return does not throw off
tests.
2019-04-24 10:04:20 -07:00
fischertony
7344fdb0a4 SourceKit: Account for existing braces when expanding closure placeholders 2019-04-12 07:30:28 +03:00
Xi Ge
3160446a8c SourceKitd: fix a placeholder expanding issue. rdar://34230324
When expanding placeholders, we analyze the surrounding context of a
placeholder to decide whether to expand the placeholder to a trailing
closure. This analysis assumes CallExpr is the only AST node with argument;
however UnresolvedMemberExpr can have argument as well. This commit
teaches the analysis logic to handle both.
2017-11-16 16:31:50 -08:00
Xi Ge
5c9099b07e SourceKitd: Properly record enclosing statement to ensure expanding to trailing closures consistently. rdar://33477177 2017-08-28 13:43:13 -07:00
Xi Ge
9577d980b0 [SourceKit] Initialize pointer as nullptr to fix a crash. rdar://28959889 2016-10-27 13:01:50 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Argyrios Kyrtzidis
1e9bae34a3 [AST] Preserve parameter names in TypeReprs of function types.
Also fixup 'test/SourceKit/CodeExpand/code-expand.swift' and use the syntax
for adding parameter names with an underscore for first name.
2016-08-09 18:07:58 -07:00
Doug Gregor
5b67fe455c [SE-0111 HACK] Disable some IDE- and SourceKit-related changes.
I still need to investigate what happened here, but I don't want it to
delay landing the bulk of SE-0111.
2016-07-29 17:28:25 -07:00
Xi Ge
09a19bb230 [SourceKit] Avoid expanding the last argument as trailing closure if there are other closures in the tuple. rdar://23428366 (#3408)
SourceKit invariantly expands the last argument in a function call as trailing closure,
if it is of function type. However, there are situations when inline closures
are preferred; for example, when the last argument is not the only closure in the function
call. This patch modifies SourceKit so that when the argument contains multiple closures,
the last argument is expanded as inline closure.
2016-07-07 18:25:55 -07:00
ken0nek
3ac60b13f5 Add spaces before and after closure arrow in test 2015-12-23 04:38:46 +09:00
Xi Ge
ab969d14a4 [SourceKit][PlaceholderExpand] Avoid function signatures when expanding trailing closures of ()->(). rdar://21879249 2015-12-07 11:48:53 -08:00
Argyrios Kyrtzidis
8ff6a98a99 [sourcekit] Merge SourceKit into the Swift repo.
The code goes into its own sub-tree under 'tools' but tests go under 'test',
so that running 'check-swift' will also run all the SourceKit tests.

SourceKit is disabled on non-darwin platforms.
2015-11-05 01:09:08 -08:00