Skip to content

[SourceKit/CodeFormat] Indentation fixes for multi-line string, UnresolvedSpecializeExpr, and trailing target handling. #31098

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

Merged
merged 2 commits into from
Apr 20, 2020

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Apr 17, 2020

  1. Fixes a bug were we were indenting within a multi-line string when we shouldn't have been. The checks for walking into an AST node or not were based on their end source loc, which is the start of their last token. If that token was a multi-line string and line being indented was within it, we we wouldn't walk into the node, and so never set the flag to indicate we were attempting to indent within a string.

  2. We weren't handling UnresolvedSpecializeExpr when determining if an expression was 'outdenting' or not, so we ended up indenting the filter call below when we shouldn't have:

     let x = foo<
         Int,
         String,
         Int
     >()
          .filter { $0 > 10 }
    

    It's now handled correctly.

  3. Fixes up ListAligner (and the code using it) to handle trailing indentation targets in many more cases. This makes the as-you-type indentation more consistent with select-and-reindent-after-you're-done indentation. Hitting enter after a comma in an incomplete list, or after an empty list that requires at least one element now give the correct indentation in many more cases (including guard/if/while conditions, and enum case elements). A few lists still don't handle trailing indentation targets properly, though, because the parser drops them from the AST when incomplete or empty.

Resolves rdar://problem/62061741

…on ranges < >

They were missed before, so < > that should trigger outdenting weren't. E.g.
let x = foo<
  Int, String, Int
>()
    .count // Indented becase we didn't process the < > brackets previously.
@nathawes
Copy link
Contributor Author

@swift-ci please smoke test

…ces and fix a bug where multi-line string indentation was modified.

E.g. if/guard condition patterns are column-aligned, but hitting enter after
the ',' below wasn't column-aligning the next empty line:

guard let x = Optional(42),
// No indentation added here after enter

Also the isTargetContext() check takes a start and end token location, but
wasn't accounting for the end location pointing a multiline string, so we
weren't walking into such nodes. This meant we didn't realise the target
location was within a multiline string in some cases, and we ended up
interfering with whitespace in its content.
@nathawes nathawes force-pushed the indentation-fixes branch from de420aa to e01c1a1 Compare April 19, 2020 22:11
@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes
Copy link
Contributor Author

@swift-ci please stress test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - de420aa2b6ce1e91c7acedb86bbabb6bdc1e86d1

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - de420aa2b6ce1e91c7acedb86bbabb6bdc1e86d1

@nathawes nathawes requested a review from benlangmuir April 20, 2020 17:21
@nathawes nathawes changed the title [WIP] Indentation fixes [SourceKit/CodeFormat] Indentation fixes for multi-line string, UnresolvedSpecializeExpr, and trailing target handling. Apr 20, 2020
@nathawes nathawes marked this pull request as ready for review April 20, 2020 17:37
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.

3 participants