[5.1][SourceKit] Fix placeholder expansion not working inside #if #26040
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #26036 from master
Issue: rdar://problem/51995648
Explanation:
All editor placeholder expansions inside #if blocks were failing. For example, with the below placeholder produced by code completion:
the expansion was failing and Xcode would simply insert the placeholder content verbatim:
rather than expanding successfully as it does outside of
#if
blocks:This was failing because the
PlaceholderFinder
ASTWalker
wasn't walking into the clauses ofIfConfigDecl
s, so didn't find them. Additionally theCallExprFinder
walker (used to determine if expansions should use trailing closure syntax) wasn't configured to walk into inactive if-config clauses, so expansions weren't using trailing closure syntax in inactive regions.Scope: This issue affects all editor placeholder expansions inside of #if blocks
Risk: Low. The fix is limited to SourceKit's placeholder expansion request, and only affects the behavior on placeholders within
#if
blocks.Origination: Placeholder expansion never worked in inactive
#if
blocks, but used to work in active#if
blocks prior to Xcode 10.2. The offending change was that#if
conditions are no longer evaluated when parsing to produce an AST for SourceKit's purely syntactic requests (including placeholder expansion) so there aren't any active clauses anymore.Testing: Added regression tests and manually checked it behaves correctly in Xcode
Reviewer: Xi Ge (in the master PR)
Resolves rdar://problem/51995648