Skip to content

[Diag] Make fixItReplace slightly smart #4499

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
Aug 31, 2016

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Aug 25, 2016

What's in this pull request?

When replace something with a punctuator, we often prefer adding spaces around it.
For instance,

  typealias Foo: Int
  // fix it
  typealias Foo = Int

In this case we want to add a space before =, but not after that.

With this change, we can simply fixItReplace(ColonLoc, " = ").
fixItReplace() automatically adjust the spaces around it.


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@rintaro
Copy link
Member Author

rintaro commented Aug 25, 2016

@swift-ci Please smoke test

typealias Foo : Int // expected-error {{expected '=' in typealias declaration}} {{15-16==}}
typealias Foo1 : Int // expected-error {{expected '=' in typealias declaration}} {{16-17==}}
typealias Foo2: Int // expected-error {{expected '=' in typealias declaration}} {{15-16= =}}
typealias Foo3 :Int // expected-error {{expected '=' in typealias declaration}} {{16-17== }}

Copy link
Contributor

Choose a reason for hiding this comment

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

Test case for comments here too? typealias Foo4:/*comment*/Int

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Thanks!

@jtbandes
Copy link
Contributor

Nice 😄

When replace something with a punctuator, we often prefer adding spaces around it.
For instance,

   func foo(): bar {}
   // fix it
   func foo() -> bar {}

In this case we want to add a space before '->', but not after that.

With this change, we can simply `fixItReplace(ColonLoc, " -> ")`.
`fixItReplace()` automatically adjust the spaces around it.
@rintaro rintaro force-pushed the fixitreplace-smart branch from 37fc797 to ba982bc Compare August 25, 2016 04:52
@rintaro
Copy link
Member Author

rintaro commented Aug 25, 2016

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Aug 25, 2016

@swift-ci Please smoke test Linux platform


// If we're replacing with something that wants spaces around it, do a bit of
// extra work so that we don't suggest extra spaces.
if (Str.back() == ' ') {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest defending against the empty string here, just in case...

Copy link
Member Author

Choose a reason for hiding this comment

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

@DougGregor
It's redundant because a few lines above:

   if (Str.empty())
      return fixItRemove(R);

@jrose-apple
Copy link
Contributor

That's pretty good. Is there a way to share the logic with fixItRemove?

@rintaro rintaro force-pushed the fixitreplace-smart branch from 1c21996 to b9c2089 Compare August 25, 2016 17:35
/// \brief Extract a character at \p Loc. If \p Loc is the end of the buffer,
/// return '\f'.
static char extractCharAfter(SourceManager &SM, SourceLoc Loc) {
auto chars = SM.extractText({Loc, 1});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: indentation is two characters.

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@rintaro rintaro force-pushed the fixitreplace-smart branch from b9c2089 to 96600fe Compare August 25, 2016 17:40
@rintaro
Copy link
Member Author

rintaro commented Aug 25, 2016

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Aug 25, 2016

@shahmishal
Copy link
Member

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 96600fe
Test requested by - @shahmishal

@rintaro
Copy link
Member Author

rintaro commented Aug 25, 2016

Unrelated non-deterministic error on Linux?

11:41:33 
TestFoundation/TestNSOperationQueue.swift:63: error: TestNSOperationQueue.test_OperationPriorities : XCTAssertEqual failed: ("Operation1 executed") is not equal to ("Operation3 executed") - 
11:41:33 TestFoundation/TestNSOperationQueue.swift:64: error: TestNSOperationQueue.test_OperationPriorities : XCTAssertEqual failed: ("Operation3 executed") is not equal to ("Operation1 executed") - 

@swift-ci Please test Linux platform

@jrose-apple
Copy link
Contributor

Just to make sure nothing's changed,

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test Linux platform

@jrose-apple
Copy link
Contributor

@rintaro, this is ready to merge, yes?

@rintaro
Copy link
Member Author

rintaro commented Aug 31, 2016

@jrose-apple
Yes, please merge. I'm not authorized to merge into master.

@jrose-apple jrose-apple merged commit e44e0d9 into swiftlang:master Aug 31, 2016
@rintaro rintaro deleted the fixitreplace-smart branch August 31, 2016 07:15
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.

6 participants