-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
4e4b1e7
to
37fc797
Compare
@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== }} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
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.
37fc797
to
ba982bc
Compare
@swift-ci Please smoke test |
@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() == ' ') { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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);
That's pretty good. Is there a way to share the logic with fixItRemove? |
1c21996
to
b9c2089
Compare
/// \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}); |
There was a problem hiding this comment.
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.
@swift-ci Please test |
b9c2089
to
96600fe
Compare
@swift-ci Please smoke test |
Before indentation fix(b9c2089): HEAD(96600fe): |
@swift-ci Please test |
Build failed |
Unrelated non-deterministic error on Linux?
@swift-ci Please test Linux platform |
Just to make sure nothing's changed, @swift-ci Please smoke test |
@swift-ci Please smoke test Linux platform |
@rintaro, this is ready to merge, yes? |
@jrose-apple |
What's in this pull request?
When replace something with a punctuator, we often prefer adding spaces around it.
For instance,
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:
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
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.